You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #118131 - lukas-code:multi-default, r=wesleywiser
improve tool-only help for multiple `#[default]` variants
When defining an enum with multiple `#[default]` variants, we emit a tool-only suggestion for every `#[default]`ed variant to remove all other `#[default]`s. This PR improves the suggestion to correctly handle the cases where one variant has multiple `#[default]`s and where different `#[default]`s have the same span due to macro expansions.
fixes#118119
LL | #[default] // also "HELP make `A` default", but compiletest can't handle multispans
10
+
LL | B,
11
+
| - additional default
12
+
|
13
+
= note: only one variant can be default
14
+
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
15
+
16
+
error: multiple declared defaults
17
+
--> $DIR/multiple-defaults.rs:18:10
18
+
|
19
+
LL | #[derive(Default)]
20
+
| ^^^^^^^
21
+
...
22
+
LL | A,
23
+
| - first default
24
+
LL | #[default]
25
+
LL | A,
26
+
| - additional default
27
+
|
28
+
= note: only one variant can be default
29
+
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
30
+
31
+
error[E0428]: the name `A` is defined multiple times
32
+
--> $DIR/multiple-defaults.rs:23:5
33
+
|
34
+
LL | A,
35
+
| - previous definition of the type `A` here
36
+
LL | #[default]
37
+
LL | A,
38
+
| ^ `A` redefined here
39
+
|
40
+
= note: `A` must be defined only once in the type namespace of this enum
41
+
42
+
error: multiple declared defaults
43
+
--> $DIR/multiple-defaults.rs:31:18
44
+
|
45
+
LL | #[derive(Default)]
46
+
| ^^^^^^^
47
+
...
48
+
LL | $id,
49
+
| ---
50
+
| |
51
+
| first default
52
+
| additional default
53
+
...
54
+
LL | m! { A B }
55
+
| ---------- in this macro invocation
56
+
|
57
+
= note: only one variant can be default
58
+
= note: this error originates in the derive macro `Default` which comes from the expansion of the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
59
+
60
+
error: aborting due to 4 previous errors
61
+
62
+
For more information about this error, try `rustc --explain E0428`.
0 commit comments