fn main() {
for _ in std::ops::Range { start: 0, end: 10 } {}
}
// error: expected type, found `0`
// --> src/main.rs:2:39
// |
// 2 | for _ in std::ops::Range { start: 0, end: 10 } {}
// | ^ expecting a type here because of type ascription
// error[E0423]: expected value, found struct `std::ops::Range`
// --> src/main.rs:2:14
// |
// 2 | for _ in std::ops::Range { start: 0, end: 10 } {}
// | ^^^^^^^^^^^^^^^ did you mean `std::ops::Range { /* fields */ }`?
It's confusing here, as it suggests using exactly what the user has typed. It should instead suggest the user parenthesise the struct literal.
(There's probably a reason this doesn't parse as-is, but if not, it seems like a nice case to handle.)
馃憤 on improving the diagnostics here.
There's probably a reason this doesn't parse as-is
The problem is that when the parser sees the {
after Range
it doesn't know whether it's a struct literal or the start of the loop body, and at parse time it has no idea that Range
is a struct, not a constant.
Most helpful comment
馃憤 on improving the diagnostics here.
The problem is that when the parser sees the
{
afterRange
it doesn't know whether it's a struct literal or the start of the loop body, and at parse time it has no idea thatRange
is a struct, not a constant.