Skip to content

Commit 5f9e304

Browse files
committed
Improve diagnostics for constants being used in irrefutable patterns
It's pretty confusing and this error triggers in resolve only when "shadowing" a const, so let's make that clearer.
1 parent 3157691 commit 5f9e304

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/librustc_resolve/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ enum ResolutionError<'a> {
141141
/// error E0413: declaration shadows an enum variant or unit-like struct in scope
142142
DeclarationShadowsEnumVariantOrUnitLikeStruct(Name),
143143
/// error E0414: only irrefutable patterns allowed here
144-
OnlyIrrefutablePatternsAllowedHere(Name),
144+
ConstantForIrrefutableBinding(Name),
145145
/// error E0415: identifier is bound more than once in this parameter list
146146
IdentifierBoundMoreThanOnceInParameterList(&'a str),
147147
/// error E0416: identifier is bound more than once in the same pattern
@@ -323,11 +323,11 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
323323
or unit-like struct in scope",
324324
name)
325325
}
326-
ResolutionError::OnlyIrrefutablePatternsAllowedHere(name) => {
326+
ResolutionError::ConstantForIrrefutableBinding(name) => {
327327
let mut err = struct_span_err!(resolver.session,
328328
span,
329329
E0414,
330-
"only irrefutable patterns allowed here");
330+
"variable bindings cannot shadow constants");
331331
err.span_note(span,
332332
"there already is a constant in scope sharing the same \
333333
name as this pattern");
@@ -2233,7 +2233,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22332233
resolve_error(
22342234
self,
22352235
pattern.span,
2236-
ResolutionError::OnlyIrrefutablePatternsAllowedHere(name)
2236+
ResolutionError::ConstantForIrrefutableBinding(name)
22372237
);
22382238
self.record_def(pattern.id, err_path_resolution());
22392239
}

src/test/compile-fail/const-pattern-irrefutable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use foo::d; //~ NOTE constant imported here
1919
const a: u8 = 2; //~ NOTE constant defined here
2020

2121
fn main() {
22-
let a = 4; //~ ERROR only irrefutable
22+
let a = 4; //~ ERROR variable bindings cannot
2323
//~^ NOTE there already is a constant in scope
24-
let c = 4; //~ ERROR only irrefutable
24+
let c = 4; //~ ERROR variable bindings cannot
2525
//~^ NOTE there already is a constant in scope
26-
let d = 4; //~ ERROR only irrefutable
26+
let d = 4; //~ ERROR variable bindings cannot
2727
//~^ NOTE there already is a constant in scope
2828
}

src/test/compile-fail/issue-27033.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
};
1515
const C: u8 = 1;
1616
match 1 {
17-
C @ 2 => { //~ ERROR only irrefutable patterns allowed here
17+
C @ 2 => { //~ ERROR variable bindings cannot shadow constants
1818
println!("{}", C);
1919
}
2020
_ => {}

0 commit comments

Comments
 (0)