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

Use heuristics to suggest assignment #65566

Merged
merged 5 commits into from
Oct 27, 2019
Merged

Conversation

estebank
Copy link
Contributor

When detecting a possible = -> : typo in a let binding, suggest
assigning instead of setting the type.

Partially address #57828.

@rust-highfive
Copy link
Collaborator

r? @zackmdavis

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 18, 2019
@estebank
Copy link
Contributor Author

Follow up work would be to silence likely knock-down errors. To do, we should keep track of having suggested := (the span is enough) and not emit the "invalid parenthesized type parameters" and "ambiguous associated type" errors if their spans are contained by it.

src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
src/librustc_resolve/late.rs Outdated Show resolved Hide resolved
let val = match local {
Local { pat, ty: Some(ty), init: None, .. } => match pat.kind {
// We check for this to avoid tuple struct fields.
PatKind::Wild => None,
Copy link
Contributor

Choose a reason for hiding this comment

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

We have let _: <type> here -- what's special about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've seen no way to differentiate between let _: <type>; and struct T(usize);. Without this filter the suggestion triggers incorrectly for the latter in one of the tests.

src/librustc_resolve/late/diagnostics.rs Outdated Show resolved Hide resolved
@Centril
Copy link
Contributor

Centril commented Oct 19, 2019

Is this a commonly occurring problem? cc @hsivonen didn't really elaborate and they are not a newcomer.

@estebank
Copy link
Contributor Author

estebank commented Oct 19, 2019

We already handle this kind of error when there are parse errors, but this case is insidious because it parses correctly and then causes multiple knock down errors. The big win would be to turn the three errors into just one.

Edit: I think this is a common thing to happen when editing code, akin to trailing commas or missing semicolons. I know I've hit it a couple of times.

@hsivonen
Copy link
Member

Is this a commonly occurring problem?

I don't know how commonly this occurs, but when it did occur, it was confusing.

@estebank
Copy link
Contributor Author

@hsivonen would the current output have been enough for you to quickly identify the issue?

error[E0573]: expected type, found local variable `num`
  --> $DIR/let-binding-init-expr-as-ty.rs:2:27
   |
LL |     let foo: i32::from_be(num);
   |            --             ^^^ not a type
   |            |
   |            help: use `=` if you meant to assign

error: parenthesized type parameters may only be used with a `Fn` trait
  --> $DIR/let-binding-init-expr-as-ty.rs:2:19
   |
LL |     let foo: i32::from_be(num);
   |                   ^^^^^^^^^^^^
   |
   = note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>

error[E0223]: ambiguous associated type
  --> $DIR/let-binding-init-expr-as-ty.rs:2:14
   |
LL |     let foo: i32::from_be(num);
   |              ^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<i32 as Trait>::from_be`

Further improvements would get pretty hairy pretty quickly.

@hsivonen
Copy link
Member

would the current output have been enough for you to quickly identify the issue?

Likely yes. Thank you!

@estebank
Copy link
Contributor Author

r? @Centril

@rust-highfive rust-highfive assigned Centril and unassigned zackmdavis Oct 25, 2019
@Centril
Copy link
Contributor

Centril commented Oct 26, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Oct 26, 2019

📌 Commit 10ce36c has been approved by Centril

@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 Oct 26, 2019
@bors
Copy link
Contributor

bors commented Oct 26, 2019

⌛ Testing commit 10ce36c with merge cf96b4bad10c951e1e6e0053fe091868fafa5ac9...

@Centril
Copy link
Contributor

Centril commented Oct 26, 2019

@bors treeclosed=1000

@rust-highfive
Copy link
Collaborator

Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-26T07:18:53.1399271Z do so (now or later) by using -b with the checkout command again. Example:
2019-10-26T07:18:53.1400079Z 
2019-10-26T07:18:53.1403308Z   git checkout -b <new-branch-name>
2019-10-26T07:18:53.1404331Z 
2019-10-26T07:18:53.1404938Z HEAD is now at cf96b4bad Auto merge of #65566 - estebank:let-expr-as-ty, r=Centril
2019-10-26T07:18:53.2013734Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-10-26T07:18:53.2276470Z ==============================================================================
2019-10-26T07:18:53.2276592Z Task         : Bash
2019-10-26T07:18:53.2276677Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-10-26T07:20:32.8004531Z Chocolatey installed 0/1 packages. 1 packages failed.
2019-10-26T07:20:32.8004965Z  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
2019-10-26T07:20:32.8011060Z 
2019-10-26T07:20:32.8017389Z Failures
2019-10-26T07:20:32.8024735Z  - msys2 (exited 1) - msys2 not installed. An error occurred during installation:
2019-10-26T07:20:32.8025305Z  The remote server returned an error: (503) Server Unavailable. Service Unavailable
2019-10-26T07:20:33.3100079Z 
2019-10-26T07:20:33.3202189Z ##[error]Bash exited with code '1'.
2019-10-26T07:20:33.3437294Z ##[section]Starting: Upload CPU usage statistics
2019-10-26T07:20:33.3549928Z ==============================================================================
2019-10-26T07:20:33.3550044Z Task         : Bash
2019-10-26T07:20:33.3550116Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-10-26T07:20:33.6908889Z ========================== Starting Command Output ===========================
2019-10-26T07:20:33.6914878Z [command]"C:\Program Files\Git\bin\bash.exe" --noprofile --norc /d/a/_temp/a38c3b31-4a84-465b-89b3-e2fc1ba236e7.sh
2019-10-26T07:20:33.7363987Z /d/a/_temp/a38c3b31-4a84-465b-89b3-e2fc1ba236e7.sh: line 1: aws: command not found
2019-10-26T07:20:33.7391556Z 
2019-10-26T07:20:33.7410693Z ##[error]Bash exited with code '127'.
2019-10-26T07:20:33.7487889Z ##[section]Starting: Checkout
2019-10-26T07:20:33.7639758Z ==============================================================================
2019-10-26T07:20:33.7639868Z Task         : Get sources
2019-10-26T07:20:33.7639973Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Oct 26, 2019

💔 Test failed - checks-azure

@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 Oct 26, 2019
@JohnTitor
Copy link
Member

It seems chocolatey is now available, let's check if it works.
@bors treeclosed-

@JohnTitor
Copy link
Member

@bors retry

@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 Oct 26, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 26, 2019
Use heuristics to suggest assignment

When detecting a possible `=` -> `:` typo in a `let` binding, suggest
assigning instead of setting the type.

Partially address rust-lang#57828.
@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 26, 2019
@estebank
Copy link
Contributor Author

Fallout from the suggestions change. I'll rebase and fix.

@estebank
Copy link
Contributor Author

@bors r=Centril

@bors
Copy link
Contributor

bors commented Oct 26, 2019

📌 Commit b579c5a has been approved by Centril

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 26, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 27, 2019
Use heuristics to suggest assignment

When detecting a possible `=` -> `:` typo in a `let` binding, suggest
assigning instead of setting the type.

Partially address rust-lang#57828.
bors added a commit that referenced this pull request Oct 27, 2019
Rollup of 6 pull requests

Successful merges:

 - #65566 (Use heuristics to suggest assignment)
 - #65738 (Coherence should allow fundamental types to impl traits when they are local)
 - #65777 (Don't ICE for completely unexpandable `impl Trait` types)
 - #65834 (Remove lint callback from driver)
 - #65839 (Clean up `check_consts` now that new promotion pass is implemented)
 - #65855 (Add long error explaination for E0666)

Failed merges:

r? @ghost
@bors bors merged commit b579c5a into rust-lang:master Oct 27, 2019
@estebank estebank deleted the let-expr-as-ty branch November 9, 2023 05:18
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.

7 participants