From 3ffca9e78a835309c7f77b9ce571d214d83de283 Mon Sep 17 00:00:00 2001 From: Bastian Kersting Date: Wed, 20 Aug 2025 19:31:48 +0000 Subject: [PATCH] Don't evaluate the sanitizer attribute if no sanitizer is enabled This is just logical as the attribute has anyways no effect in that case. --- compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index c8690251bd096..266f43ce2bccc 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -630,6 +630,11 @@ fn parse_sanitize_attr( } fn disabled_sanitizers_for(tcx: TyCtxt<'_>, did: LocalDefId) -> SanitizerSet { + // No need to evaluate the sanitizer attribute if no sanitizer is enabled. + if tcx.sess.opts.unstable_opts.sanitizer.is_empty() { + return SanitizerSet::empty(); + } + // Backtrack to the crate root. let disabled = match tcx.opt_local_parent(did) { // Check the parent (recursively).