Skip to content

lint errors make rustc abort early #82761

Closed
@SNCPlay42

Description

@SNCPlay42

In general, the compiler tries to keep going after errors to emit as many helpful diagnostics as possible. This isn't always possible because later stages of compilation might need certain conditions to be upheld, so sometimes the compiler aborts early.

It should never be necessary to abort early due to a lint from an external tool (e.g. clippy) because the compiler's hard errors should be sufficient to enforce conditions needed by later stages.

At present, however, error-level lints emitted by external tools can cause compilation to abort early. It seems unfortunate that, after fixing all the problems reported by one run of clippy, you could run clippy again (perhaps by committing your "fixed" code and updating a PR, causing CI to run) and discover there are more problems (when CI fails).

As an example, this code:

fn main() {
    if true {} {}
    
    let x;
    if true {
        x = 1;
    } else {
        x = 1;
    }
    println!("{}", x);
}

Emits two lints with clippy:

warning: this looks like an `else {..}` but the `else` is missing
 --> src/main.rs:4:15
  |
4 |     if true {} {}
  |               ^
  |
  = note: `#[warn(clippy::suspicious_else_formatting)]` on by default
  = note: to remove this lint, add the missing `else` or add a new line before the next block
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting

error: this `if` has identical blocks
  --> src/main.rs:9:12
   |
9  |       } else {
   |  ____________^
10 | |         x = 1;
11 | |     }
   | |_____^
   |
   = note: `#[deny(clippy::if_same_then_else)]` on by default
note: same as this
  --> src/main.rs:7:13
   |
7  |       if true {
   |  _____________^
8  | |         x = 1;
9  | |     } else {
   | |_____^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else

error: aborting due to previous error; 1 warning emitted

error: could not compile `playground`

If #![deny(clippy::all)] is added, only the first lint is emitted, and the compiler aborts after it:

error: this looks like an `else {..}` but the `else` is missing
 --> src/main.rs:4:15
  |
4 |     if true {} {}
  |               ^
  |
note: the lint level is defined here
 --> src/main.rs:1:8
  |
1 | #[deny(clippy::all)]
  |        ^^^^^^^^^^^
  = note: `#[deny(clippy::suspicious_else_formatting)]` implied by `#[deny(clippy::all)]`
  = note: to remove this lint, add the missing `else` or add a new line before the next block
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting

error: aborting due to previous error

error: could not compile `playground`

@rustbot label A-lint

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-clippyArea: ClippyA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions