rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.38k stars 1.53k forks source link

`clippy-driver` compiler error output differs from `rustc` #13351

Open atro7318 opened 1 month ago

atro7318 commented 1 month ago

Description

When there is a compiler error, the errors differ in that the clippy-driver uses the fully qualified module path to refer to trait, struct, function, etc. definitions, and rustc does not.

This becomes a problem when writing trybuild compiler tests against macros, in which case the tests only pass if the output is exactly the same. It would be expected that these tests should be able to be run through clippy-driver and rustc and yield the same results.

I created a simple example in Rust playground that fails to compile.

When it is run via rustc, this is the error output:

error[E0277]: the trait bound `MyStruct: MyTrait` is not satisfied
 --> src/main.rs:8:19
  |
8 |     my_mod::my_fn(my_mod::MyStruct);
  |     ------------- ^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `MyStruct`
  |     |
  |     required by a bound introduced by this call
  |
help: this trait has no implementations, consider adding one
 --> src/main.rs:2:5
  |
2 |     pub trait MyTrait {}
  |     ^^^^^^^^^^^^^^^^^
note: required by a bound in `my_fn`
 --> src/main.rs:4:21
  |
4 |     pub fn my_fn<T: MyTrait>(_t: T) {}
  |                     ^^^^^^^ required by this bound in `my_fn`

When the clippy tool runs it (via clippy-driver) this is the error output:

error[E0277]: the trait bound `my_mod::MyStruct: my_mod::MyTrait` is not satisfied
 --> src/main.rs:8:19
  |
8 |     my_mod::my_fn(my_mod::MyStruct);
  |     ------------- ^^^^^^^^^^^^^^^^ the trait `my_mod::MyTrait` is not implemented for `my_mod::MyStruct`
  |     |
  |     required by a bound introduced by this call
  |
help: this trait has no implementations, consider adding one
 --> src/main.rs:2:5
  |
2 |     pub trait MyTrait {}
  |     ^^^^^^^^^^^^^^^^^
note: required by a bound in `my_mod::my_fn`
 --> src/main.rs:4:21
  |
4 |     pub fn my_fn<T: MyTrait>(_t: T) {}
  |                     ^^^^^^^ required by this bound in `my_fn`

Version

rustc: 1.80.1
clippy: 0.1.80

Additional Labels

No response

alex-semenyuk commented 1 month ago

@rustbot label c-bug