Rollup merge of #148839 - luca3s:rtsan_ice_fix, r=WaffleLapkin

fix rtsan_nonblocking_async lint closure ICE

Fixes https://github.com/rust-lang/rust/issues/148750, which i introduced in https://github.com/rust-lang/rust/pull/147935.
I also added the bug report to the tests.
This commit is contained in:
Stuart Cook 2025-11-13 11:57:08 +11:00 committed by GitHub
commit 20f111f0d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 6 deletions

View file

@ -469,16 +469,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(

View file

@ -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
};
}