@@ -242,7 +242,9 @@ impl LintLevelsProvider for LintLevelQueryMap<'_> {
242242
243243struct QueryMapExpectationsWrapper < ' tcx > {
244244 tcx : TyCtxt < ' tcx > ,
245+ /// HirId of the currently investigated element.
245246 cur : HirId ,
247+ /// Level map for `cur`.
246248 specs : ShallowLintLevelMap ,
247249 expectations : Vec < ( LintExpectationId , LintExpectation ) > ,
248250 unstable_to_stable_ids : FxHashMap < LintExpectationId , LintExpectationId > ,
@@ -255,11 +257,11 @@ impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
255257 self . specs . specs . get ( & self . cur . local_id ) . unwrap_or ( & self . empty )
256258 }
257259 fn insert ( & mut self , id : LintId , lvl : LevelAndSource ) {
258- let specs = self . specs . specs . get_mut_or_insert_default ( self . cur . local_id ) ;
259- specs. clear ( ) ;
260- specs. insert ( id, lvl) ;
260+ self . specs . specs . get_mut_or_insert_default ( self . cur . local_id ) . insert ( id, lvl) ;
261261 }
262262 fn get_lint_level ( & self , lint : & ' static Lint , _: & Session ) -> LevelAndSource {
263+ // We cannot use `tcx.lint_level_at_node` because we want to know in which order the
264+ // attributes have been inserted, in particular whether an `expect` follows a `forbid`.
263265 self . specs . lint_level_id_at_node ( self . tcx , LintId :: of ( lint) , self . cur )
264266 }
265267 fn push_expectation ( & mut self , id : LintExpectationId , expectation : LintExpectation ) {
@@ -355,7 +357,9 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
355357
356358impl < ' tcx > LintLevelsBuilder < ' _ , QueryMapExpectationsWrapper < ' tcx > > {
357359 fn add_id ( & mut self , hir_id : HirId ) {
360+ // Change both the `HirId` and the associated specs.
358361 self . provider . cur = hir_id;
362+ self . provider . specs . specs . clear ( ) ;
359363 self . add ( self . provider . tcx . hir ( ) . attrs ( hir_id) , hir_id == hir:: CRATE_HIR_ID , Some ( hir_id) ) ;
360364 }
361365}
0 commit comments