rust/tests/ui/attributes/no-sanitize.rs
Nicholas Nethercote 2fef0a30ae Replace infallible name_or_empty methods with fallible name methods.
I'm removing empty identifiers everywhere, because in practice they
always mean "no identifier" rather than "empty identifier". (An empty
identifier is impossible.) It's better to use `Option` to mean "no
identifier" because you then can't forget about the "no identifier"
possibility.

Some specifics:
- When testing an attribute for a single name, the commit uses the
  `has_name` method.
- When testing an attribute for multiple names, the commit uses the new
  `has_any_name` method.
- When using `match` on an attribute, the match arms now have `Some` on
  them.

In the tests, we now avoid printing empty identifiers by not printing
the identifier in the `error:` line at all, instead letting the carets
point out the problem.
2025-04-17 09:50:52 +10:00

46 lines
1.2 KiB
Rust

#![feature(no_sanitize)]
#![feature(stmt_expr_attributes)]
#![deny(unused_attributes)]
#![allow(dead_code)]
fn invalid() {
#[no_sanitize(memory)] //~ ERROR `#[no_sanitize(memory)]` should be applied to a function
{
1
};
}
#[no_sanitize(memory)] //~ ERROR `#[no_sanitize(memory)]` should be applied to a function
type InvalidTy = ();
#[no_sanitize(memory)] //~ ERROR `#[no_sanitize(memory)]` should be applied to a function
mod invalid_module {}
fn main() {
let _ = #[no_sanitize(memory)] //~ ERROR `#[no_sanitize(memory)]` should be applied to a function
(|| 1);
}
#[no_sanitize(memory)] //~ ERROR `#[no_sanitize(memory)]` should be applied to a function
struct F;
#[no_sanitize(memory)] //~ ERROR `#[no_sanitize(memory)]` should be applied to a function
impl F {
#[no_sanitize(memory)]
fn valid(&self) {}
}
#[no_sanitize(address, memory)] //~ ERROR `#[no_sanitize(memory)]` should be applied to a function
static INVALID : i32 = 0;
#[no_sanitize(memory)]
fn valid() {}
#[no_sanitize(address)]
static VALID : i32 = 0;
#[no_sanitize("address")]
//~^ ERROR `#[no_sanitize(...)]` should be applied to a function
//~| ERROR invalid argument for `no_sanitize`
static VALID2 : i32 = 0;