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

Suggest that expressions that look like const generic arguments should be enclosed in brackets #77502

Merged

Conversation

varkor
Copy link
Member

@varkor varkor commented Oct 3, 2020

I pulled out the changes for const expressions from #71592 (without the trait object diagnostic changes) and made some small changes; the implementation is @estebank's.

We're also going to want to make some changes separately to account for trait objects (they result in poor diagnostics, as is evident from one of the test cases here), such as an adaption of #72273.

Fixes #70753.

r? @petrochenkov

@varkor varkor added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` labels Oct 3, 2020
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 3, 2020
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.

Thanks for picking this up @varkor!

@varkor varkor force-pushed the const-generics-suggest-enclosing-braces branch from debf4a7 to 5f8aa8a Compare October 3, 2020 19:04
@petrochenkov
Copy link
Contributor

I'll get to this next weekend most likely.

compiler/rustc_parse/src/parser/path.rs Show resolved Hide resolved
compiler/rustc_parse/src/parser/path.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/path.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov 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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 11, 2020
@varkor varkor force-pushed the const-generics-suggest-enclosing-braces branch from c23db00 to b03e75e Compare October 21, 2020 20:29
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 21, 2020
@varkor
Copy link
Member Author

varkor commented Oct 21, 2020

@petrochenkov: I've moved the functions to diagnostics.rs.

compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
@camelid camelid added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Oct 22, 2020
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/diagnostics.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/parser/expr.rs Show resolved Hide resolved
@petrochenkov petrochenkov 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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 24, 2020
@varkor
Copy link
Member Author

varkor commented Oct 25, 2020

@petrochenkov: I've added some more tests. The error messages in these cases are not ideal, but they're particularly difficult to handle well.

@varkor varkor added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2020
@varkor varkor force-pushed the const-generics-suggest-enclosing-braces branch from e4f2b91 to 9aa3cfb Compare October 25, 2020 13:29
@estebank
Copy link
Contributor

The error messages in these cases are not ideal, but they're particularly difficult to handle well.

Handling >> will be hard but we could potentially keep track of how many < we've seen to decide whether to detect it as bitshift or closing type param (we already have recovery for too many closing > in type params so it would have to interact nicely with it), but I don't think it is necessary just yet as the suggestion does give you enough of a clue as to what to do.

@petrochenkov
Copy link
Contributor

r=me with commits squashed.

@petrochenkov petrochenkov 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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 26, 2020
…enclosed in brackets

Co-Authored-By: Esteban Kuber <github@kuber.com.ar>
@varkor varkor force-pushed the const-generics-suggest-enclosing-braces branch from 9aa3cfb to ac14540 Compare October 26, 2020 21:55
@varkor
Copy link
Member Author

varkor commented Oct 26, 2020

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Oct 26, 2020

📌 Commit ac14540 has been approved by petrochenkov

@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, 2020
@bors
Copy link
Contributor

bors commented Oct 27, 2020

⌛ Testing commit ac14540 with merge 20b1e05...

@bors
Copy link
Contributor

bors commented Oct 27, 2020

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 20b1e05 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` F-const_generics `#![feature(const_generics)]` merged-by-bors This PR was explicitly merged by bors. 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.

const_generics: parsing fails with const expression in type parameter
8 participants