Skip to content

Commit 8919894

Browse files
Distinguish between imported and defined items
1 parent d04e83f commit 8919894

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/librustc/lint/builtin.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ pub enum BuiltinLintDiagnostics {
489489
UnknownCrateTypes(Span, String, String),
490490
UnusedImports(String, Vec<(Span, String)>),
491491
NestedImplTrait { outer_impl_trait_span: Span, inner_impl_trait_span: Span },
492-
RedundantImport(Vec<Span>, ast::Ident),
492+
RedundantImport(Vec<(Span, bool)>, ast::Ident),
493493
}
494494

495495
impl BuiltinLintDiagnostics {
@@ -587,10 +587,11 @@ impl BuiltinLintDiagnostics {
587587
db.span_label(inner_impl_trait_span, "nested `impl Trait` here");
588588
}
589589
BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
590-
for span in spans {
590+
for (span, is_imported) in spans {
591+
let introduced = if is_imported { "imported" } else { "defined" };
591592
db.span_label(
592593
span,
593-
format!("the item `{}` was already imported here", ident)
594+
format!("the item `{}` was {} here", ident, introduced)
594595
);
595596
}
596597
}

src/librustc_resolve/resolve_imports.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
12951295
) {
12961296
Ok(other_binding) => {
12971297
is_redundant[ns] = Some(binding.def() == other_binding.def());
1298-
redundant_span[ns] = Some(other_binding.span);
1298+
redundant_span[ns] =
1299+
Some((other_binding.span, other_binding.is_import()));
12991300
}
13001301
Err(_) => is_redundant[ns] = Some(false)
13011302
}

src/test/ui/lint/use-redundant.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: the item `Bar` is imported redundantly
22
--> $DIR/use-redundant.rs:14:9
33
|
44
LL | use crate::foo::Bar;
5-
| --------------- the item `Bar` was already imported here
5+
| --------------- the item `Bar` was imported here
66
...
77
LL | use crate::foo::Bar;
88
| ^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)