-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
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 ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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
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.)
Metadata
Metadata
Assignees
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 ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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.