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

Recover from Foo(a: 1, b: 2) #88729

Merged
merged 2 commits into from
Sep 16, 2021

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Sep 7, 2021

Detect likely struct literal using parentheses as delimiters and emit
targeted suggestion instead of type ascription parse error.

Fix #61326.

Detect likely `struct` literal using parentheses as delimiters and emit
targeted suggestion instead of type ascription parse error.

Fix rust-lang#61326.
@rust-highfive
Copy link
Collaborator

r? @oli-obk

(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 Sep 7, 2021
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
help: if `bar` is a struct, use braces as delimiters
|
LL | bar { }
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems messed up. Shouldn't it be bar { baz: $rest } ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is indeed "not correct", caused by the macro context of the spans involved. I could never show the suggestions if a macro is involved, but that would hide the suggestion even if the macro isn't mixing fragments coming from the caller with internal spans. Then again a middle point would be to give just a help without a suggestion for things in macros now that I think about it 🤔

self.mk_expr(lo.to(self.prev_token.span), self.mk_call(fun, args), AttrVec::new())
});
match (seq.as_mut(), snapshot) {
Copy link
Contributor

@oli-obk oli-obk Sep 14, 2021

Choose a reason for hiding this comment

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

Please pull this out of the happy path into a separate function

r=me with that done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very rude of you to make me fix this while Mara is speaking :)

@estebank
Copy link
Contributor Author

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Sep 14, 2021

📌 Commit ffc623a has been approved by oli-obk

@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 Sep 14, 2021
Manishearth added a commit to Manishearth/rust that referenced this pull request Sep 16, 2021
…s, r=oli-obk

Recover from `Foo(a: 1, b: 2)`

Detect likely `struct` literal using parentheses as delimiters and emit
targeted suggestion instead of type ascription parse error.

Fix rust-lang#61326.
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 16, 2021
…arth

Rollup of 10 pull requests

Successful merges:

 - rust-lang#88292 (Enable --generate-link-to-definition for rustc's docs)
 - rust-lang#88729 (Recover from `Foo(a: 1, b: 2)`)
 - rust-lang#88875 (cleanup(rustc_trait_selection): remove vestigial code from rustc_on_unimplemented)
 - rust-lang#88892 (Move object safety suggestions to the end of the error)
 - rust-lang#88928 (Document the closure arguments for `reduce`.)
 - rust-lang#88976 (Clean up and add doc comments for CStr)
 - rust-lang#88983 (Allow calling `get_body_with_borrowck_facts` without `-Z polonius`)
 - rust-lang#88985 (Update clobber_abi list to include k[1-7] regs)
 - rust-lang#88986 (Update the backtrace crate)
 - rust-lang#89009 (Fix typo in `break` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2c7d48b into rust-lang:master Sep 16, 2021
@rustbot rustbot added this to the 1.57.0 milestone Sep 16, 2021
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.

Handle Foo { a: usize, b: usize } used as Foo(1, 2) gracefully
6 participants