diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-02-25 13:43:21 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-02-25 13:43:21 +0000 |
| commit | 40bde9902c3d6a32ee25cdf66cbcf4fc4687b3d9 (patch) | |
| tree | 52128e4c3f696bb43a2abd1a99b6c91a21c14e2c | |
| parent | c5d5c62601d90bebdd6ef6238b928d461b85fa68 (diff) | |
| download | rust-40bde9902c3d6a32ee25cdf66cbcf4fc4687b3d9.tar.gz rust-40bde9902c3d6a32ee25cdf66cbcf4fc4687b3d9.zip | |
Address review.
| -rw-r--r-- | compiler/rustc_resolve/src/check_unused.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/compiler/rustc_resolve/src/check_unused.rs b/compiler/rustc_resolve/src/check_unused.rs index df7f91c5a27..b2578e4c4b4 100644 --- a/compiler/rustc_resolve/src/check_unused.rs +++ b/compiler/rustc_resolve/src/check_unused.rs @@ -34,7 +34,7 @@ use rustc_data_structures::unord::UnordSet; use rustc_errors::{pluralize, MultiSpan}; use rustc_session::lint::builtin::{MACRO_USE_EXTERN_CRATE, UNUSED_EXTERN_CRATES, UNUSED_IMPORTS}; use rustc_session::lint::BuiltinLintDiagnostics; -use rustc_span::symbol::{Ident, Symbol}; +use rustc_span::symbol::Ident; use rustc_span::{Span, DUMMY_SP}; struct UnusedImport<'a> { @@ -72,10 +72,8 @@ struct ExternCrateToLint { has_attrs: bool, /// Name used to refer to the crate. ident: Ident, - /// If `Some`, then this is renamed (`extern crate orig_name as - /// crate_name`), and -- perhaps surprisingly -- this stores the - /// *original* name (`item.name` will contain the new name) - orig_name: Option<Symbol>, + /// Whether the statement renames the crate `extern crate orig_name as new_name;`. + renames: bool, } impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> { @@ -130,7 +128,7 @@ impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> { span_with_attributes: item.span_with_attributes(), has_attrs: !item.attrs.is_empty(), ident: item.ident, - orig_name, + renames: orig_name.is_some(), }); } _ => {} @@ -423,18 +421,16 @@ impl Resolver<'_, '_> { // If the extern crate is renamed, then we cannot suggest replacing it with a use as this // would not insert the new name into the prelude, where other imports in the crate may be // expecting it. - if extern_crate.orig_name.is_some() { + if extern_crate.renames { continue; } // If the extern crate isn't in the extern prelude, // there is no way it can be written as a `use`. - let usage_name = - extern_crate.orig_name.map_or(extern_crate.ident, Ident::with_dummy_span); if !visitor .r .extern_prelude - .get(&usage_name) + .get(&extern_crate.ident) .map_or(false, |entry| !entry.introduced_by_item) { continue; |
