Skip to content

Commit ab264ae

Browse files
committed
Fix ICE from #105101
1 parent c97b539 commit ab264ae

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
@@ -146,7 +146,7 @@ fn extract_default_variant<'a>(
146146
let suggestion = default_variants
147147
.iter()
148148
.filter_map(|v| {
149-
if v.ident == variant.ident {
149+
if v.span == variant.span {
150150
None
151151
} else {
152152
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)