@@ -133,19 +133,21 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
133
133
134
134
// If the crate is fully unused, we suggest removing it altogether.
135
135
// We do this in any edition.
136
- if let Some ( & span) = unused_extern_crates. get ( & extern_crate. def_id ) {
137
- assert_eq ! ( extern_crate. def_id. krate, LOCAL_CRATE ) ;
138
- let hir_id = tcx. hir . definitions ( ) . def_index_to_hir_id ( extern_crate. def_id . index ) ;
139
- let id = tcx. hir . hir_to_node_id ( hir_id) ;
140
- let msg = "unused extern crate" ;
141
- tcx. struct_span_lint_node ( lint, id, span, msg)
142
- . span_suggestion_short_with_applicability (
143
- span,
144
- "remove it" ,
145
- String :: new ( ) ,
146
- Applicability :: MachineApplicable )
147
- . emit ( ) ;
148
- continue ;
136
+ if extern_crate. warn_if_unused {
137
+ if let Some ( & span) = unused_extern_crates. get ( & extern_crate. def_id ) {
138
+ assert_eq ! ( extern_crate. def_id. krate, LOCAL_CRATE ) ;
139
+ let hir_id = tcx. hir . definitions ( ) . def_index_to_hir_id ( extern_crate. def_id . index ) ;
140
+ let id = tcx. hir . hir_to_node_id ( hir_id) ;
141
+ let msg = "unused extern crate" ;
142
+ tcx. struct_span_lint_node ( lint, id, span, msg)
143
+ . span_suggestion_short_with_applicability (
144
+ span,
145
+ "remove it" ,
146
+ String :: new ( ) ,
147
+ Applicability :: MachineApplicable )
148
+ . emit ( ) ;
149
+ continue ;
150
+ }
149
151
}
150
152
151
153
// If we are not in Rust 2018 edition, then we don't make any further
@@ -202,6 +204,10 @@ struct ExternCrateToLint {
202
204
/// crate_name`), and -- perhaps surprisingly -- this stores the
203
205
/// *original* name (`item.name` will contain the new name)
204
206
orig_name : Option < ast:: Name > ,
207
+
208
+ /// if `false`, the original name started with `_`, so we shouldn't lint
209
+ /// about it going unused (but we should still emit idiom lints).
210
+ warn_if_unused : bool ,
205
211
}
206
212
207
213
impl < ' a , ' tcx , ' v > ItemLikeVisitor < ' v > for CollectExternCrateVisitor < ' a , ' tcx > {
@@ -213,6 +219,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a, 'tcx> {
213
219
def_id : extern_crate_def_id,
214
220
span : item. span ,
215
221
orig_name,
222
+ warn_if_unused : !item. name . as_str ( ) . starts_with ( '_' ) ,
216
223
}
217
224
) ;
218
225
}
0 commit comments