@@ -242,7 +242,9 @@ impl LintLevelsProvider for LintLevelQueryMap<'_> {
242
242
243
243
struct QueryMapExpectationsWrapper < ' tcx > {
244
244
tcx : TyCtxt < ' tcx > ,
245
+ /// HirId of the currently investigated element.
245
246
cur : HirId ,
247
+ /// Level map for `cur`.
246
248
specs : ShallowLintLevelMap ,
247
249
expectations : Vec < ( LintExpectationId , LintExpectation ) > ,
248
250
unstable_to_stable_ids : FxHashMap < LintExpectationId , LintExpectationId > ,
@@ -255,11 +257,11 @@ impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
255
257
self . specs . specs . get ( & self . cur . local_id ) . unwrap_or ( & self . empty )
256
258
}
257
259
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) ;
261
261
}
262
262
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`.
263
265
self . specs . lint_level_id_at_node ( self . tcx , LintId :: of ( lint) , self . cur )
264
266
}
265
267
fn push_expectation ( & mut self , id : LintExpectationId , expectation : LintExpectation ) {
@@ -355,7 +357,9 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
355
357
356
358
impl < ' tcx > LintLevelsBuilder < ' _ , QueryMapExpectationsWrapper < ' tcx > > {
357
359
fn add_id ( & mut self , hir_id : HirId ) {
360
+ // Change both the `HirId` and the associated specs.
358
361
self . provider . cur = hir_id;
362
+ self . provider . specs . specs . clear ( ) ;
359
363
self . add ( self . provider . tcx . hir ( ) . attrs ( hir_id) , hir_id == hir:: CRATE_HIR_ID , Some ( hir_id) ) ;
360
364
}
361
365
}
0 commit comments