@@ -51,6 +51,7 @@ use rustc_data_structures::tagged_ptr::TaggedRef;
5151use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
5252use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
5353use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId } ;
54+ use rustc_hir:: lints:: DelayedLint ;
5455use rustc_hir:: {
5556 self as hir, AngleBrackets , ConstArg , GenericArg , HirId , ItemLocalMap , LangItem ,
5657 LifetimeSource , LifetimeSyntax , ParamName , TraitCandidate ,
@@ -141,6 +142,8 @@ struct LoweringContext<'a, 'hir> {
141142 allow_for_await : Arc < [ Symbol ] > ,
142143 allow_async_fn_traits : Arc < [ Symbol ] > ,
143144
145+ delayed_lints : Vec < DelayedLint > ,
146+
144147 attribute_parser : AttributeParser < ' hir > ,
145148}
146149
@@ -189,7 +192,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
189192 // interact with `gen`/`async gen` blocks
190193 allow_async_iterator : [ sym:: gen_future, sym:: async_iterator] . into ( ) ,
191194
192- attribute_parser : AttributeParser :: new ( tcx. sess , tcx. features ( ) , registered_tools) ,
195+ attribute_parser : AttributeParser :: new ( tcx, tcx. features ( ) , registered_tools) ,
196+ delayed_lints : Vec :: new ( ) ,
193197 }
194198 }
195199
@@ -198,6 +202,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
198202 }
199203}
200204
205+ struct SpanLowerer {
206+ is_incremental : bool ,
207+ defid : LocalDefId ,
208+ }
209+
210+ impl SpanLowerer {
211+ fn lower ( & self , span : Span ) -> Span {
212+ if self . is_incremental {
213+ span. with_parent ( Some ( self . defid ) )
214+ } else {
215+ // Do not make spans relative when not using incremental compilation.
216+ span
217+ }
218+ }
219+ }
220+
201221#[ extension( trait ResolverAstLoweringExt ) ]
202222impl ResolverAstLowering {
203223 fn legacy_const_generic_args ( & self , expr : & Expr ) -> Option < Vec < usize > > {
@@ -573,6 +593,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
573593 std:: mem:: replace ( & mut self . item_local_id_counter , hir:: ItemLocalId :: new ( 1 ) ) ;
574594 let current_impl_trait_defs = std:: mem:: take ( & mut self . impl_trait_defs ) ;
575595 let current_impl_trait_bounds = std:: mem:: take ( & mut self . impl_trait_bounds ) ;
596+ let current_delayed_lints = std:: mem:: take ( & mut self . delayed_lints ) ;
576597
577598 // Do not reset `next_node_id` and `node_id_to_def_id`:
578599 // we want `f` to be able to refer to the `LocalDefId`s that the caller created.
@@ -606,6 +627,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
606627 self . item_local_id_counter = current_local_counter;
607628 self . impl_trait_defs = current_impl_trait_defs;
608629 self . impl_trait_bounds = current_impl_trait_bounds;
630+ self . delayed_lints = current_delayed_lints;
609631
610632 debug_assert ! ( !self . children. iter( ) . any( |( id, _) | id == & owner_id. def_id) ) ;
611633 self . children . push ( ( owner_id. def_id , hir:: MaybeOwner :: Owner ( info) ) ) ;
@@ -616,6 +638,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
616638 let mut bodies = std:: mem:: take ( & mut self . bodies ) ;
617639 let define_opaque = std:: mem:: take ( & mut self . define_opaque ) ;
618640 let trait_map = std:: mem:: take ( & mut self . trait_map ) ;
641+ let delayed_lints = std:: mem:: take ( & mut self . delayed_lints ) . into_boxed_slice ( ) ;
619642
620643 #[ cfg( debug_assertions) ]
621644 for ( id, attrs) in attrs. iter ( ) {
@@ -629,14 +652,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
629652 let bodies = SortedMap :: from_presorted_elements ( bodies) ;
630653
631654 // Don't hash unless necessary, because it's expensive.
632- let ( opt_hash_including_bodies, attrs_hash) =
633- self . tcx . hash_owner_nodes ( node, & bodies, & attrs, define_opaque) ;
655+ let ( opt_hash_including_bodies, attrs_hash, delayed_lints_hash ) =
656+ self . tcx . hash_owner_nodes ( node, & bodies, & attrs, & delayed_lints , define_opaque) ;
634657 let num_nodes = self . item_local_id_counter . as_usize ( ) ;
635658 let ( nodes, parenting) = index:: index_hir ( self . tcx , node, & bodies, num_nodes) ;
636659 let nodes = hir:: OwnerNodes { opt_hash_including_bodies, nodes, bodies } ;
637660 let attrs = hir:: AttributeMap { map : attrs, opt_hash : attrs_hash, define_opaque } ;
661+ let delayed_lints =
662+ hir:: lints:: DelayedLints { lints : delayed_lints, opt_hash : delayed_lints_hash } ;
638663
639- self . arena . alloc ( hir:: OwnerInfo { nodes, parenting, attrs, trait_map } )
664+ self . arena . alloc ( hir:: OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints } )
640665 }
641666
642667 /// 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