@@ -51,6 +51,7 @@ use rustc_data_structures::tagged_ptr::TaggedRef;
51
51
use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
52
52
use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
53
53
use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId } ;
54
+ use rustc_hir:: lints:: DelayedLint ;
54
55
use rustc_hir:: {
55
56
self as hir, AngleBrackets , ConstArg , GenericArg , HirId , ItemLocalMap , LangItem ,
56
57
LifetimeSource , LifetimeSyntax , ParamName , TraitCandidate ,
@@ -141,6 +142,8 @@ struct LoweringContext<'a, 'hir> {
141
142
allow_for_await : Arc < [ Symbol ] > ,
142
143
allow_async_fn_traits : Arc < [ Symbol ] > ,
143
144
145
+ delayed_lints : Vec < DelayedLint > ,
146
+
144
147
attribute_parser : AttributeParser < ' hir > ,
145
148
}
146
149
@@ -190,6 +193,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
190
193
allow_async_iterator : [ sym:: gen_future, sym:: async_iterator] . into ( ) ,
191
194
192
195
attribute_parser : AttributeParser :: new ( tcx. sess , tcx. features ( ) , registered_tools) ,
196
+ delayed_lints : Vec :: new ( ) ,
193
197
}
194
198
}
195
199
@@ -198,6 +202,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
198
202
}
199
203
}
200
204
205
+ struct SpanLowerer {
206
+ is_incremental : bool ,
207
+ def_id : LocalDefId ,
208
+ }
209
+
210
+ impl SpanLowerer {
211
+ fn lower ( & self , span : Span ) -> Span {
212
+ if self . is_incremental {
213
+ span. with_parent ( Some ( self . def_id ) )
214
+ } else {
215
+ // Do not make spans relative when not using incremental compilation.
216
+ span
217
+ }
218
+ }
219
+ }
220
+
201
221
#[ extension( trait ResolverAstLoweringExt ) ]
202
222
impl ResolverAstLowering {
203
223
fn legacy_const_generic_args ( & self , expr : & Expr ) -> Option < Vec < usize > > {
@@ -573,6 +593,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
573
593
std:: mem:: replace ( & mut self . item_local_id_counter , hir:: ItemLocalId :: new ( 1 ) ) ;
574
594
let current_impl_trait_defs = std:: mem:: take ( & mut self . impl_trait_defs ) ;
575
595
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 ) ;
576
597
577
598
// Do not reset `next_node_id` and `node_id_to_def_id`:
578
599
// 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> {
606
627
self . item_local_id_counter = current_local_counter;
607
628
self . impl_trait_defs = current_impl_trait_defs;
608
629
self . impl_trait_bounds = current_impl_trait_bounds;
630
+ self . delayed_lints = current_delayed_lints;
609
631
610
632
debug_assert ! ( !self . children. iter( ) . any( |( id, _) | id == & owner_id. def_id) ) ;
611
633
self . children . push ( ( owner_id. def_id , hir:: MaybeOwner :: Owner ( info) ) ) ;
@@ -616,6 +638,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
616
638
let mut bodies = std:: mem:: take ( & mut self . bodies ) ;
617
639
let define_opaque = std:: mem:: take ( & mut self . define_opaque ) ;
618
640
let trait_map = std:: mem:: take ( & mut self . trait_map ) ;
641
+ let delayed_lints = std:: mem:: take ( & mut self . delayed_lints ) . into_boxed_slice ( ) ;
619
642
620
643
#[ cfg( debug_assertions) ]
621
644
for ( id, attrs) in attrs. iter ( ) {
@@ -629,14 +652,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
629
652
let bodies = SortedMap :: from_presorted_elements ( bodies) ;
630
653
631
654
// 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) ;
634
657
let num_nodes = self . item_local_id_counter . as_usize ( ) ;
635
658
let ( nodes, parenting) = index:: index_hir ( self . tcx , node, & bodies, num_nodes) ;
636
659
let nodes = hir:: OwnerNodes { opt_hash_including_bodies, nodes, bodies } ;
637
660
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 } ;
638
663
639
- self . arena . alloc ( hir:: OwnerInfo { nodes, parenting, attrs, trait_map } )
664
+ self . arena . alloc ( hir:: OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints } )
640
665
}
641
666
642
667
/// This method allocates a new `HirId` for the given `NodeId`.
@@ -759,15 +784,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
759
784
} )
760
785
}
761
786
787
+ fn span_lowerer ( & self ) -> SpanLowerer {
788
+ SpanLowerer {
789
+ is_incremental : self . tcx . sess . opts . incremental . is_some ( ) ,
790
+ def_id : self . current_hir_id_owner . def_id ,
791
+ }
792
+ }
793
+
762
794
/// Intercept all spans entering HIR.
763
795
/// Mark a span as relative to the current owning item.
764
796
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)
771
798
}
772
799
773
800
fn lower_ident ( & self , ident : Ident ) -> Ident {
@@ -889,7 +916,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
889
916
if attrs. is_empty ( ) {
890
917
& [ ]
891
918
} 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 ) ;
893
920
894
921
debug_assert_eq ! ( id. owner, self . current_hir_id_owner) ;
895
922
let ret = self . arena . alloc_from_iter ( lowered_attrs) ;
@@ -909,9 +936,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
909
936
}
910
937
}
911
938
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
+ )
915
956
}
916
957
917
958
fn alias_attrs ( & mut self , id : HirId , target_id : HirId ) {
0 commit comments