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

correct unused field pattern suggestions #47922

Merged

Conversation

zackmdavis
Copy link
Member

The glossaries in the draft rustc-guide book and librustc/README.md
state that `NodeId` is being gradually phased out in favor of `HirId`;
as such, the present author claims that we ought to have a typedef for
efficient `HirId` maps and sets in the module for such, even if no use
for them has been made as yet (compatibility constraints preventing the
use of it in the author's present unit of work): it is important to
create the psychological "affordance" (in James J. Gibson's sense) that
`HirId`s are a thing that compiler developers can work with.
Previously, unused variables would get a note that the warning could be
silenced by prefixing the variable with an underscore, but that doesn't
work for field shorthand patterns, which the liveness analysis didn't
know about.

The "to avoid this warning" verbiage seemed unnecessary.

Resolves rust-lang#47390.
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

r=me once travis succeeds.

If you have the time to improve the other warning it'd be great, but that can be done on a follow up PR.

30 | mut hours_are_suns,
| ^^^^^^^^^^^^^^^^^^
|
= note: consider using `_hours_are_suns` instead
Copy link
Contributor

Choose a reason for hiding this comment

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

This warning is emitted somewhere else. Would you mind checking how hard it'd be to modify that note by checking if it is a field in a struct literal?

Copy link
Member Author

Choose a reason for hiding this comment

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

@estebank The PR touches this code (on master, the note starts with "to avoid this warning", which I thought was unnecessary). I had started working on making this a structured suggestion, too, but then backed off when I realized that getting the suggestion right would involve more refactoring than I wanted to do now. Notice that the span includes the mut: in the case of an entirely unused variable, that's fine (the mut is also unused, so replacing both the variable and any muts or refs with variable: _ is correct), but in the case of a mere unused assignment (where we mutate the variable, but don't do anything interesting with it), not only is the mut significant, but there are also other appearances of the variable (requiring a multi-span suggestion).

@kennytm
Copy link
Member

kennytm commented Feb 1, 2018

@bors r=estebank

@bors
Copy link
Contributor

bors commented Feb 1, 2018

📌 Commit e4b1a79 has been approved by estebank

@kennytm kennytm added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Feb 1, 2018
@bors
Copy link
Contributor

bors commented Feb 5, 2018

⌛ Testing commit e4b1a79 with merge c0efdab7d210301ff339b52db9ce52b90f1553be...

@bors
Copy link
Contributor

bors commented Feb 5, 2018

💔 Test failed - status-appveyor

@kennytm
Copy link
Member

kennytm commented Feb 5, 2018

@bors retry

3 hour timeout

@bors
Copy link
Contributor

bors commented Feb 6, 2018

⌛ Testing commit e4b1a79 with merge 290af29...

bors added a commit that referenced this pull request Feb 6, 2018
@bors
Copy link
Contributor

bors commented Feb 6, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 6, 2018
@zackmdavis
Copy link
Member Author

#46903 is killing our throughput 💔 ☠️ (although this time it was the 64-bit build that timed out)

@kennytm
Copy link
Member

kennytm commented Feb 7, 2018

@bors retry

3 hour timeout

@bors bors 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 Feb 7, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 7, 2018
bors added a commit that referenced this pull request Feb 7, 2018
Rollup of 10 pull requests

- Successful merges: #47613, #47631, #47810, #47883, #47922, #47944, #48014, #48018, #48020, #48028
- Failed merges:
@bors bors merged commit e4b1a79 into rust-lang:master Feb 7, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Apr 30, 2018
…=estebank

Display correct unused field suggestion for nested struct patterns

Extends rust-lang#47922 by checking more sophisticated patterns (e.g. references, slices, etc.).
Before:
```
warning: unused variable: `bar`
  --> src/main.rs:37:21
   |
37 |         &Foo::Bar { bar } => true,
   |                     ^^^ help: consider using `_bar` instead
   |
   = note: #[warn(unused_variables)] on by default
```
After:
```
warning: unused variable: `bar`
  --> src/main.rs:37:21
   |
37 |         &Foo::Bar { bar } => true,
   |                     ^^^ help: try ignoring the field: `bar: _`
   |
   = note: #[warn(unused_variables)] on by default
```

Fixes rust-lang#50303.

r? @estebank
zackmdavis added a commit to zackmdavis/rust that referenced this pull request May 18, 2018
In e4b1a79 (rust-lang#47922), we corrected erroneous suggestions for unused
shorthand field pattern bindings, suggesting `field: _` where the
previous suggestion of `_field` wouldn't even have compiled
(rust-lang#47390). Soon, it was revealed that this was insufficient (rust-lang#50303), and
the fix was extended to references, slices, &c. (rust-lang#50327) But even this
proved inadequate, as the erroneous suggestions were still being issued
for patterns in local (`let`) bindings (rust-lang#50804). Here, we yank the
shorthand-detection and variable/node registration code into a new
common function that can be called while visiting both match arms and
`let` bindings.

Resolves rust-lang#50804.
kennytm added a commit to kennytm/rust that referenced this pull request May 19, 2018
…ed_field_pattern_3_straight_to_video, r=estebank

in which the unused shorthand field pattern debacle/saga continues

In e4b1a79 (rust-lang#47922), we corrected erroneous suggestions for unused
shorthand field pattern bindings, suggesting `field: _` where the
previous suggestion of `_field` wouldn't even have compiled
(rust-lang#47390). Soon, it was revealed that this was insufficient (rust-lang#50303), and
the fix was extended to references, slices, &c. (rust-lang#50327) But even this
proved inadequate, as the erroneous suggestions were still being issued
for patterns in local (`let`) bindings (rust-lang#50804). Here, we yank the
shorthand-detection and variable/node registration code into a new
common function that can be called while visiting both match arms and
`let` bindings.

Resolves rust-lang#50804.

r? @estebank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants