Skip to content

Suggest replacing an inexisting field for an unmentioned field - #87960

Merged
bors merged 1 commit into
rust-lang:masterfrom
hkmatsumoto:suggest-inexisting-field-for-unmentioned-field
Sep 19, 2021
Merged

Suggest replacing an inexisting field for an unmentioned field#87960
bors merged 1 commit into
rust-lang:masterfrom
hkmatsumoto:suggest-inexisting-field-for-unmentioned-field

Conversation

@hkmatsumoto

@hkmatsumotohkmatsumoto commented Aug 12, 2021

Copy link
Copy Markdown
Contributor

Fix#87938

This PR adds a suggestion to replace an inexisting field for an
unmentioned field. Given the following code:

enumFoo{Bar{alpha:u8,bravo:u8,charlie:u8},}fnfoo(foo:Foo){match foo {Foo::Bar{
alpha,
beta,// `bravo` miswritten as `beta` here.
charlie,} => todo!(),}}

the compiler now emits the error messages below.

error[E0026]: variant `Foo::Bar` does not have a field named `beta`
--> src/lib.rs:9:13
|
9 | beta, // `bravo` miswritten as `beta` here.
| ^^^^
| |
| variant `Foo::Bar` does not have this field
| help: `Foo::Bar` has a field named `bravo`: `bravo`

Note that this suggestion is available iff the number of inexisting
fields and unmentioned fields are both 1.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @LeSeulArtichaut

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2021
@hkmatsumoto
hkmatsumotoforce-pushed the suggest-inexisting-field-for-unmentioned-field branch from 7def33c to 9d9f742CompareAugust 12, 2021 10:58

@LeSeulArtichautLeSeulArtichaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, and sorry for the delay on my part. I have a few minor comments.

Comment threadcompiler/rustc_typeck/src/check/pat.rs Outdated
Comment threadcompiler/rustc_typeck/src/check/pat.rs Outdated
Comment threadsrc/test/ui/issues/issue-52717.stderr Outdated
@LeSeulArtichaut

Copy link
Copy Markdown
Contributor

r? @estebank who will have a much better idea of what the best diagnostics are

Comment threadsrc/test/ui/issues/issue-51102.stderr Outdated
Comment threadsrc/test/ui/issues/issue-52717.stderr Outdated
@inquisitivecrystalinquisitivecrystal added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 24, 2021
@JohnCSimonJohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 13, 2021
@hkmatsumoto
hkmatsumotoforce-pushed the suggest-inexisting-field-for-unmentioned-field branch from 9d9f742 to 4caab25CompareSeptember 13, 2021 09:12
Comment threadcompiler/rustc_typeck/src/check/pat.rs Outdated
@estebank

Copy link
Copy Markdown
Contributor

Please squash your commits. Then we can merge this :)

This PR adds a suggestion to replace an inexisting field for an
unmentioned field. Given the following code:
```rust
enum Foo {
Bar { alpha: u8, bravo: u8, charlie: u8 },
}
fn foo(foo: Foo) {
match foo {
Foo::Bar {
alpha,
beta, // `bravo` miswritten as `beta` here.
charlie,
} => todo!(),
}
}
```
the compiler now emits the error messages below.
```text
error[E0026]: variant `Foo::Bar` does not have a field named `beta`
--> src/lib.rs:9:13
|
9 | beta, // `bravo` miswritten as `beta` here.
| ^^^^
| |
| variant `Foo::Bar` does not have this field
| help: `Foo::Bar` has a field named `bravo`: `bravo`
```
Note that this suggestion is available iff the number of inexisting
fields and unmentioned fields are both 1.
@hkmatsumoto
hkmatsumotoforce-pushed the suggest-inexisting-field-for-unmentioned-field branch from 74277a4 to 37196e3CompareSeptember 13, 2021 12:16
@estebank

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@bors

bors commented Sep 18, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 37196e3 has been approved by estebank

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 18, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Sep 19, 2021
…d-for-unmentioned-field, r=estebank
Suggest replacing an inexisting field for an unmentioned field
Fixrust-lang#87938
This PR adds a suggestion to replace an inexisting field for an
unmentioned field. Given the following code:
```rust
enum Foo {
Bar { alpha: u8, bravo: u8, charlie: u8 },
}
fn foo(foo: Foo) {
match foo {
Foo::Bar {
alpha,
beta, // `bravo` miswritten as `beta` here.
charlie,
} => todo!(),
}
}
```
the compiler now emits the error messages below.
```text
error[E0026]: variant `Foo::Bar` does not have a field named `beta`
--> src/lib.rs:9:13
|
9 | beta, // `bravo` miswritten as `beta` here.
| ^^^^
| |
| variant `Foo::Bar` does not have this field
| help: `Foo::Bar` has a field named `bravo`: `bravo`
```
Note that this suggestion is available iff the number of inexisting
fields and unmentioned fields are both 1.
@JohnTitorJohnTitor mentioned this pull request Sep 19, 2021
@JohnTitorJohnTitor mentioned this pull request Sep 19, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 19, 2021
Rollup of 10 pull requests
Successful merges:
- rust-lang#87960 (Suggest replacing an inexisting field for an unmentioned field)
- rust-lang#88855 (Allow simd_shuffle to accept vectors of any length)
- rust-lang#88966 (Check for shadowing issues involving block labels)
- rust-lang#88996 (Fix linting when trailing macro expands to a trailing semi)
- rust-lang#89017 (fix potential race in AtomicU64 time monotonizer)
- rust-lang#89021 (Add a separate error for `dyn Trait` in `const fn`)
- rust-lang#89051 (Add intra-doc links and small changes to `std::os` to be more consistent)
- rust-lang#89053 (refactor: VecDeques IntoIter fields to private)
- rust-lang#89055 (Suggest better place to add call parentheses for method expressions wrapped in parentheses)
- rust-lang#89081 (Fix a typo)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit ebd31f5 into rust-lang:masterSep 19, 2021
@rustbotrustbot added this to the 1.57.0 milestone Sep 19, 2021
@hkmatsumoto
hkmatsumoto deleted the suggest-inexisting-field-for-unmentioned-field branch September 19, 2021 13:46
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest a missing field when the rest of the field is found

8 participants

@hkmatsumoto@rust-highfive@LeSeulArtichaut@estebank@bors@JohnCSimon@inquisitivecrystal@rustbot