Skip to content

Commit ce9ef37

Browse files
committed
Readd suggestion in enum variants with incorrect args
1 parent a317da4 commit ce9ef37

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/librustc_resolve/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,18 @@ impl<'a> Resolver<'a> {
27302730
}
27312731
return (err, candidates);
27322732
}
2733+
(Def::VariantCtor(_, ctor_kind), _) if ns == ValueNS && is_struct_like(def) => {
2734+
let block = match ctor_kind {
2735+
CtorKind::Fn => "(/* fields */)",
2736+
CtorKind::Fictive => " { /* fields */ }",
2737+
def => bug!("found def `{:?}` when looking for a ctor",
2738+
def),
2739+
};
2740+
err.span_label(span, format!("did you mean `{}{}`?",
2741+
path_str,
2742+
block));
2743+
return (err, candidates);
2744+
}
27332745
_ => {}
27342746
}
27352747
}

src/test/ui/resolve/issue-18252.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0423]: expected function, found struct variant `Foo::Variant`
22
--> $DIR/issue-18252.rs:16:13
33
|
44
16 | let f = Foo::Variant(42);
5-
| ^^^^^^^^^^^^ not a function
5+
| ^^^^^^^^^^^^ did you mean `Foo::Variant { /* fields */ }`?
66

77
error: aborting due to previous error
88

src/test/ui/resolve/issue-19452.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error[E0423]: expected value, found struct variant `Homura::Madoka`
22
--> $DIR/issue-19452.rs:19:18
33
|
44
19 | let homura = Homura::Madoka;
5-
| ^^^^^^^^^^^^^^ not a value
5+
| ^^^^^^^^^^^^^^ did you mean `Homura::Madoka { /* fields */ }`?
66

77
error[E0423]: expected value, found struct variant `issue_19452_aux::Homura::Madoka`
88
--> $DIR/issue-19452.rs:22:18
99
|
1010
22 | let homura = issue_19452_aux::Homura::Madoka;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a value
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ did you mean `issue_19452_aux::Homura::Madoka { /* fields */ }`?
1212

1313
error: aborting due to 2 previous errors
1414

0 commit comments

Comments
 (0)