@@ -5,7 +5,7 @@ use itertools::Itertools;
55use rustc_hir:: def_id:: LocalDefId ;
66use rustc_hir:: intravisit:: { Visitor , walk_block, walk_expr, walk_stmt} ;
77use rustc_hir:: { BlockCheckMode , Expr , ExprKind , HirId , Stmt , UnsafeSource } ;
8- use rustc_lint:: { LateContext , LateLintPass } ;
8+ use rustc_lint:: { LateContext , LateLintPass , Level , LintContext } ;
99use rustc_session:: impl_lint_pass;
1010use rustc_span:: { Span , SyntaxContext , sym} ;
1111use std:: collections:: BTreeMap ;
@@ -249,6 +249,14 @@ impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
249249 } )
250250 . flatten ( )
251251 . copied ( )
252+ . inspect ( |& unsafe_block| {
253+ if let Level :: Expect ( id) = cx. tcx . lint_level_at_node ( MACRO_METAVARS_IN_UNSAFE , unsafe_block) . 0 {
254+ // Since we're going to deduplicate expanded unsafe blocks by its enclosing macro definition soon,
255+ // which would lead to unfulfilled `#[expect()]`s in all other unsafe blocks that are filtered out except for the one
256+ // we emit the warning at, we must manually fulfill the lint for all unsafe blocks here.
257+ cx. fulfill_expectation ( id) ;
258+ }
259+ } )
252260 . map ( |id| {
253261 // Remove the syntax context to hide "in this macro invocation" in the diagnostic.
254262 // The invocation doesn't matter. Also we want to dedupe by the unsafe block and not by anything
0 commit comments