From 1bfad0199f0984c6c5a5dcc22cf18ab793e17ab9 Mon Sep 17 00:00:00 2001 From: Lucas Baumann Date: Mon, 10 Nov 2025 15:18:16 +0100 Subject: [PATCH] fix rtsan_nonblocking_async lint closure ICE --- compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 14 ++++++++------ tests/ui/sanitize-attr/invalid-sanitize.rs | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 720f8061c4e66..ad4482383a450 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -468,16 +468,18 @@ fn check_result( }) } - // warn for nonblocking async fn. + // warn for nonblocking async functions, blocks and closures. // This doesn't behave as expected, because the executor can run blocking code without the sanitizer noticing. if codegen_fn_attrs.sanitizers.rtsan_setting == RtsanSetting::Nonblocking && let Some(sanitize_span) = interesting_spans.sanitize - // async function - && (tcx.asyncness(did).is_async() || (tcx.is_closure_like(did.into()) + // async fn + && (tcx.asyncness(did).is_async() // async block - && (tcx.coroutine_is_async(did.into()) - // async closure - || tcx.coroutine_is_async(tcx.coroutine_for_closure(did))))) + || tcx.is_coroutine(did.into()) + // async closure + || (tcx.is_closure_like(did.into()) + && tcx.hir_node_by_def_id(did).expect_closure().kind + != rustc_hir::ClosureKind::Closure)) { let hir_id = tcx.local_def_id_to_hir_id(did); tcx.node_span_lint( diff --git a/tests/ui/sanitize-attr/invalid-sanitize.rs b/tests/ui/sanitize-attr/invalid-sanitize.rs index 63eef51664845..6846b6ff228b2 100644 --- a/tests/ui/sanitize-attr/invalid-sanitize.rs +++ b/tests/ui/sanitize-attr/invalid-sanitize.rs @@ -37,4 +37,9 @@ fn test() { #[sanitize(realtime = "nonblocking")] //~ WARN: the async executor can run blocking code, without realtime sanitizer catching it [rtsan_nonblocking_async] async || {} }; + + let _regular_closure = { + #[sanitize(realtime = "nonblocking")] // no warning on a regular closure + || 0 + }; }