Skip to content

Commit 5a4e0b1

Browse files
committed
Remove use of ast_map.span_if_local() and improve diagnostics
1 parent 60c8f7d commit 5a4e0b1

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/librustc_resolve/lib.rs

Lines changed: 6 additions & 11 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(DefId, Name),
144+
OnlyIrrefutablePatternsAllowedHere(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,22 +323,18 @@ 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(did, name) => {
326+
ResolutionError::OnlyIrrefutablePatternsAllowedHere(name) => {
327327
let mut err = struct_span_err!(resolver.session,
328328
span,
329329
E0414,
330330
"only irrefutable patterns allowed here");
331331
err.span_note(span,
332332
"there already is a constant in scope sharing the same \
333333
name as this pattern");
334-
if let Some(sp) = resolver.ast_map.span_if_local(did) {
335-
err.span_note(sp, "constant defined here");
336-
}
337334
if let Some(binding) = resolver.current_module
338335
.resolve_name_in_lexical_scope(name, ValueNS) {
339-
if binding.is_import() {
340-
err.span_note(binding.span, "constant imported here");
341-
}
336+
let participle = if binding.is_import() { "imported" } else { "defined" };
337+
err.span_note(binding.span, &format!("constant {} here", participle));
342338
}
343339
err
344340
}
@@ -2248,12 +2244,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22482244
depth: 0,
22492245
});
22502246
}
2251-
FoundConst(def, name) => {
2247+
FoundConst(_, name) => {
22522248
resolve_error(
22532249
self,
22542250
pattern.span,
2255-
ResolutionError::OnlyIrrefutablePatternsAllowedHere(def.def_id(),
2256-
name)
2251+
ResolutionError::OnlyIrrefutablePatternsAllowedHere(name)
22572252
);
22582253
self.record_def(pattern.id, err_path_resolution());
22592254
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// except according to those terms.
1010

1111
mod foo {
12-
pub const b: u8 = 2; //~ NOTE constant defined here
13-
pub const d: u8 = 2; //~ NOTE constant defined here
12+
pub const b: u8 = 2;
13+
pub const d: u8 = 2;
1414
}
1515

1616
use foo::b as c; //~ NOTE constant imported here

0 commit comments

Comments
 (0)