-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given an invalid call such as:
fn main() {
foo::("foo");
}
The following diagnostic is issued:
error: expected type, found `"foo"`
--> src/main.rs:2:9
|
2 | foo::("foo");
| ^^^^^ expected type
This gets much worse on multiline calls:
fn main() {
foo::(
bar(x, y, z),
bar(x, y, z),
bar(x, y, z),
bar(x, y, z),
bar(x, y, z),
bar(x, y, z),
bar(x, y, z),
baz("test"),
),
}
Which just prints out a diagnostic nowhere near the error:
error: expected type, found `"test"`
--> src/main.rs:10:13
|
10 | baz("test"),
| ^^^^^^ expected type
Ideally this should mention something about either missing a missing turbofish (e.g. foo::<..>("foo")
), or a missing identifier (e.g. foo::bar("foo")
). This would at least get the error pointing to the correct spot.
Latest playground nightly (2024-02-09)
fmeasefmease
Metadata
Metadata
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
fmease commentedon Feb 10, 2024
Oh, wow, it didn't even occur to me until now that the expression
Option::(i32)::None::()
is syntactically valid >.<Edit: Wow, even
let _ = Fn::() -> Option<i32>;
is syntactically well-formed.fmease commentedon Feb 10, 2024
This should pretty easy to fix, basically if we fail to parse a type here
rust/compiler/rustc_parse/src/parser/path.rs
Line 375 in 7954c28
we should first of all attach a label to the
::(
saying something akin to while parsing this list of parenthesized type arguments starting here and we should suggest removing the trailing path separator if thePathStyle
isExpr
, the parenthesized generics aren't followed by::
or->
and if the list of non-types we encountered can be successfully parsed as a list of expressions (using a snapshot parser).Furthermore, if the
PathStyle
isPat
we can try to reparse the list as a list of patterns and provide the same structured suggestion.I will gladly mentor & review any PR for this.
SummerGram commentedon Feb 12, 2024
@rustbot claim
11 remaining items