]> git.lizzy.rs Git - rust.git/commitdiff
Distinguish between imported and defined items
authorFabian Drinck <fabian.drinck@rwth-aachen.de>
Sat, 16 Mar 2019 18:06:22 +0000 (19:06 +0100)
committerFabian Drinck <fabian.drinck@rwth-aachen.de>
Sat, 30 Mar 2019 21:37:02 +0000 (22:37 +0100)
src/librustc/lint/builtin.rs
src/librustc_resolve/resolve_imports.rs
src/test/ui/lint/use-redundant.stderr

index 002ee599400597a007679af94595bf6946287daf..462f0947338bb36f3295d16c7149739f7d6a4294 100644 (file)
@@ -489,7 +489,7 @@ pub enum BuiltinLintDiagnostics {
     UnknownCrateTypes(Span, String, String),
     UnusedImports(String, Vec<(Span, String)>),
     NestedImplTrait { outer_impl_trait_span: Span, inner_impl_trait_span: Span },
-    RedundantImport(Vec<Span>, ast::Ident),
+    RedundantImport(Vec<(Span, bool)>, ast::Ident),
 }
 
 impl BuiltinLintDiagnostics {
@@ -587,10 +587,11 @@ pub fn run(self, sess: &Session, db: &mut DiagnosticBuilder<'_>) {
                 db.span_label(inner_impl_trait_span, "nested `impl Trait` here");
             }
             BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
-                for span in spans {
+                for (span, is_imported) in spans {
+                    let introduced = if is_imported { "imported" } else { "defined" };
                     db.span_label(
                         span,
-                        format!("the item `{}` was already imported here", ident)
+                        format!("the item `{}` was {} here", ident, introduced)
                     );
                 }
             }
index cd018d8eb9e23adff0b389d228328f1b2521db9e..eacbf81347aa72680bf95a0315f571e5cd6e5edb 100644 (file)
@@ -1295,7 +1295,8 @@ fn check_for_redundant_imports(
             ) {
                 Ok(other_binding) => {
                     is_redundant[ns] = Some(binding.def() == other_binding.def());
-                    redundant_span[ns] = Some(other_binding.span);
+                    redundant_span[ns] =
+                        Some((other_binding.span, other_binding.is_import()));
                 }
                 Err(_) => is_redundant[ns] = Some(false)
             }
index c843ed160df08c6fcfcf03d15b2b06ccf853ff26..b5000b22a1dad40a0fbab83e03686a6eb8366001 100644 (file)
@@ -2,7 +2,7 @@ warning: the item `Bar` is imported redundantly
   --> $DIR/use-redundant.rs:14:9
    |
 LL | use crate::foo::Bar;
-   |     --------------- the item `Bar` was already imported here
+   |     --------------- the item `Bar` was imported here
 ...
 LL |     use crate::foo::Bar;
    |         ^^^^^^^^^^^^^^^