Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak conditions for E0026 and E0769 #75352

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/librustc_typeck/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,8 +1229,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Applicability::MaybeIncorrect,
);

// we don't want to throw `E0027` in case we have thrown `E0026` for them
unmentioned_fields.retain(|&x| x.name != suggested_name);
// When we have a tuple struct used with struct we don't want to suggest using
// the (valid) struct syntax with numeric field names. Instead we want to
// suggest the expected syntax. We infer that this is the case by parsing the
// `Ident` into an unsized integer. The suggestion will be emitted elsewhere in
// `smart_resolve_context_dependent_help`.
if suggested_name.to_ident_string().parse::<usize>().is_err() {
// We don't want to throw `E0027` in case we have thrown `E0026` for them.
unmentioned_fields.retain(|&x| x.name != suggested_name);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-17800.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum MyOption<T> {
fn main() {
match MyOption::MySome(42) {
MyOption::MySome { x: 42 } => (),
//~^ ERROR variant `MyOption::MySome` does not have a field named `x`
//~^ ERROR tuple variant `MyOption::MySome` written as struct variant
_ => (),
}
}
11 changes: 4 additions & 7 deletions src/test/ui/issues/issue-17800.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
error[E0026]: variant `MyOption::MySome` does not have a field named `x`
--> $DIR/issue-17800.rs:8:28
error[E0769]: tuple variant `MyOption::MySome` written as struct variant
--> $DIR/issue-17800.rs:8:9
|
LL | MyOption::MySome { x: 42 } => (),
| ^
| |
| variant `MyOption::MySome` does not have this field
| help: a field with a similar name exists: `0`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `MyOption::MySome(42)`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0026`.
For more information about this error, try `rustc --explain E0769`.