You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
For const variable declaration, if type is left dangling, also suggest type #100146
Compiling playground v0.0.1 (/playground)
error: expected type, found `=`
--> src/main.rs:2:14
|
2 | const b: = 123;
| ^ expected type
error: could not compile `playground` due to previous error
Since the compiler suggests the type needed for the following:
fnmain(){const b = 123;}
Compiling playground v0.0.1 (/playground)
error: missing type for `const` item
--> src/main.rs:2:11
|
2 | const b = 123;
| ^ help: provide a type for the constant: `b: i32`
error: could not compile `playground` due to previous error
The output ideally should also suggest the type if its left dangling.
Basically just that the colon is included but no type is specified.
Just like in the first example (where the type is left empty, with a colon), it should also suggest the type to include to make the program compile. (Like the second example which suggests the type to include)
This is because if we have colon, the parser will try to parse a type, then error will trigger.
If we don't have colon, parser will try to insert a place hold:
@WaffleLapkin
I have a branch in local could fix this issue.
But it also break another testcase with wrong syntax, but I think it's OK since this testcase is far from normal syntax.
Do you mind I send a PR for this?
Activity
compiler-errors commentedon Aug 4, 2022
cc @WaffleLapkin who knows how to do this since he worked on that
typeofPR i thinkWaffleLapkin commentedon Aug 4, 2022
@rustbot claim
WaffleLapkin commentedon Aug 5, 2022
@Rageking8 what you've meant by a type that's left dangling?
Rageking8 commentedon Aug 5, 2022
Basically just that the colon is included but no type is specified.
Just like in the first example (where the type is left empty, with a colon), it should also suggest the type to include to make the program compile. (Like the second example which suggests the type to include)
chenyukang commentedon Aug 5, 2022
This is because if we have colon, the parser will try to parse a type, then error will trigger.
If we don't have colon, parser will try to insert a place hold:
Then type checker will enrich the type messages.
https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/parser/item.rs#L1183
I'm thinking on the solution.
chenyukang commentedon Aug 5, 2022
@WaffleLapkin
I have a branch in local could fix this issue.
But it also break another testcase with wrong syntax, but I think it's OK since this testcase is far from normal syntax.
Do you mind I send a PR for this?
WaffleLapkin commentedon Aug 5, 2022
@chenyukang oh, I've had a fix too, oops 😅
I've opened a PR already: #100168, but feel free to open a PR as well, if you think your approach might be better.
chenyukang commentedon Aug 5, 2022
My fix is shorter, but seems a little bit hacky 😁
FYI: chenyukang@3440429
Rollup merge of rust-lang#100168 - WaffleLapkin:improve_diagnostics_f…