Skip to content

Commit 40bde99

Browse files
committed
Address review.
1 parent c5d5c62 commit 40bde99

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

compiler/rustc_resolve/src/check_unused.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_data_structures::unord::UnordSet;
3434
use rustc_errors::{pluralize, MultiSpan};
3535
use rustc_session::lint::builtin::{MACRO_USE_EXTERN_CRATE, UNUSED_EXTERN_CRATES, UNUSED_IMPORTS};
3636
use rustc_session::lint::BuiltinLintDiagnostics;
37-
use rustc_span::symbol::{Ident, Symbol};
37+
use rustc_span::symbol::Ident;
3838
use rustc_span::{Span, DUMMY_SP};
3939

4040
struct UnusedImport<'a> {
@@ -72,10 +72,8 @@ struct ExternCrateToLint {
7272
has_attrs: bool,
7373
/// Name used to refer to the crate.
7474
ident: Ident,
75-
/// If `Some`, then this is renamed (`extern crate orig_name as
76-
/// crate_name`), and -- perhaps surprisingly -- this stores the
77-
/// *original* name (`item.name` will contain the new name)
78-
orig_name: Option<Symbol>,
75+
/// Whether the statement renames the crate `extern crate orig_name as new_name;`.
76+
renames: bool,
7977
}
8078

8179
impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
@@ -130,7 +128,7 @@ impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
130128
span_with_attributes: item.span_with_attributes(),
131129
has_attrs: !item.attrs.is_empty(),
132130
ident: item.ident,
133-
orig_name,
131+
renames: orig_name.is_some(),
134132
});
135133
}
136134
_ => {}
@@ -423,18 +421,16 @@ impl Resolver<'_, '_> {
423421
// If the extern crate is renamed, then we cannot suggest replacing it with a use as this
424422
// would not insert the new name into the prelude, where other imports in the crate may be
425423
// expecting it.
426-
if extern_crate.orig_name.is_some() {
424+
if extern_crate.renames {
427425
continue;
428426
}
429427

430428
// If the extern crate isn't in the extern prelude,
431429
// there is no way it can be written as a `use`.
432-
let usage_name =
433-
extern_crate.orig_name.map_or(extern_crate.ident, Ident::with_dummy_span);
434430
if !visitor
435431
.r
436432
.extern_prelude
437-
.get(&usage_name)
433+
.get(&extern_crate.ident)
438434
.map_or(false, |entry| !entry.introduced_by_item)
439435
{
440436
continue;

0 commit comments

Comments
 (0)