From fd4c6e903b0161cedb2297e2de25783842dffe2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 11 Apr 2019 16:15:48 -0700 Subject: [PATCH 1/2] Remove duplicated redundant spans --- src/librustc_resolve/resolve_imports.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 97b630ba5f298..2c98c66c62e37 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -1310,15 +1310,14 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { if !is_redundant.is_empty() && is_redundant.present_items().all(|is_redundant| is_redundant) { + let mut redundant_spans: Vec<_> = redundant_span.present_items().collect(); + redundant_spans.dedup(); self.session.buffer_lint_with_diagnostic( UNUSED_IMPORTS, directive.id, directive.span, &format!("the item `{}` is imported redundantly", ident), - BuiltinLintDiagnostics::RedundantImport( - redundant_span.present_items().collect(), - ident, - ), + BuiltinLintDiagnostics::RedundantImport(redundant_spans, ident), ); } } From ca5a9ce2a131b117f1d7f70163d96623ab9ca213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 12 Apr 2019 11:42:52 -0700 Subject: [PATCH 2/2] Add test and fix dedup --- src/librustc_resolve/resolve_imports.rs | 1 + src/test/ui/issues/issue-59896.rs | 10 ++++++++++ src/test/ui/issues/issue-59896.stderr | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/test/ui/issues/issue-59896.rs create mode 100644 src/test/ui/issues/issue-59896.stderr diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 2c98c66c62e37..e3909b466558d 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -1311,6 +1311,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { is_redundant.present_items().all(|is_redundant| is_redundant) { let mut redundant_spans: Vec<_> = redundant_span.present_items().collect(); + redundant_spans.sort(); redundant_spans.dedup(); self.session.buffer_lint_with_diagnostic( UNUSED_IMPORTS, diff --git a/src/test/ui/issues/issue-59896.rs b/src/test/ui/issues/issue-59896.rs new file mode 100644 index 0000000000000..cecf2c5c22b81 --- /dev/null +++ b/src/test/ui/issues/issue-59896.rs @@ -0,0 +1,10 @@ +#![deny(unused_imports)] + +struct S; + +fn main() { + use S; //~ ERROR the item `S` is imported redundantly + + let _s = S; +} + diff --git a/src/test/ui/issues/issue-59896.stderr b/src/test/ui/issues/issue-59896.stderr new file mode 100644 index 0000000000000..ef78f27fa69a3 --- /dev/null +++ b/src/test/ui/issues/issue-59896.stderr @@ -0,0 +1,17 @@ +error: the item `S` is imported redundantly + --> $DIR/issue-59896.rs:6:9 + | +LL | struct S; + | --------- the item `S` is already defined here +... +LL | use S; + | ^ + | +note: lint level defined here + --> $DIR/issue-59896.rs:1:9 + | +LL | #![deny(unused_imports)] + | ^^^^^^^^^^^^^^ + +error: aborting due to previous error +