rust/tests/ui/macros/missing-derive-1.rs
Esteban Küber 92a798dac0 Detect when attribute is provided by missing derive macro
```
error: cannot find attribute `empty_helper` in this scope
  --> $DIR/derive-helper-legacy-limits.rs:17:3
   |
LL | #[empty_helper]
   |   ^^^^^^^^^^^^
   |
help: `empty_helper` is an attribute that can be used by the derive macro `Empty`, you might be missing a `derive` attribute
   |
LL + #[derive(Empty)]
LL | struct S2;
   |
```

Look at proc-macro attributes when encountering unknown attribute

```
error: cannot find attribute `sede` in this scope
  --> src/main.rs:18:7
   |
18 |     #[sede(untagged)]
   |       ^^^^
   |
help: the derive macros `Serialize` and `Deserialize` accept the similarly named `serde` attribute
   |
18 |     #[serde(untagged)]
   |       ~~~~~

error: cannot find attribute `serde` in this scope
  --> src/main.rs:12:7
   |
12 |     #[serde(untagged)]
   |       ^^^^^
   |
   = note: `serde` is in scope, but it is a crate, not an attribute
help: `serde` is an attribute that can be used by the derive macros `Serialize` and `Deserialize`, you might be missing a `derive` attribute
   |
10 | #[derive(Serialize, Deserialize)]
   |
```
2025-06-12 21:28:49 +00:00

34 lines
775 B
Rust

//@aux-build:serde.rs
// derive macros imported and used
extern crate serde;
use serde::{Serialize, Deserialize};
#[serde(untagged)] //~ ERROR cannot find attribute `serde`
enum A { //~ HELP `serde` is an attribute that can be used by the derive macros `Deserialize` and `Serialize`
A,
B,
}
enum B { //~ HELP `serde` is an attribute that can be used by the derive macros `Deserialize` and `Serialize`
A,
#[serde(untagged)] //~ ERROR cannot find attribute `serde`
B,
}
enum C {
A,
#[sede(untagged)] //~ ERROR cannot find attribute `sede`
B, //~^ HELP the derive macros `Deserialize` and `Serialize` accept the similarly named `serde` attribute
}
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
enum D {
A,
B,
}
fn main() {}