Closed
Description
Hello, with rustc 1.17.0-nightly (8c4f2c6 2017-03-22), the following code
fn main () {
for i 0..2 {
println!("{}", i);
}
}
gives this error message:
error: expected one of `@` or `in`, found `0`
--> src/disasm/mod.rs:27:15
|
27 | for i 0..2 {
|
An improved error message could add a hint : did you mean 'for i in 0..2'
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
estebank commentedon Sep 21, 2017
Current output:
How would you want to improve upon this? Adding a suggestion?
To do so, we could use the same strategy as in #42578: in
parse_for_expr
if theIn
keyword is not found, try to continue building the expression as if theIn
keyword had been found. If we find further errors, we revert the state of the compiler to right after trying to continue and return the error fromexpect_keyword
. Otherwise we cancel that one and create a new custom diagnostic:or just modify the existing error with the proposed
span_suggestion
(so it looks like the 2 above).martinlindhe commentedon Sep 22, 2017
Looks like current output already is an improvement over the reported one, but eithwr 2 or 3 would make it even more obvious i guess. No strong opinions here
nikomatsakis commentedon Sep 25, 2017
Seems to me that the third error is the most clear ("error: missing
in
infor
loop"); I suspect people using fancy pattern features will figure out what's going on.Add a nicer error message for missing in for loop, fixes rust-lang#40782
Rollup merge of rust-lang#45639 - LaurentMazare:master, r=petrochenkov
Rollup merge of rust-lang#136536 - DuskyElf:master, r=jieyouxu
Rollup merge of rust-lang#136536 - DuskyElf:master, r=jieyouxu
Rollup merge of rust-lang#136536 - DuskyElf:master, r=jieyouxu
Unrolled build for rust-lang#136536