Skip to content

Commit 703d93c

Browse files
committed
Remove the no_sanitize attribute in favor of sanitize
This removes the #[no_sanitize] attribute, which was behind an unstable feature named no_sanitize. Instead, we introduce the sanitize attribute which is more powerful and allows to be extended in the future (instead of just focusing on turning sanitizers off).
1 parent 47e3bc8 commit 703d93c

32 files changed

+126
-408
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ codegen_ssa_invalid_monomorphization_unsupported_symbol = invalid monomorphizati
169169
170170
codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size = invalid monomorphization of `{$name}` intrinsic: unsupported {$symbol} from `{$in_ty}` with element `{$in_elem}` of size `{$size}` to `{$ret_ty}`
171171
172-
codegen_ssa_invalid_no_sanitize = invalid argument for `no_sanitize`
173-
.note = expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`
174-
175172
codegen_ssa_invalid_sanitize = invalid argument for `sanitize`
176173
.note = expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`
177174

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
8585

8686
let mut inline_span = None;
8787
let mut link_ordinal_span = None;
88-
let mut no_sanitize_span = None;
8988
let mut sanitize_span = None;
9089
let mut mixed_export_name_no_mangle_lint_state = MixedExportNameAndNoMangleState::default();
9190
let mut no_mangle_span = None;
@@ -321,39 +320,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
321320
codegen_fn_attrs.link_ordinal = ordinal;
322321
}
323322
}
324-
sym::no_sanitize => {
325-
no_sanitize_span = Some(attr.span());
326-
if let Some(list) = attr.meta_item_list() {
327-
for item in list.iter() {
328-
match item.name() {
329-
Some(sym::address) => {
330-
codegen_fn_attrs.no_sanitize |=
331-
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS
332-
}
333-
Some(sym::cfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI,
334-
Some(sym::kcfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI,
335-
Some(sym::memory) => {
336-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY
337-
}
338-
Some(sym::memtag) => {
339-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG
340-
}
341-
Some(sym::shadow_call_stack) => {
342-
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK
343-
}
344-
Some(sym::thread) => {
345-
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD
346-
}
347-
Some(sym::hwaddress) => {
348-
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS
349-
}
350-
_ => {
351-
tcx.dcx().emit_err(errors::InvalidNoSanitize { span: item.span() });
352-
}
353-
}
354-
}
355-
}
356-
}
357323
sym::sanitize => sanitize_span = Some(attr.span()),
358324
sym::instruction_set => {
359325
codegen_fn_attrs.instruction_set =
@@ -573,16 +539,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
573539
tcx.dcx().span_err(span, "cannot use `#[inline(always)]` with `#[target_feature]`");
574540
}
575541

576-
if !codegen_fn_attrs.no_sanitize.is_empty()
577-
&& codegen_fn_attrs.inline.always()
578-
&& let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span)
579-
{
580-
let hir_id = tcx.local_def_id_to_hir_id(did);
581-
tcx.node_span_lint(lint::builtin::INLINE_NO_SANITIZE, hir_id, no_sanitize_span, |lint| {
582-
lint.primary_message("`no_sanitize` will have no effect after inlining");
583-
lint.span_note(inline_span, "inlining requested here");
584-
})
585-
}
586542
if !codegen_fn_attrs.no_sanitize.is_empty()
587543
&& codegen_fn_attrs.inline.always()
588544
&& let (Some(sanitize_span), Some(inline_span)) = (sanitize_span, inline_span)

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,14 +1136,6 @@ impl IntoDiagArg for ExpectedPointerMutability {
11361136
}
11371137
}
11381138

1139-
#[derive(Diagnostic)]
1140-
#[diag(codegen_ssa_invalid_no_sanitize)]
1141-
#[note]
1142-
pub(crate) struct InvalidNoSanitize {
1143-
#[primary_span]
1144-
pub span: Span,
1145-
}
1146-
11471139
#[derive(Diagnostic)]
11481140
#[diag(codegen_ssa_invalid_sanitize)]
11491141
#[note]

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
521521
),
522522
ungated!(track_caller, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes),
523523
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, EncodeCrossCrate::No),
524-
gated!(
525-
no_sanitize, Normal,
526-
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
527-
EncodeCrossCrate::No, experimental!(no_sanitize)
528-
),
529524
gated!(
530525
sanitize, Normal, template!(List: r#"address = "on|off", cfi = "on|off""#), ErrorPreceding,
531526
EncodeCrossCrate::No, sanitize, experimental!(sanitize),

compiler/rustc_feature/src/removed.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ declare_features! (
186186
(removed, no_coverage, "1.74.0", Some(84605), Some("renamed to `coverage_attribute`"), 114656),
187187
/// Allows `#[no_debug]`.
188188
(removed, no_debug, "1.43.0", Some(29721), Some("removed due to lack of demand"), 69667),
189+
// Allows the use of `no_sanitize` attribute.
190+
/// The feature was renamed to `sanitize` and the attribute to `#[sanitize(xyz = "on|off")]`
191+
(removed, no_sanitize, "CURRENT_RUSTC_VERSION", Some(39699), Some(r#"renamed to sanitize(xyz = "on|off")"#), 1234),
189192
/// Note: this feature was previously recorded in a separate
190193
/// `STABLE_REMOVED` list because it, uniquely, was once stable but was
191194
/// then removed. But there was no utility storing it separately, so now

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,6 @@ declare_features! (
593593
(unstable, new_range, "1.86.0", Some(123741)),
594594
/// Allows `#![no_core]`.
595595
(unstable, no_core, "1.3.0", Some(29639)),
596-
/// Allows the use of `no_sanitize` attribute.
597-
(unstable, no_sanitize, "1.42.0", Some(39699)),
598596
/// Allows using the `non_exhaustive_omitted_patterns` lint.
599597
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
600598
/// Allows `for<T>` binders in where-clauses

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,18 +2296,18 @@ declare_lint! {
22962296

22972297
declare_lint! {
22982298
/// The `inline_no_sanitize` lint detects incompatible use of
2299-
/// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
2299+
/// [`#[inline(always)]`][inline] and [`#[sanitize(xyz = "off")]`][sanitize].
23002300
///
23012301
/// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2302-
/// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2302+
/// [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
23032303
///
23042304
/// ### Example
23052305
///
23062306
/// ```rust
2307-
/// #![feature(no_sanitize)]
2307+
/// #![feature(sanitize)]
23082308
///
23092309
/// #[inline(always)]
2310-
/// #[no_sanitize(address)]
2310+
/// #[sanitize(address = "off")]
23112311
/// fn x() {}
23122312
///
23132313
/// fn main() {
@@ -2320,11 +2320,11 @@ declare_lint! {
23202320
/// ### Explanation
23212321
///
23222322
/// The use of the [`#[inline(always)]`][inline] attribute prevents the
2323-
/// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
2323+
/// the [`#[sanitize(xyz = "off")]`][sanitize] attribute from working.
23242324
/// Consider temporarily removing `inline` attribute.
23252325
pub INLINE_NO_SANITIZE,
23262326
Warn,
2327-
"detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2327+
r#"detects incompatible use of `#[inline(always)]` and `#[sanitize(... = "off")]`"#,
23282328
}
23292329

23302330
declare_lint! {

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub struct CodegenFnAttrs {
4040
/// The `#[link_section = "..."]` attribute, or what executable section this
4141
/// should be placed in.
4242
pub link_section: Option<Symbol>,
43-
/// The `#[no_sanitize(...)]` attribute. Indicates sanitizers for which
44-
/// instrumentation should be disabled inside the annotated function.
43+
/// The `#[sanitize(xyz = "off")]` attribute. Indicates sanitizers for which
44+
/// instrumentation should be disabled inside the function.
4545
pub no_sanitize: SanitizerSet,
4646
/// The `#[instruction_set(set)]` attribute. Indicates if the generated code should
4747
/// be generated against a specific instruction set. Only usable on architectures which allow

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,6 @@ passes_no_mangle_foreign =
526526
.note = symbol names in extern blocks are not mangled
527527
.suggestion = remove this attribute
528528
529-
passes_no_sanitize =
530-
`#[no_sanitize({$attr_str})]` should be applied to {$accepted_kind}
531-
.label = not {$accepted_kind}
532-
533529
passes_non_exaustive_with_default_field_values =
534530
`#[non_exhaustive]` can't be used to annotate items with default field values
535531
.label = this struct has default field values

compiler/rustc_passes/src/check_attr.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
161161
[sym::inline, ..] => self.check_inline(hir_id, attr, span, target),
162162
[sym::coverage, ..] => self.check_coverage(attr, span, target),
163163
[sym::optimize, ..] => self.check_optimize(hir_id, attr, span, target),
164-
[sym::no_sanitize, ..] => {
165-
self.check_no_sanitize(attr, span, target)
166-
}
167164
[sym::sanitize, ..] => {
168165
self.check_sanitize(attr, span, target)
169166
}
@@ -537,42 +534,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
537534
}
538535
}
539536

540-
fn check_no_sanitize(&self, attr: &Attribute, span: Span, target: Target) {
541-
if let Some(list) = attr.meta_item_list() {
542-
for item in list.iter() {
543-
let sym = item.name();
544-
match sym {
545-
Some(s @ sym::address | s @ sym::hwaddress) => {
546-
let is_valid =
547-
matches!(target, Target::Fn | Target::Method(..) | Target::Static);
548-
if !is_valid {
549-
self.dcx().emit_err(errors::NoSanitize {
550-
attr_span: item.span(),
551-
defn_span: span,
552-
accepted_kind: "a function or static",
553-
attr_str: s.as_str(),
554-
});
555-
}
556-
}
557-
_ => {
558-
let is_valid = matches!(target, Target::Fn | Target::Method(..));
559-
if !is_valid {
560-
self.dcx().emit_err(errors::NoSanitize {
561-
attr_span: item.span(),
562-
defn_span: span,
563-
accepted_kind: "a function",
564-
attr_str: &match sym {
565-
Some(name) => name.to_string(),
566-
None => "...".to_string(),
567-
},
568-
});
569-
}
570-
}
571-
}
572-
}
573-
}
574-
}
575-
576537
/// Checks that the `#[sanitize(..)]` attribute is applied to a
577538
/// function/closure/method, or to an impl block or module.
578539
fn check_sanitize(&self, attr: &Attribute, target_span: Span, target: Target) {

0 commit comments

Comments
 (0)