@@ -16,7 +16,7 @@ use crate::{Resolver, ResolverArenas, Segment, ToNameBinding, Used, VisResolutio
16
16
17
17
use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
18
18
use rustc_ast:: { self as ast, AssocItem , AssocItemKind , MetaItemKind , StmtKind } ;
19
- use rustc_ast:: { Block , ForeignItem , ForeignItemKind , Impl , Item , ItemKind , NodeId } ;
19
+ use rustc_ast:: { AttrVec , Block , ForeignItem , ForeignItemKind , Impl , Item , ItemKind , NodeId } ;
20
20
use rustc_attr as attr;
21
21
use rustc_data_structures:: sync:: Lrc ;
22
22
use rustc_errors:: { codes:: * , struct_span_code_err, Applicability } ;
@@ -30,6 +30,7 @@ use rustc_middle::{bug, ty};
30
30
use rustc_span:: hygiene:: { ExpnId , LocalExpnId , MacroKind } ;
31
31
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
32
32
use rustc_span:: Span ;
33
+ use thin_vec:: ThinVec ;
33
34
34
35
use std:: cell:: Cell ;
35
36
@@ -360,6 +361,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
360
361
use_span : item. span ,
361
362
use_span_with_attributes : item. span_with_attributes ( ) ,
362
363
has_attributes : !item. attrs . is_empty ( ) ,
364
+ has_allow_unused_imports_attribute : check_allow_unused_imports_attr ( & item. attrs ) ,
363
365
root_span,
364
366
root_id,
365
367
vis : Cell :: new ( Some ( vis) ) ,
@@ -884,6 +886,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
884
886
parent_scope : self . parent_scope ,
885
887
imported_module : Cell :: new ( module) ,
886
888
has_attributes : !item. attrs . is_empty ( ) ,
889
+ has_allow_unused_imports_attribute : check_allow_unused_imports_attr ( & item. attrs ) ,
887
890
use_span_with_attributes : item. span_with_attributes ( ) ,
888
891
use_span : item. span ,
889
892
root_span : item. span ,
@@ -1091,6 +1094,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1091
1094
imported_module : Cell :: new ( Some ( ModuleOrUniformRoot :: Module ( module) ) ) ,
1092
1095
use_span_with_attributes : item. span_with_attributes ( ) ,
1093
1096
has_attributes : !item. attrs . is_empty ( ) ,
1097
+ has_allow_unused_imports_attribute : check_allow_unused_imports_attr ( & item. attrs ) ,
1094
1098
use_span : item. span ,
1095
1099
root_span : span,
1096
1100
span,
@@ -1262,6 +1266,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1262
1266
parent_scope : self . parent_scope ,
1263
1267
imported_module : Cell :: new ( None ) ,
1264
1268
has_attributes : false ,
1269
+ has_allow_unused_imports_attribute : false ,
1265
1270
use_span_with_attributes : span,
1266
1271
use_span : span,
1267
1272
root_span : span,
@@ -1534,3 +1539,16 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1534
1539
}
1535
1540
}
1536
1541
}
1542
+
1543
+ fn check_allow_unused_imports_attr ( attrs : & AttrVec ) -> bool {
1544
+ attrs. iter ( ) . any ( |attr| {
1545
+ if attr. has_name ( sym:: allow) {
1546
+ for item in attr. meta_item_list ( ) . unwrap_or_else ( ThinVec :: new) {
1547
+ if item. has_name ( sym:: unused_imports) {
1548
+ return true ;
1549
+ }
1550
+ }
1551
+ }
1552
+ false
1553
+ } )
1554
+ }
0 commit comments