Skip to content

Commit 443925c

Browse files
authored
Rollup merge of rust-lang#59896 - estebank:dedup-spans, r=davidtwco
Remove duplicated redundant spans Fix rust-lang#59895.
2 parents 6c5777e + ca5a9ce commit 443925c

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/librustc_resolve/resolve_imports.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1313,15 +1313,15 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
13131313
if !is_redundant.is_empty() &&
13141314
is_redundant.present_items().all(|is_redundant| is_redundant)
13151315
{
1316+
let mut redundant_spans: Vec<_> = redundant_span.present_items().collect();
1317+
redundant_spans.sort();
1318+
redundant_spans.dedup();
13161319
self.session.buffer_lint_with_diagnostic(
13171320
UNUSED_IMPORTS,
13181321
directive.id,
13191322
directive.span,
13201323
&format!("the item `{}` is imported redundantly", ident),
1321-
BuiltinLintDiagnostics::RedundantImport(
1322-
redundant_span.present_items().collect(),
1323-
ident,
1324-
),
1324+
BuiltinLintDiagnostics::RedundantImport(redundant_spans, ident),
13251325
);
13261326
}
13271327
}

src/test/ui/issues/issue-59896.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![deny(unused_imports)]
2+
3+
struct S;
4+
5+
fn main() {
6+
use S; //~ ERROR the item `S` is imported redundantly
7+
8+
let _s = S;
9+
}
10+

src/test/ui/issues/issue-59896.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: the item `S` is imported redundantly
2+
--> $DIR/issue-59896.rs:6:9
3+
|
4+
LL | struct S;
5+
| --------- the item `S` is already defined here
6+
...
7+
LL | use S;
8+
| ^
9+
|
10+
note: lint level defined here
11+
--> $DIR/issue-59896.rs:1:9
12+
|
13+
LL | #![deny(unused_imports)]
14+
| ^^^^^^^^^^^^^^
15+
16+
error: aborting due to previous error
17+

0 commit comments

Comments
 (0)