@@ -39,7 +39,7 @@ use rustc_session::lint::{
3939} ;
4040use rustc_session:: Session ;
4141use rustc_span:: symbol:: { sym, Symbol } ;
42- use rustc_span:: { AttrId , Span , DUMMY_SP } ;
42+ use rustc_span:: { Span , DUMMY_SP } ;
4343use tracing:: { debug, instrument} ;
4444
4545use crate :: errors:: {
@@ -123,34 +123,6 @@ impl LintLevelSets {
123123 }
124124}
125125
126- fn lint_expectations ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Vec < ( LintExpectationId , LintExpectation ) > {
127- let store = unerased_lint_store ( tcx. sess ) ;
128-
129- let mut builder = LintLevelsBuilder {
130- sess : tcx. sess ,
131- features : tcx. features ( ) ,
132- provider : QueryMapExpectationsWrapper {
133- tcx,
134- cur : hir:: CRATE_HIR_ID ,
135- specs : ShallowLintLevelMap :: default ( ) ,
136- expectations : Vec :: new ( ) ,
137- unstable_to_stable_ids : FxIndexMap :: default ( ) ,
138- empty : FxIndexMap :: default ( ) ,
139- } ,
140- lint_added_lints : false ,
141- store,
142- registered_tools : tcx. registered_tools ( ( ) ) ,
143- } ;
144-
145- builder. add_command_line ( ) ;
146- builder. add_id ( hir:: CRATE_HIR_ID ) ;
147- tcx. hir ( ) . walk_toplevel_module ( & mut builder) ;
148-
149- tcx. dcx ( ) . update_unstable_expectation_id ( builder. provider . unstable_to_stable_ids ) ;
150-
151- builder. provider . expectations
152- }
153-
154126#[ instrument( level = "trace" , skip( tcx) , ret) ]
155127fn shallow_lint_levels_on ( tcx : TyCtxt < ' _ > , owner : hir:: OwnerId ) -> ShallowLintLevelMap {
156128 let store = unerased_lint_store ( tcx. sess ) ;
@@ -215,7 +187,7 @@ pub trait LintLevelsProvider {
215187 fn current_specs ( & self ) -> & FxIndexMap < LintId , LevelAndSource > ;
216188 fn insert ( & mut self , id : LintId , lvl : LevelAndSource ) ;
217189 fn get_lint_level ( & self , lint : & ' static Lint , sess : & Session ) -> LevelAndSource ;
218- fn push_expectation ( & mut self , _id : LintExpectationId , _expectation : LintExpectation ) { }
190+ fn push_expectation ( & mut self , id : LintExpectationId , expectation : LintExpectation ) ;
219191}
220192
221193impl LintLevelsProvider for TopDown {
@@ -230,6 +202,8 @@ impl LintLevelsProvider for TopDown {
230202 fn get_lint_level ( & self , lint : & ' static Lint , sess : & Session ) -> LevelAndSource {
231203 self . sets . get_lint_level ( lint, self . cur , Some ( self . current_specs ( ) ) , sess)
232204 }
205+
206+ fn push_expectation ( & mut self , _: LintExpectationId , _: LintExpectation ) { }
233207}
234208
235209struct LintLevelQueryMap < ' tcx > {
@@ -251,46 +225,8 @@ impl LintLevelsProvider for LintLevelQueryMap<'_> {
251225 fn get_lint_level ( & self , lint : & ' static Lint , _: & Session ) -> LevelAndSource {
252226 self . specs . lint_level_id_at_node ( self . tcx , LintId :: of ( lint) , self . cur )
253227 }
254- }
255-
256- struct QueryMapExpectationsWrapper < ' tcx > {
257- tcx : TyCtxt < ' tcx > ,
258- /// HirId of the currently investigated element.
259- cur : HirId ,
260- /// Level map for `cur`.
261- specs : ShallowLintLevelMap ,
262- expectations : Vec < ( LintExpectationId , LintExpectation ) > ,
263- unstable_to_stable_ids : FxIndexMap < AttrId , LintExpectationId > ,
264- /// Empty hash map to simplify code.
265- empty : FxIndexMap < LintId , LevelAndSource > ,
266- }
267-
268- impl LintLevelsProvider for QueryMapExpectationsWrapper < ' _ > {
269- fn current_specs ( & self ) -> & FxIndexMap < LintId , LevelAndSource > {
270- self . specs . specs . get ( & self . cur . local_id ) . unwrap_or ( & self . empty )
271- }
272- fn insert ( & mut self , id : LintId , lvl : LevelAndSource ) {
273- self . specs . specs . get_mut_or_insert_default ( self . cur . local_id ) . insert ( id, lvl) ;
274- }
275- fn get_lint_level ( & self , lint : & ' static Lint , _: & Session ) -> LevelAndSource {
276- // We cannot use `tcx.lint_level_at_node` because we want to know in which order the
277- // attributes have been inserted, in particular whether an `expect` follows a `forbid`.
278- self . specs . lint_level_id_at_node ( self . tcx , LintId :: of ( lint) , self . cur )
279- }
280228 fn push_expectation ( & mut self , id : LintExpectationId , expectation : LintExpectation ) {
281- let LintExpectationId :: Stable { attr_id : Some ( attr_id) , hir_id, attr_index, .. } = id
282- else {
283- bug ! ( "unstable expectation id should already be mapped" )
284- } ;
285-
286- self . unstable_to_stable_ids . entry ( attr_id) . or_insert ( LintExpectationId :: Stable {
287- hir_id,
288- attr_index,
289- lint_index : None ,
290- attr_id : None ,
291- } ) ;
292-
293- self . expectations . push ( ( id. normalize ( ) , expectation) ) ;
229+ self . specs . expectations . push ( ( id. normalize ( ) , expectation) )
294230 }
295231}
296232
@@ -375,80 +311,6 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
375311 }
376312}
377313
378- impl < ' tcx > LintLevelsBuilder < ' _ , QueryMapExpectationsWrapper < ' tcx > > {
379- fn add_id ( & mut self , hir_id : HirId ) {
380- // Change both the `HirId` and the associated specs.
381- self . provider . cur = hir_id;
382- self . provider . specs . specs . clear ( ) ;
383- self . add ( self . provider . tcx . hir ( ) . attrs ( hir_id) , hir_id == hir:: CRATE_HIR_ID , Some ( hir_id) ) ;
384- }
385- }
386-
387- impl < ' tcx > Visitor < ' tcx > for LintLevelsBuilder < ' _ , QueryMapExpectationsWrapper < ' tcx > > {
388- type NestedFilter = nested_filter:: All ;
389-
390- fn nested_visit_map ( & mut self ) -> Self :: Map {
391- self . provider . tcx . hir ( )
392- }
393-
394- fn visit_param ( & mut self , param : & ' tcx hir:: Param < ' tcx > ) {
395- self . add_id ( param. hir_id ) ;
396- intravisit:: walk_param ( self , param) ;
397- }
398-
399- fn visit_item ( & mut self , it : & ' tcx hir:: Item < ' tcx > ) {
400- self . add_id ( it. hir_id ( ) ) ;
401- intravisit:: walk_item ( self , it) ;
402- }
403-
404- fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem < ' tcx > ) {
405- self . add_id ( it. hir_id ( ) ) ;
406- intravisit:: walk_foreign_item ( self , it) ;
407- }
408-
409- fn visit_stmt ( & mut self , e : & ' tcx hir:: Stmt < ' tcx > ) {
410- // We will call `add_id` when we walk
411- // the `StmtKind`. The outer statement itself doesn't
412- // define the lint levels.
413- intravisit:: walk_stmt ( self , e) ;
414- }
415-
416- fn visit_expr ( & mut self , e : & ' tcx hir:: Expr < ' tcx > ) {
417- self . add_id ( e. hir_id ) ;
418- intravisit:: walk_expr ( self , e) ;
419- }
420-
421- fn visit_field_def ( & mut self , s : & ' tcx hir:: FieldDef < ' tcx > ) {
422- self . add_id ( s. hir_id ) ;
423- intravisit:: walk_field_def ( self , s) ;
424- }
425-
426- fn visit_variant ( & mut self , v : & ' tcx hir:: Variant < ' tcx > ) {
427- self . add_id ( v. hir_id ) ;
428- intravisit:: walk_variant ( self , v) ;
429- }
430-
431- fn visit_local ( & mut self , l : & ' tcx hir:: LetStmt < ' tcx > ) {
432- self . add_id ( l. hir_id ) ;
433- intravisit:: walk_local ( self , l) ;
434- }
435-
436- fn visit_arm ( & mut self , a : & ' tcx hir:: Arm < ' tcx > ) {
437- self . add_id ( a. hir_id ) ;
438- intravisit:: walk_arm ( self , a) ;
439- }
440-
441- fn visit_trait_item ( & mut self , trait_item : & ' tcx hir:: TraitItem < ' tcx > ) {
442- self . add_id ( trait_item. hir_id ( ) ) ;
443- intravisit:: walk_trait_item ( self , trait_item) ;
444- }
445-
446- fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem < ' tcx > ) {
447- self . add_id ( impl_item. hir_id ( ) ) ;
448- intravisit:: walk_impl_item ( self , impl_item) ;
449- }
450- }
451-
452314pub struct LintLevelsBuilder < ' s , P > {
453315 sess : & ' s Session ,
454316 features : & ' s Features ,
@@ -1109,7 +971,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
1109971}
1110972
1111973pub ( crate ) fn provide ( providers : & mut Providers ) {
1112- * providers = Providers { shallow_lint_levels_on, lint_expectations , ..* providers } ;
974+ * providers = Providers { shallow_lint_levels_on, ..* providers } ;
1113975}
1114976
1115977pub fn parse_lint_and_tool_name ( lint_name : & str ) -> ( Option < Symbol > , & str ) {
0 commit comments