@@ -20,7 +20,7 @@ use rustc_session::lint::builtin::{
2020use rustc_session:: lint:: { Level , Lint , LintExpectationId , LintId } ;
2121use rustc_session:: Session ;
2222use rustc_span:: symbol:: { sym, Symbol } ;
23- use rustc_span:: { AttrId , Span , DUMMY_SP } ;
23+ use rustc_span:: { Span , DUMMY_SP } ;
2424use tracing:: { debug, instrument} ;
2525use { rustc_ast as ast, rustc_hir as hir} ;
2626
@@ -115,34 +115,6 @@ impl LintLevelSets {
115115 }
116116}
117117
118- fn lint_expectations ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Vec < ( LintExpectationId , LintExpectation ) > {
119- let store = unerased_lint_store ( tcx. sess ) ;
120-
121- let mut builder = LintLevelsBuilder {
122- sess : tcx. sess ,
123- features : tcx. features ( ) ,
124- provider : QueryMapExpectationsWrapper {
125- tcx,
126- cur : hir:: CRATE_HIR_ID ,
127- specs : ShallowLintLevelMap :: default ( ) ,
128- expectations : Vec :: new ( ) ,
129- unstable_to_stable_ids : FxIndexMap :: default ( ) ,
130- empty : FxIndexMap :: default ( ) ,
131- } ,
132- lint_added_lints : false ,
133- store,
134- registered_tools : tcx. registered_tools ( ( ) ) ,
135- } ;
136-
137- builder. add_command_line ( ) ;
138- builder. add_id ( hir:: CRATE_HIR_ID ) ;
139- tcx. hir ( ) . walk_toplevel_module ( & mut builder) ;
140-
141- tcx. dcx ( ) . update_unstable_expectation_id ( builder. provider . unstable_to_stable_ids ) ;
142-
143- builder. provider . expectations
144- }
145-
146118#[ instrument( level = "trace" , skip( tcx) , ret) ]
147119fn shallow_lint_levels_on ( tcx : TyCtxt < ' _ > , owner : hir:: OwnerId ) -> ShallowLintLevelMap {
148120 let store = unerased_lint_store ( tcx. sess ) ;
@@ -207,7 +179,7 @@ pub trait LintLevelsProvider {
207179 fn current_specs ( & self ) -> & FxIndexMap < LintId , LevelAndSource > ;
208180 fn insert ( & mut self , id : LintId , lvl : LevelAndSource ) ;
209181 fn get_lint_level ( & self , lint : & ' static Lint , sess : & Session ) -> LevelAndSource ;
210- fn push_expectation ( & mut self , _id : LintExpectationId , _expectation : LintExpectation ) { }
182+ fn push_expectation ( & mut self , id : LintExpectationId , expectation : LintExpectation ) ;
211183}
212184
213185impl LintLevelsProvider for TopDown {
@@ -222,6 +194,8 @@ impl LintLevelsProvider for TopDown {
222194 fn get_lint_level ( & self , lint : & ' static Lint , sess : & Session ) -> LevelAndSource {
223195 self . sets . get_lint_level ( lint, self . cur , Some ( self . current_specs ( ) ) , sess)
224196 }
197+
198+ fn push_expectation ( & mut self , _: LintExpectationId , _: LintExpectation ) { }
225199}
226200
227201struct LintLevelQueryMap < ' tcx > {
@@ -243,46 +217,8 @@ impl LintLevelsProvider for LintLevelQueryMap<'_> {
243217 fn get_lint_level ( & self , lint : & ' static Lint , _: & Session ) -> LevelAndSource {
244218 self . specs . lint_level_id_at_node ( self . tcx , LintId :: of ( lint) , self . cur )
245219 }
246- }
247-
248- struct QueryMapExpectationsWrapper < ' tcx > {
249- tcx : TyCtxt < ' tcx > ,
250- /// HirId of the currently investigated element.
251- cur : HirId ,
252- /// Level map for `cur`.
253- specs : ShallowLintLevelMap ,
254- expectations : Vec < ( LintExpectationId , LintExpectation ) > ,
255- unstable_to_stable_ids : FxIndexMap < AttrId , LintExpectationId > ,
256- /// Empty hash map to simplify code.
257- empty : FxIndexMap < LintId , LevelAndSource > ,
258- }
259-
260- impl LintLevelsProvider for QueryMapExpectationsWrapper < ' _ > {
261- fn current_specs ( & self ) -> & FxIndexMap < LintId , LevelAndSource > {
262- self . specs . specs . get ( & self . cur . local_id ) . unwrap_or ( & self . empty )
263- }
264- fn insert ( & mut self , id : LintId , lvl : LevelAndSource ) {
265- self . specs . specs . get_mut_or_insert_default ( self . cur . local_id ) . insert ( id, lvl) ;
266- }
267- fn get_lint_level ( & self , lint : & ' static Lint , _: & Session ) -> LevelAndSource {
268- // We cannot use `tcx.lint_level_at_node` because we want to know in which order the
269- // attributes have been inserted, in particular whether an `expect` follows a `forbid`.
270- self . specs . lint_level_id_at_node ( self . tcx , LintId :: of ( lint) , self . cur )
271- }
272220 fn push_expectation ( & mut self , id : LintExpectationId , expectation : LintExpectation ) {
273- let LintExpectationId :: Stable { attr_id : Some ( attr_id) , hir_id, attr_index, .. } = id
274- else {
275- bug ! ( "unstable expectation id should already be mapped" )
276- } ;
277-
278- self . unstable_to_stable_ids . entry ( attr_id) . or_insert ( LintExpectationId :: Stable {
279- hir_id,
280- attr_index,
281- lint_index : None ,
282- attr_id : None ,
283- } ) ;
284-
285- self . expectations . push ( ( id. normalize ( ) , expectation) ) ;
221+ self . specs . expectations . push ( ( id. normalize ( ) , expectation) )
286222 }
287223}
288224
@@ -367,80 +303,6 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
367303 }
368304}
369305
370- impl < ' tcx > LintLevelsBuilder < ' _ , QueryMapExpectationsWrapper < ' tcx > > {
371- fn add_id ( & mut self , hir_id : HirId ) {
372- // Change both the `HirId` and the associated specs.
373- self . provider . cur = hir_id;
374- self . provider . specs . specs . clear ( ) ;
375- self . add ( self . provider . tcx . hir ( ) . attrs ( hir_id) , hir_id == hir:: CRATE_HIR_ID , Some ( hir_id) ) ;
376- }
377- }
378-
379- impl < ' tcx > Visitor < ' tcx > for LintLevelsBuilder < ' _ , QueryMapExpectationsWrapper < ' tcx > > {
380- type NestedFilter = nested_filter:: All ;
381-
382- fn nested_visit_map ( & mut self ) -> Self :: Map {
383- self . provider . tcx . hir ( )
384- }
385-
386- fn visit_param ( & mut self , param : & ' tcx hir:: Param < ' tcx > ) {
387- self . add_id ( param. hir_id ) ;
388- intravisit:: walk_param ( self , param) ;
389- }
390-
391- fn visit_item ( & mut self , it : & ' tcx hir:: Item < ' tcx > ) {
392- self . add_id ( it. hir_id ( ) ) ;
393- intravisit:: walk_item ( self , it) ;
394- }
395-
396- fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem < ' tcx > ) {
397- self . add_id ( it. hir_id ( ) ) ;
398- intravisit:: walk_foreign_item ( self , it) ;
399- }
400-
401- fn visit_stmt ( & mut self , e : & ' tcx hir:: Stmt < ' tcx > ) {
402- // We will call `add_id` when we walk
403- // the `StmtKind`. The outer statement itself doesn't
404- // define the lint levels.
405- intravisit:: walk_stmt ( self , e) ;
406- }
407-
408- fn visit_expr ( & mut self , e : & ' tcx hir:: Expr < ' tcx > ) {
409- self . add_id ( e. hir_id ) ;
410- intravisit:: walk_expr ( self , e) ;
411- }
412-
413- fn visit_field_def ( & mut self , s : & ' tcx hir:: FieldDef < ' tcx > ) {
414- self . add_id ( s. hir_id ) ;
415- intravisit:: walk_field_def ( self , s) ;
416- }
417-
418- fn visit_variant ( & mut self , v : & ' tcx hir:: Variant < ' tcx > ) {
419- self . add_id ( v. hir_id ) ;
420- intravisit:: walk_variant ( self , v) ;
421- }
422-
423- fn visit_local ( & mut self , l : & ' tcx hir:: LetStmt < ' tcx > ) {
424- self . add_id ( l. hir_id ) ;
425- intravisit:: walk_local ( self , l) ;
426- }
427-
428- fn visit_arm ( & mut self , a : & ' tcx hir:: Arm < ' tcx > ) {
429- self . add_id ( a. hir_id ) ;
430- intravisit:: walk_arm ( self , a) ;
431- }
432-
433- fn visit_trait_item ( & mut self , trait_item : & ' tcx hir:: TraitItem < ' tcx > ) {
434- self . add_id ( trait_item. hir_id ( ) ) ;
435- intravisit:: walk_trait_item ( self , trait_item) ;
436- }
437-
438- fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem < ' tcx > ) {
439- self . add_id ( impl_item. hir_id ( ) ) ;
440- intravisit:: walk_impl_item ( self , impl_item) ;
441- }
442- }
443-
444306pub struct LintLevelsBuilder < ' s , P > {
445307 sess : & ' s Session ,
446308 features : & ' s Features ,
@@ -1099,7 +961,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
1099961}
1100962
1101963pub ( crate ) fn provide ( providers : & mut Providers ) {
1102- * providers = Providers { shallow_lint_levels_on, lint_expectations , ..* providers } ;
964+ * providers = Providers { shallow_lint_levels_on, ..* providers } ;
1103965}
1104966
1105967pub ( crate ) fn parse_lint_and_tool_name ( lint_name : & str ) -> ( Option < Symbol > , & str ) {
0 commit comments