@@ -53,6 +53,7 @@ use rustc_data_structures::tagged_ptr::TaggedRef;
53
53
use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
54
54
use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
55
55
use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId } ;
56
+ use rustc_hir:: lints:: DelayedLint ;
56
57
use rustc_hir:: {
57
58
self as hir, AngleBrackets , ConstArg , GenericArg , HirId , ItemLocalMap , LangItem ,
58
59
LifetimeSource , LifetimeSyntax , ParamName , TraitCandidate ,
@@ -143,6 +144,8 @@ struct LoweringContext<'a, 'hir> {
143
144
allow_for_await : Arc < [ Symbol ] > ,
144
145
allow_async_fn_traits : Arc < [ Symbol ] > ,
145
146
147
+ delayed_lints : Vec < DelayedLint > ,
148
+
146
149
attribute_parser : AttributeParser < ' hir > ,
147
150
}
148
151
@@ -191,7 +194,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
191
194
// interact with `gen`/`async gen` blocks
192
195
allow_async_iterator : [ sym:: gen_future, sym:: async_iterator] . into ( ) ,
193
196
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 ( ) ,
195
199
}
196
200
}
197
201
@@ -200,6 +204,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
200
204
}
201
205
}
202
206
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
+
203
223
#[ extension( trait ResolverAstLoweringExt ) ]
204
224
impl ResolverAstLowering {
205
225
fn legacy_const_generic_args ( & self , expr : & Expr ) -> Option < Vec < usize > > {
@@ -575,6 +595,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
575
595
std:: mem:: replace ( & mut self . item_local_id_counter , hir:: ItemLocalId :: new ( 1 ) ) ;
576
596
let current_impl_trait_defs = std:: mem:: take ( & mut self . impl_trait_defs ) ;
577
597
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 ) ;
578
599
579
600
// Do not reset `next_node_id` and `node_id_to_def_id`:
580
601
// 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> {
608
629
self . item_local_id_counter = current_local_counter;
609
630
self . impl_trait_defs = current_impl_trait_defs;
610
631
self . impl_trait_bounds = current_impl_trait_bounds;
632
+ self . delayed_lints = current_delayed_lints;
611
633
612
634
debug_assert ! ( !self . children. iter( ) . any( |( id, _) | id == & owner_id. def_id) ) ;
613
635
self . children . push ( ( owner_id. def_id , hir:: MaybeOwner :: Owner ( info) ) ) ;
@@ -618,6 +640,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
618
640
let mut bodies = std:: mem:: take ( & mut self . bodies ) ;
619
641
let define_opaque = std:: mem:: take ( & mut self . define_opaque ) ;
620
642
let trait_map = std:: mem:: take ( & mut self . trait_map ) ;
643
+ let delayed_lints = std:: mem:: take ( & mut self . delayed_lints ) . into_boxed_slice ( ) ;
621
644
622
645
#[ cfg( debug_assertions) ]
623
646
for ( id, attrs) in attrs. iter ( ) {
@@ -631,14 +654,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
631
654
let bodies = SortedMap :: from_presorted_elements ( bodies) ;
632
655
633
656
// 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) ;
636
659
let num_nodes = self . item_local_id_counter . as_usize ( ) ;
637
660
let ( nodes, parenting) = index:: index_hir ( self . tcx , node, & bodies, num_nodes) ;
638
661
let nodes = hir:: OwnerNodes { opt_hash_including_bodies, nodes, bodies } ;
639
662
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 } ;
640
665
641
- self . arena . alloc ( hir:: OwnerInfo { nodes, parenting, attrs, trait_map } )
666
+ self . arena . alloc ( hir:: OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints } )
642
667
}
643
668
644
669
/// 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
+ defid : 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