@@ -34,7 +34,7 @@ use rustc_data_structures::unord::UnordSet;
34
34
use rustc_errors:: { pluralize, MultiSpan } ;
35
35
use rustc_session:: lint:: builtin:: { MACRO_USE_EXTERN_CRATE , UNUSED_EXTERN_CRATES , UNUSED_IMPORTS } ;
36
36
use rustc_session:: lint:: BuiltinLintDiagnostics ;
37
- use rustc_span:: symbol:: { Ident , Symbol } ;
37
+ use rustc_span:: symbol:: Ident ;
38
38
use rustc_span:: { Span , DUMMY_SP } ;
39
39
40
40
struct UnusedImport < ' a > {
@@ -72,10 +72,8 @@ struct ExternCrateToLint {
72
72
has_attrs : bool ,
73
73
/// Name used to refer to the crate.
74
74
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 ,
79
77
}
80
78
81
79
impl < ' a , ' b , ' tcx > UnusedImportCheckVisitor < ' a , ' b , ' tcx > {
@@ -130,7 +128,7 @@ impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
130
128
span_with_attributes : item. span_with_attributes ( ) ,
131
129
has_attrs : !item. attrs . is_empty ( ) ,
132
130
ident : item. ident ,
133
- orig_name,
131
+ renames : orig_name. is_some ( ) ,
134
132
} ) ;
135
133
}
136
134
_ => { }
@@ -423,18 +421,16 @@ impl Resolver<'_, '_> {
423
421
// If the extern crate is renamed, then we cannot suggest replacing it with a use as this
424
422
// would not insert the new name into the prelude, where other imports in the crate may be
425
423
// expecting it.
426
- if extern_crate. orig_name . is_some ( ) {
424
+ if extern_crate. renames {
427
425
continue ;
428
426
}
429
427
430
428
// If the extern crate isn't in the extern prelude,
431
429
// 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) ;
434
430
if !visitor
435
431
. r
436
432
. extern_prelude
437
- . get ( & usage_name )
433
+ . get ( & extern_crate . ident )
438
434
. map_or ( false , |entry| !entry. introduced_by_item )
439
435
{
440
436
continue ;
0 commit comments