about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-04-25 00:12:12 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-04-29 18:34:40 +0000
commit5a4e0b14e39989f327f9f8103cf38ec43cd22131 (patch)
treeff5952b977c7ad7bc180f9069900d62ee61cec9b
parent60c8f7dbf5788f1c9f3a27be2e7be28ecf7817ff (diff)
downloadrust-5a4e0b14e39989f327f9f8103cf38ec43cd22131.tar.gz
rust-5a4e0b14e39989f327f9f8103cf38ec43cd22131.zip
Remove use of `ast_map.span_if_local()` and improve diagnostics
-rw-r--r--src/librustc_resolve/lib.rs17
-rw-r--r--src/test/compile-fail/const-pattern-irrefutable.rs4
2 files changed, 8 insertions, 13 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index bca7a6a89e9..c0a22151a59 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -141,7 +141,7 @@ enum ResolutionError<'a> {
     /// error E0413: declaration shadows an enum variant or unit-like struct in scope
     DeclarationShadowsEnumVariantOrUnitLikeStruct(Name),
     /// error E0414: only irrefutable patterns allowed here
-    OnlyIrrefutablePatternsAllowedHere(DefId, Name),
+    OnlyIrrefutablePatternsAllowedHere(Name),
     /// error E0415: identifier is bound more than once in this parameter list
     IdentifierBoundMoreThanOnceInParameterList(&'a str),
     /// error E0416: identifier is bound more than once in the same pattern
@@ -323,7 +323,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
                               or unit-like struct in scope",
                              name)
         }
-        ResolutionError::OnlyIrrefutablePatternsAllowedHere(did, name) => {
+        ResolutionError::OnlyIrrefutablePatternsAllowedHere(name) => {
             let mut err = struct_span_err!(resolver.session,
                                            span,
                                            E0414,
@@ -331,14 +331,10 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
             err.span_note(span,
                           "there already is a constant in scope sharing the same \
                            name as this pattern");
-            if let Some(sp) = resolver.ast_map.span_if_local(did) {
-                err.span_note(sp, "constant defined here");
-            }
             if let Some(binding) = resolver.current_module
                                            .resolve_name_in_lexical_scope(name, ValueNS) {
-                if binding.is_import() {
-                    err.span_note(binding.span, "constant imported here");
-                }
+                let participle = if binding.is_import() { "imported" } else { "defined" };
+                err.span_note(binding.span, &format!("constant {} here", participle));
             }
             err
         }
@@ -2248,12 +2244,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
                                                 depth: 0,
                                             });
                         }
-                        FoundConst(def, name) => {
+                        FoundConst(_, name) => {
                             resolve_error(
                                 self,
                                 pattern.span,
-                                ResolutionError::OnlyIrrefutablePatternsAllowedHere(def.def_id(),
-                                                                                    name)
+                                ResolutionError::OnlyIrrefutablePatternsAllowedHere(name)
                             );
                             self.record_def(pattern.id, err_path_resolution());
                         }
diff --git a/src/test/compile-fail/const-pattern-irrefutable.rs b/src/test/compile-fail/const-pattern-irrefutable.rs
index bc395af9622..825c39011fc 100644
--- a/src/test/compile-fail/const-pattern-irrefutable.rs
+++ b/src/test/compile-fail/const-pattern-irrefutable.rs
@@ -9,8 +9,8 @@
 // except according to those terms.
 
 mod foo {
-    pub const b: u8 = 2; //~ NOTE constant defined here
-    pub const d: u8 = 2; //~ NOTE constant defined here
+    pub const b: u8 = 2;
+    pub const d: u8 = 2;
 }
 
 use foo::b as c; //~ NOTE constant imported here