Skip to content

Commit 7eac555

Browse files
authored
Rollup merge of rust-lang#64660 - guanqun:unify-errors-for-tuple-struct, r=estebank
unify errors for tuple/struct variants fix rust-lang#63983
2 parents 25bdd76 + e001c5f commit 7eac555

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

src/librustc_resolve/late/diagnostics.rs

+6
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ impl<'a> LateResolutionVisitor<'a, '_> {
445445
(Res::Def(DefKind::Ctor(_, CtorKind::Fictive), _), _) if ns == ValueNS => {
446446
bad_struct_syntax_suggestion();
447447
}
448+
(Res::Def(DefKind::Ctor(_, CtorKind::Fn), _), _) if ns == ValueNS => {
449+
err.span_label(
450+
span,
451+
format!("did you mean `{} ( /* fields */ )`?", path_str),
452+
);
453+
}
448454
(Res::SelfTy(..), _) if ns == ValueNS => {
449455
err.span_label(span, fallback_label);
450456
err.note("can't use `Self` as a constructor, you must use the implemented struct");

src/test/ui/empty/empty-struct-tuple-pat.stderr

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ error[E0532]: expected unit struct/variant or constant, found tuple variant `E::
2020
--> $DIR/empty-struct-tuple-pat.rs:29:9
2121
|
2222
LL | E::Empty4 => ()
23-
| ^^^^^^^^^ not a unit struct/variant or constant
23+
| ^^^^^^^^^ did you mean `E::Empty4 ( /* fields */ )`?
2424

2525
error[E0532]: expected unit struct/variant or constant, found tuple variant `XE::XEmpty5`
2626
--> $DIR/empty-struct-tuple-pat.rs:33:9
2727
|
2828
LL | XE::XEmpty5 => (),
2929
| ^^^^-------
30-
| |
31-
| help: a unit variant with a similar name exists: `XEmpty4`
30+
| | |
31+
| | help: a unit variant with a similar name exists: `XEmpty4`
32+
| did you mean `XE::XEmpty5 ( /* fields */ )`?
3233

3334
error: aborting due to 4 previous errors
3435

src/test/ui/issues/issue-32004.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ error[E0532]: expected unit struct/variant or constant, found tuple variant `Foo
33
|
44
LL | Foo::Bar => {}
55
| ^^^^^---
6-
| |
7-
| help: a unit variant with a similar name exists: `Baz`
6+
| | |
7+
| | help: a unit variant with a similar name exists: `Baz`
8+
| did you mean `Foo::Bar ( /* fields */ )`?
89

910
error[E0532]: expected tuple struct/variant, found unit struct `S`
1011
--> $DIR/issue-32004.rs:16:9

src/test/ui/issues/issue-63983.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
enum MyEnum {
2+
Tuple(i32),
3+
Struct{ s: i32 },
4+
}
5+
6+
fn foo(en: MyEnum) {
7+
match en {
8+
MyEnum::Tuple => "",
9+
//~^ ERROR expected unit struct/variant or constant, found tuple variant `MyEnum::Tuple`
10+
MyEnum::Struct => "",
11+
//~^ ERROR expected unit struct/variant or constant, found struct variant `MyEnum::Struct`
12+
};
13+
}
14+
15+
fn main() {}

src/test/ui/issues/issue-63983.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0532]: expected unit struct/variant or constant, found tuple variant `MyEnum::Tuple`
2+
--> $DIR/issue-63983.rs:8:9
3+
|
4+
LL | MyEnum::Tuple => "",
5+
| ^^^^^^^^^^^^^ did you mean `MyEnum::Tuple ( /* fields */ )`?
6+
7+
error[E0532]: expected unit struct/variant or constant, found struct variant `MyEnum::Struct`
8+
--> $DIR/issue-63983.rs:10:9
9+
|
10+
LL | MyEnum::Struct => "",
11+
| ^^^^^^^^^^^^^^ did you mean `MyEnum::Struct { /* fields */ }`?
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0532`.

0 commit comments

Comments
 (0)