Closed
Description
Right now, if rustc
is parsing a function body and sees a ,
when it expected a ;
, it will give up on parsing the rest of the current function body.
Meanwhile, later phases of the compiler still run. Which means, for example, if the remainder of that erroneous function body contains the sole references to certain imports, then you get false warnings about those imports being unused.
Here is a concrete example (playground):
use std::iter::Iterator;
fn main() {
struct S;
let _x = 3,
impl Iterator for S {
type Item = S;
fn next(&mut self) -> Option<S> { Some(S) }
}
}
which yields the following diagnostic output on nightly and beta:
error: expected one of `.`, `;`, `?`, or an operator, found `,`
--> src/main.rs:5:15
|
5 | let _x = 3,
| ^ expected one of `.`, `;`, `?`, or an operator here
warning: unused import: `std::iter::Iterator`
--> src/main.rs:1:5
|
1 | use std::iter::Iterator;
| ^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
error: aborting due to previous error
This seems to affect the current nightly and beta, but not stable (I.e., the stable channel just presents the parse error, not the erroneous lint about the supposedly unused import.)