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).