@@ -16,7 +16,7 @@ use crate::{Resolver, ResolverArenas, Segment, ToNameBinding, Used, VisResolutio
1616
1717use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
1818use 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 } ;
2020use rustc_attr as attr;
2121use rustc_data_structures:: sync:: Lrc ;
2222use rustc_errors:: { codes:: * , struct_span_code_err, Applicability } ;
@@ -30,6 +30,7 @@ use rustc_middle::{bug, ty};
3030use rustc_span:: hygiene:: { ExpnId , LocalExpnId , MacroKind } ;
3131use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
3232use rustc_span:: Span ;
33+ use thin_vec:: ThinVec ;
3334
3435use std:: cell:: Cell ;
3536
@@ -360,6 +361,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
360361 use_span : item. span ,
361362 use_span_with_attributes : item. span_with_attributes ( ) ,
362363 has_attributes : !item. attrs . is_empty ( ) ,
364+ has_allow_unused_imports_attribute : check_allow_unused_imports_attr ( & item. attrs ) ,
363365 root_span,
364366 root_id,
365367 vis : Cell :: new ( Some ( vis) ) ,
@@ -884,6 +886,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
884886 parent_scope : self . parent_scope ,
885887 imported_module : Cell :: new ( module) ,
886888 has_attributes : !item. attrs . is_empty ( ) ,
889+ has_allow_unused_imports_attribute : check_allow_unused_imports_attr ( & item. attrs ) ,
887890 use_span_with_attributes : item. span_with_attributes ( ) ,
888891 use_span : item. span ,
889892 root_span : item. span ,
@@ -1091,6 +1094,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10911094 imported_module : Cell :: new ( Some ( ModuleOrUniformRoot :: Module ( module) ) ) ,
10921095 use_span_with_attributes : item. span_with_attributes ( ) ,
10931096 has_attributes : !item. attrs . is_empty ( ) ,
1097+ has_allow_unused_imports_attribute : check_allow_unused_imports_attr ( & item. attrs ) ,
10941098 use_span : item. span ,
10951099 root_span : span,
10961100 span,
@@ -1262,6 +1266,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12621266 parent_scope : self . parent_scope ,
12631267 imported_module : Cell :: new ( None ) ,
12641268 has_attributes : false ,
1269+ has_allow_unused_imports_attribute : false ,
12651270 use_span_with_attributes : span,
12661271 use_span : span,
12671272 root_span : span,
@@ -1534,3 +1539,16 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
15341539 }
15351540 }
15361541}
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