Skip to content

Commit ceca4a1

Browse files
Distinguish between imported and defined items
1 parent 567649b commit ceca4a1

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
@@ -488,7 +488,7 @@ pub enum BuiltinLintDiagnostics {
488488
UnknownCrateTypes(Span, String, String),
489489
UnusedImports(String, Vec<(Span, String)>),
490490
NestedImplTrait { outer_impl_trait_span: Span, inner_impl_trait_span: Span },
491-
RedundantImport(Vec<Span>, ast::Ident),
491+
RedundantImport(Vec<(Span, bool)>, ast::Ident),
492492
}
493493

494494
impl BuiltinLintDiagnostics {
@@ -586,10 +586,11 @@ impl BuiltinLintDiagnostics {
586586
db.span_label(inner_impl_trait_span, "nested `impl Trait` here");
587587
}
588588
BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
589-
for span in spans {
589+
for (span, is_imported) in spans {
590+
let introduced = if is_imported { "imported" } else { "defined" };
590591
db.span_label(
591592
span,
592-
format!("the item `{}` was already imported here", ident)
593+
format!("the item `{}` was {} here", ident, introduced)
593594
);
594595
}
595596
}

src/librustc_resolve/resolve_imports.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
12981298
) {
12991299
Ok(other_binding) => {
13001300
is_redundant[ns] = Some(binding.def() == other_binding.def());
1301-
redundant_span[ns] = Some(other_binding.span);
1301+
redundant_span[ns] =
1302+
Some((other_binding.span, other_binding.is_import()));
13021303
}
13031304
Err(_) => is_redundant[ns] = Some(false)
13041305
}

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)