Skip to content

Commit 6070343

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 58b95c9 commit 6070343

32 files changed

+127
-409
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ codegen_ssa_invalid_monomorphization_unsupported_symbol = invalid monomorphizati
171171
172172
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}`
173173
174-
codegen_ssa_invalid_no_sanitize = invalid argument for `no_sanitize`
175-
.note = expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`
176-
177174
codegen_ssa_invalid_sanitize = invalid argument for `sanitize`
178175
.note = expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`
179176

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
8686
let rust_target_features = tcx.rust_target_features(LOCAL_CRATE);
8787

8888
let mut link_ordinal_span = None;
89-
let mut no_sanitize_span = None;
9089
let mut sanitize_span = None;
9190

9291
for attr in attrs.iter() {
@@ -257,39 +256,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
257256
codegen_fn_attrs.link_ordinal = ordinal;
258257
}
259258
}
260-
sym::no_sanitize => {
261-
no_sanitize_span = Some(attr.span());
262-
if let Some(list) = attr.meta_item_list() {
263-
for item in list.iter() {
264-
match item.name() {
265-
Some(sym::address) => {
266-
codegen_fn_attrs.no_sanitize |=
267-
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS
268-
}
269-
Some(sym::cfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI,
270-
Some(sym::kcfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI,
271-
Some(sym::memory) => {
272-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY
273-
}
274-
Some(sym::memtag) => {
275-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG
276-
}
277-
Some(sym::shadow_call_stack) => {
278-
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK
279-
}
280-
Some(sym::thread) => {
281-
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD
282-
}
283-
Some(sym::hwaddress) => {
284-
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS
285-
}
286-
_ => {
287-
tcx.dcx().emit_err(errors::InvalidNoSanitize { span: item.span() });
288-
}
289-
}
290-
}
291-
}
292-
}
293259
sym::sanitize => sanitize_span = Some(attr.span()),
294260
sym::instruction_set => {
295261
codegen_fn_attrs.instruction_set =
@@ -457,16 +423,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
457423
tcx.dcx().span_err(span, "cannot use `#[inline(always)]` with `#[target_feature]`");
458424
}
459425

460-
if !codegen_fn_attrs.no_sanitize.is_empty()
461-
&& codegen_fn_attrs.inline.always()
462-
&& let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span)
463-
{
464-
let hir_id = tcx.local_def_id_to_hir_id(did);
465-
tcx.node_span_lint(lint::builtin::INLINE_NO_SANITIZE, hir_id, no_sanitize_span, |lint| {
466-
lint.primary_message("`no_sanitize` will have no effect after inlining");
467-
lint.span_note(inline_span, "inlining requested here");
468-
})
469-
}
470426
if !codegen_fn_attrs.no_sanitize.is_empty()
471427
&& codegen_fn_attrs.inline.always()
472428
&& 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
@@ -1100,14 +1100,6 @@ impl IntoDiagArg for ExpectedPointerMutability {
11001100
}
11011101
}
11021102

1103-
#[derive(Diagnostic)]
1104-
#[diag(codegen_ssa_invalid_no_sanitize)]
1105-
#[note]
1106-
pub(crate) struct InvalidNoSanitize {
1107-
#[primary_span]
1108-
pub span: Span,
1109-
}
1110-
11111103
#[derive(Diagnostic)]
11121104
#[diag(codegen_ssa_invalid_sanitize)]
11131105
#[note]

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
539539
),
540540
ungated!(track_caller, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes),
541541
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, EncodeCrossCrate::No),
542-
gated!(
543-
no_sanitize, Normal,
544-
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
545-
EncodeCrossCrate::No, experimental!(no_sanitize)
546-
),
547542
gated!(
548543
sanitize, Normal, template!(List: r#"address = "on|off", cfi = "on|off""#), ErrorPreceding,
549544
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
@@ -190,6 +190,9 @@ declare_features! (
190190
(removed, no_coverage, "1.74.0", Some(84605), Some("renamed to `coverage_attribute`"), 114656),
191191
/// Allows `#[no_debug]`.
192192
(removed, no_debug, "1.43.0", Some(29721), Some("removed due to lack of demand"), 69667),
193+
// Allows the use of `no_sanitize` attribute.
194+
/// The feature was renamed to `sanitize` and the attribute to `#[sanitize(xyz = "on|off")]`
195+
(removed, no_sanitize, "CURRENT_RUSTC_VERSION", Some(39699), Some(r#"renamed to sanitize(xyz = "on|off")"#), 1234),
193196
/// Note: this feature was previously recorded in a separate
194197
/// `STABLE_REMOVED` list because it, uniquely, was once stable but was
195198
/// 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
@@ -591,8 +591,6 @@ declare_features! (
591591
(unstable, new_range, "1.86.0", Some(123741)),
592592
/// Allows `#![no_core]`.
593593
(unstable, no_core, "1.3.0", Some(29639)),
594-
/// Allows the use of `no_sanitize` attribute.
595-
(unstable, no_sanitize, "1.42.0", Some(39699)),
596594
/// Allows using the `non_exhaustive_omitted_patterns` lint.
597595
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
598596
/// 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
@@ -2298,18 +2298,18 @@ declare_lint! {
22982298

22992299
declare_lint! {
23002300
/// The `inline_no_sanitize` lint detects incompatible use of
2301-
/// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
2301+
/// [`#[inline(always)]`][inline] and [`#[sanitize(xyz = "off")]`][sanitize].
23022302
///
23032303
/// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2304-
/// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2304+
/// [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
23052305
///
23062306
/// ### Example
23072307
///
23082308
/// ```rust
2309-
/// #![feature(no_sanitize)]
2309+
/// #![feature(sanitize)]
23102310
///
23112311
/// #[inline(always)]
2312-
/// #[no_sanitize(address)]
2312+
/// #[sanitize(address = "off")]
23132313
/// fn x() {}
23142314
///
23152315
/// fn main() {
@@ -2322,11 +2322,11 @@ declare_lint! {
23222322
/// ### Explanation
23232323
///
23242324
/// The use of the [`#[inline(always)]`][inline] attribute prevents the
2325-
/// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
2325+
/// the [`#[sanitize(xyz = "off")]`][sanitize] attribute from working.
23262326
/// Consider temporarily removing `inline` attribute.
23272327
pub INLINE_NO_SANITIZE,
23282328
Warn,
2329-
"detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2329+
r#"detects incompatible use of `#[inline(always)]` and `#[sanitize(... = "off")]`"#,
23302330
}
23312331

23322332
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: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,6 @@ passes_no_mangle_foreign =
537537
.note = symbol names in extern blocks are not mangled
538538
.suggestion = remove this attribute
539539
540-
passes_no_sanitize =
541-
`#[no_sanitize({$attr_str})]` should be applied to {$accepted_kind}
542-
.label = not {$accepted_kind}
543-
544540
passes_non_exhaustive_with_default_field_values =
545541
`#[non_exhaustive]` can't be used to annotate items with default field values
546542
.label = this struct has default field values
@@ -553,7 +549,7 @@ passes_object_lifetime_err =
553549
{$repr}
554550
555551
passes_only_has_effect_on =
556-
`#[{$attr_name}]` only has an effect on {$target_name ->
552+
`#[{$attr_name}]` only has an effect on {$target_nampasses_non_exhaustive_with_default_field_valuese ->
557553
[function] functions
558554
[module] modules
559555
[implementation_block] implementation blocks

compiler/rustc_passes/src/check_attr.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
289289
self.check_diagnostic_on_unimplemented(attr.span(), hir_id, target)
290290
}
291291
[sym::coverage, ..] => self.check_coverage(attr, span, target),
292-
[sym::no_sanitize, ..] => {
293-
self.check_no_sanitize(attr, span, target)
294-
}
295292
[sym::sanitize, ..] => {
296293
self.check_sanitize(attr, span, target)
297294
}
@@ -631,42 +628,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
631628
}
632629
}
633630

634-
fn check_no_sanitize(&self, attr: &Attribute, span: Span, target: Target) {
635-
if let Some(list) = attr.meta_item_list() {
636-
for item in list.iter() {
637-
let sym = item.name();
638-
match sym {
639-
Some(s @ sym::address | s @ sym::hwaddress) => {
640-
let is_valid =
641-
matches!(target, Target::Fn | Target::Method(..) | Target::Static);
642-
if !is_valid {
643-
self.dcx().emit_err(errors::NoSanitize {
644-
attr_span: item.span(),
645-
defn_span: span,
646-
accepted_kind: "a function or static",
647-
attr_str: s.as_str(),
648-
});
649-
}
650-
}
651-
_ => {
652-
let is_valid = matches!(target, Target::Fn | Target::Method(..));
653-
if !is_valid {
654-
self.dcx().emit_err(errors::NoSanitize {
655-
attr_span: item.span(),
656-
defn_span: span,
657-
accepted_kind: "a function",
658-
attr_str: &match sym {
659-
Some(name) => name.to_string(),
660-
None => "...".to_string(),
661-
},
662-
});
663-
}
664-
}
665-
}
666-
}
667-
}
668-
}
669-
670631
/// Checks that the `#[sanitize(..)]` attribute is applied to a
671632
/// function/closure/method, or to an impl block or module.
672633
fn check_sanitize(&self, attr: &Attribute, target_span: Span, target: Target) {

0 commit comments

Comments
 (0)