rust/tests/ui/sanitize-attr/valid-sanitize.stderr
Bastian Kersting 3ef065bf87 Implement the #[sanitize(..)] attribute
This change implements the #[sanitize(..)] attribute, which opts to
replace the currently unstable #[no_sanitize]. Essentially the new
attribute works similar as #[no_sanitize], just with more flexible
options regarding where it is applied. E.g. it is possible to turn
a certain sanitizer either on or off:
`#[sanitize(address = "on|off")]`

This attribute now also applies to more places, e.g. it is possible
to turn off a sanitizer for an entire module or impl block:
```rust
\#[sanitize(address = "off")]
mod foo {
    fn unsanitized(..) {}

    #[sanitize(address = "on")]
    fn sanitized(..) {}
}

\#[sanitize(thread = "off")]
impl MyTrait for () {
    ...
}
```

This attribute is enabled behind the unstable `sanitize` feature.
2025-08-18 08:30:00 +00:00

190 lines
6.4 KiB
Text

error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:15:1
|
LL | #[sanitize(thread = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | static BAR: u32 = 0;
| -------------------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:18:1
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | type MyTypeAlias = ();
| ---------------------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:21:1
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | / trait MyTrait {
LL | | #[sanitize(address = "off")]
LL | | const TRAIT_ASSOC_CONST: u32;
... |
LL | | fn trait_assoc_fn();
LL | | }
| |_- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:65:1
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | / struct MyStruct {
LL | | #[sanitize(address = "off")]
LL | | field: u32,
LL | | }
| |_- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:67:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | field: u32,
| ---------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:92:5
|
LL | #[sanitize(address = "off", thread = "on")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _ = ();
| ----------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:98:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _let_closure = || ();
| ------------------------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:109:9
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | () => (),
| -------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:113:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | return ();
| --------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:23:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | const TRAIT_ASSOC_CONST: u32;
| ----------------------------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:26:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | type TraitAssocType;
| -------------------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:29:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn trait_method(&self);
| ----------------------- function has no body
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:35:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn trait_assoc_fn();
| -------------------- function has no body
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:43:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | type TraitAssocType = Self;
| --------------------------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:60:5
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | type T = impl Copy;
| ------------------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:80:5
|
LL | #[sanitize(address = "off", thread = "on")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | static X: u32;
| -------------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:83:5
|
LL | #[sanitize(address = "off", thread = "on")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | type T;
| ------- not a function, impl block, or module
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: sanitize attribute not allowed here
--> $DIR/valid-sanitize.rs:86:5
|
LL | #[sanitize(address = "off", thread = "on")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn foreign_fn();
| ---------------- function has no body
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
error: aborting due to 18 previous errors