-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Diagnostic when Fn*-family trait bounds is missing parens could be improved #108109
Comments
Where this function is invoked. Try looking for the code that parses "parenthesized" generics. |
@Fishrock123 If you end up writing a fix, note that those trait bounds are usually called |
It seems this diagnostic contextually comes from As corroboration it also seems that declaring a regular
rust/compiler/rustc_parse/src/parser/item.rs Lines 2375 to 2396 in 9a7cc6c
I naively think that the adjustment point should probably be However I don't understand how the output gets multiple possibilities e.g.
or the whole list of
Since it's only calling I guess this requires catching the result in pub type PErr<'a> = DiagnosticBuilder<'a, ErrorGuaranteed>; |
Any time you call |
Anyways, it shouldn't matter -- in the caller to |
Just chiming in to mention: in any parser change you make here make sure you don't start accepting new code and add tests for all combinations you can think of. |
…rochenkov Recover from missing param list in function definitions Addresses the other issue mentioned in rust-lang#108109
…rochenkov Recover from missing param list in function definitions Addresses the other issue mentioned in rust-lang#108109
Rollup merge of rust-lang#117298 - clubby789:fn-missing-params, r=petrochenkov Recover from missing param list in function definitions Addresses the other issue mentioned in rust-lang#108109
Code
Current output
Desired output
Rationale and extra context
It feels like rustc should be able to determine that a trait followed by a
->
is aFn*
-family trait bound and be able to suggest this behavior. If that is too general it could just check forFn
,FnOnce
,FnMut
.Other cases
Not that i know of...Very similar is if parenthesis are missing from regular
fn
declarations:Anything else?
Also happens on nightly according to Rust Playground.
I'd like to try my hand at implementing this diagnostic, but I'll likely need a little bit of locational guidance. A naive code search show that the message is emitted by this code is the parser diagnostics, but I'm not sure if the adjustment would need to be made within that or from where it is invoked in this case.
rust/compiler/rustc_parse/src/parser/diagnostics.rs
Lines 384 to 388 in c528357
Edit: Updated to use the wording "
Fn*
-family trait bounds" rather than "HRTBs".The text was updated successfully, but these errors were encountered: