Skip to content

Commit ee9eaa6

Browse files
authored
Rollup merge of #105106 - jhpratt:issue-105101, r=TaKO8Ki
Fix ICE from #105101 Fixes #105101 Rather than comparing idents, compare spans, which should be unique to each variant.
2 parents 3ec9a6d + ab264ae commit ee9eaa6

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

compiler/rustc_builtin_macros/src/deriving/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn extract_default_variant<'a>(
145145
let suggestion = default_variants
146146
.iter()
147147
.filter_map(|v| {
148-
if v.ident == variant.ident {
148+
if v.span == variant.span {
149149
None
150150
} else {
151151
Some((cx.sess.find_by_name(&v.attrs, kw::Default)?.span, String::new()))

src/test/ui/deriving/issue-105101.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-flags: --crate-type=lib
2+
3+
#[derive(Default)] //~ ERROR multiple declared defaults
4+
enum E {
5+
#[default]
6+
A,
7+
#[default]
8+
A, //~ ERROR defined multiple times
9+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: multiple declared defaults
2+
--> $DIR/issue-105101.rs:3:10
3+
|
4+
LL | #[derive(Default)]
5+
| ^^^^^^^
6+
...
7+
LL | A,
8+
| - first default
9+
LL | #[default]
10+
LL | A,
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[E0428]: the name `A` is defined multiple times
17+
--> $DIR/issue-105101.rs:8:5
18+
|
19+
LL | A,
20+
| - previous definition of the type `A` here
21+
LL | #[default]
22+
LL | A,
23+
| ^ `A` redefined here
24+
|
25+
= note: `A` must be defined only once in the type namespace of this enum
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0428`.

0 commit comments

Comments
 (0)