@@ -53,6 +53,7 @@ use rustc_data_structures::tagged_ptr::TaggedRef;
5353use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
5454use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
5555use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId } ;
56+ use rustc_hir:: lints:: DelayedLint ;
5657use rustc_hir:: {
5758 self as hir, AngleBrackets , ConstArg , GenericArg , HirId , ItemLocalMap , LangItem ,
5859 LifetimeSource , LifetimeSyntax , ParamName , TraitCandidate ,
@@ -143,6 +144,8 @@ struct LoweringContext<'a, 'hir> {
143144 allow_for_await : Arc < [ Symbol ] > ,
144145 allow_async_fn_traits : Arc < [ Symbol ] > ,
145146
147+ delayed_lints : Vec < DelayedLint > ,
148+
146149 attribute_parser : AttributeParser < ' hir > ,
147150}
148151
@@ -191,7 +194,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
191194 // interact with `gen`/`async gen` blocks
192195 allow_async_iterator : [ sym:: gen_future, sym:: async_iterator] . into ( ) ,
193196
194- attribute_parser : AttributeParser :: new ( tcx. sess , tcx. features ( ) , registered_tools) ,
197+ attribute_parser : AttributeParser :: new ( tcx, tcx. features ( ) , registered_tools) ,
198+ delayed_lints : Vec :: new ( ) ,
195199 }
196200 }
197201
@@ -200,6 +204,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
200204 }
201205}
202206
207+ struct SpanLowerer {
208+ is_incremental : bool ,
209+ defid : LocalDefId ,
210+ }
211+
212+ impl SpanLowerer {
213+ fn lower ( & self , span : Span ) -> Span {
214+ if self . is_incremental {
215+ span. with_parent ( Some ( self . defid ) )
216+ } else {
217+ // Do not make spans relative when not using incremental compilation.
218+ span
219+ }
220+ }
221+ }
222+
203223#[ extension( trait ResolverAstLoweringExt ) ]
204224impl ResolverAstLowering {
205225 fn legacy_const_generic_args ( & self , expr : & Expr ) -> Option < Vec < usize > > {
@@ -575,6 +595,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
575595 std:: mem:: replace ( & mut self . item_local_id_counter , hir:: ItemLocalId :: new ( 1 ) ) ;
576596 let current_impl_trait_defs = std:: mem:: take ( & mut self . impl_trait_defs ) ;
577597 let current_impl_trait_bounds = std:: mem:: take ( & mut self . impl_trait_bounds ) ;
598+ let current_delayed_lints = std:: mem:: take ( & mut self . delayed_lints ) ;
578599
579600 // Do not reset `next_node_id` and `node_id_to_def_id`:
580601 // we want `f` to be able to refer to the `LocalDefId`s that the caller created.
@@ -608,6 +629,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
608629 self . item_local_id_counter = current_local_counter;
609630 self . impl_trait_defs = current_impl_trait_defs;
610631 self . impl_trait_bounds = current_impl_trait_bounds;
632+ self . delayed_lints = current_delayed_lints;
611633
612634 debug_assert ! ( !self . children. iter( ) . any( |( id, _) | id == & owner_id. def_id) ) ;
613635 self . children . push ( ( owner_id. def_id , hir:: MaybeOwner :: Owner ( info) ) ) ;
@@ -618,6 +640,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
618640 let mut bodies = std:: mem:: take ( & mut self . bodies ) ;
619641 let define_opaque = std:: mem:: take ( & mut self . define_opaque ) ;
620642 let trait_map = std:: mem:: take ( & mut self . trait_map ) ;
643+ let delayed_lints = std:: mem:: take ( & mut self . delayed_lints ) . into_boxed_slice ( ) ;
621644
622645 #[ cfg( debug_assertions) ]
623646 for ( id, attrs) in attrs. iter ( ) {
@@ -631,14 +654,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
631654 let bodies = SortedMap :: from_presorted_elements ( bodies) ;
632655
633656 // Don't hash unless necessary, because it's expensive.
634- let ( opt_hash_including_bodies, attrs_hash) =
635- self . tcx . hash_owner_nodes ( node, & bodies, & attrs, define_opaque) ;
657+ let ( opt_hash_including_bodies, attrs_hash, delayed_lints_hash ) =
658+ self . tcx . hash_owner_nodes ( node, & bodies, & attrs, & delayed_lints , define_opaque) ;
636659 let num_nodes = self . item_local_id_counter . as_usize ( ) ;
637660 let ( nodes, parenting) = index:: index_hir ( self . tcx , node, & bodies, num_nodes) ;
638661 let nodes = hir:: OwnerNodes { opt_hash_including_bodies, nodes, bodies } ;
639662 let attrs = hir:: AttributeMap { map : attrs, opt_hash : attrs_hash, define_opaque } ;
663+ let delayed_lints =
664+ hir:: lints:: DelayedLints { lints : delayed_lints, opt_hash : delayed_lints_hash } ;
640665
641- self . arena . alloc ( hir:: OwnerInfo { nodes, parenting, attrs, trait_map } )
666+ self . arena . alloc ( hir:: OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints } )
642667 }
643668
644669 /// This method allocates a new `HirId` for the given `NodeId`.
@@ -759,15 +784,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
759784 } )
760785 }
761786
787+ fn span_lowerer ( & self ) -> SpanLowerer {
788+ SpanLowerer {
789+ is_incremental : self . tcx . sess . opts . incremental . is_some ( ) ,
790+ defid : self . current_hir_id_owner . def_id ,
791+ }
792+ }
793+
762794 /// Intercept all spans entering HIR.
763795 /// Mark a span as relative to the current owning item.
764796 fn lower_span ( & self , span : Span ) -> Span {
765- if self . tcx . sess . opts . incremental . is_some ( ) {
766- span. with_parent ( Some ( self . current_hir_id_owner . def_id ) )
767- } else {
768- // Do not make spans relative when not using incremental compilation.
769- span
770- }
797+ self . span_lowerer ( ) . lower ( span)
771798 }
772799
773800 fn lower_ident ( & self , ident : Ident ) -> Ident {
@@ -889,7 +916,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
889916 if attrs. is_empty ( ) {
890917 & [ ]
891918 } else {
892- let lowered_attrs = self . lower_attrs_vec ( attrs, self . lower_span ( target_span) ) ;
919+ let lowered_attrs = self . lower_attrs_vec ( attrs, self . lower_span ( target_span) , id ) ;
893920
894921 debug_assert_eq ! ( id. owner, self . current_hir_id_owner) ;
895922 let ret = self . arena . alloc_from_iter ( lowered_attrs) ;
@@ -909,9 +936,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
909936 }
910937 }
911938
912- fn lower_attrs_vec ( & self , attrs : & [ Attribute ] , target_span : Span ) -> Vec < hir:: Attribute > {
913- self . attribute_parser
914- . parse_attribute_list ( attrs, target_span, OmitDoc :: Lower , |s| self . lower_span ( s) )
939+ fn lower_attrs_vec (
940+ & mut self ,
941+ attrs : & [ Attribute ] ,
942+ target_span : Span ,
943+ target_hir_id : HirId ,
944+ ) -> Vec < hir:: Attribute > {
945+ let l = self . span_lowerer ( ) ;
946+ self . attribute_parser . parse_attribute_list (
947+ attrs,
948+ target_span,
949+ target_hir_id,
950+ OmitDoc :: Lower ,
951+ |s| l. lower ( s) ,
952+ |l| {
953+ self . delayed_lints . push ( DelayedLint :: AttributeParsing ( l) ) ;
954+ } ,
955+ )
915956 }
916957
917958 fn alias_attrs ( & mut self , id : HirId , target_id : HirId ) {
0 commit comments