Distinguish between imported and defined items

This commit is contained in:
Fabian Drinck 2019-03-16 19:06:22 +01:00
parent d04e83fe2c
commit 8919894c51
3 changed files with 7 additions and 5 deletions

View 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 @@ impl BuiltinLintDiagnostics {
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)
);
}
}

View file

@ -1295,7 +1295,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
) {
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)
}

View 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;
| ^^^^^^^^^^^^^^^