Crate version mismatch suggestion not being shown for trait not implemented error · Issue #89143 · rust-lang/rust (original) (raw)
In #66561 the diagnostic for trait not implemented errors was improved to add a hint suggesting there may be multiple crate versions, if there was a trait found with the same name. However that hint is not being shown for the testcase below, when I would have expected it to be.
Note: This is a variation/subset of #22750 - however I'm filing this separately since (a) this part was meant to be fixed by #66561, (b) #22750 covers a mixture of several issues (such as surfacing crate version info from cargo) and so less actionable.
Steps to reproduce:
- Clone https://github.com/edmorley/testcase-rustc-crate-version-mismatch
cd a && cargo check
The current output is (using rustc 1.59.0-beta.8
):
Checking c v0.1.0 (/Users/emorley/src/testcase-rustc-crate-version-mismatch/c-v0.1)
Checking c v0.2.0 (/Users/emorley/src/testcase-rustc-crate-version-mismatch/c-v0.2)
Checking b v0.1.0 (/Users/emorley/src/testcase-rustc-crate-version-mismatch/b)
Checking a v0.1.0 (/Users/emorley/src/testcase-rustc-crate-version-mismatch/a)
error[E0277]: the trait bound `CustomErrorHandler: ErrorHandler` is not satisfied
--> src/main.rs:5:17
|
5 | cnb_runtime(CustomErrorHandler {});
| ----------- ^^^^^^^^^^^^^^^^^^^^^ the trait `ErrorHandler` is not implemented for `CustomErrorHandler`
| |
| required by a bound introduced by this call
|
note: required by a bound in `cnb_runtime`
--> /Users/emorley/src/testcase-rustc-crate-version-mismatch/c-v0.2/src/lib.rs:3:41
|
3 | pub fn cnb_runtime(_error_handler: impl ErrorHandler) {}
| ^^^^^^^^^^^^ required by this bound in `cnb_runtime`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `a` due to previous error
Ideally the output should look like:
$ cargo check
Checking c v0.1.0 (/Users/emorley/src/testcase-rustc-crate-version-mismatch/c-v0.1)
Checking c v0.2.0 (/Users/emorley/src/testcase-rustc-crate-version-mismatch/c-v0.2)
Checking b v0.1.0 (/Users/emorley/src/testcase-rustc-crate-version-mismatch/b)
Checking a v0.1.0 (/Users/emorley/src/testcase-rustc-crate-version-mismatch/a)
error[E0277]: the trait bound `CustomErrorHandler: ErrorHandler` is not satisfied
--> src/main.rs:5:17
|
5 | cnb_runtime(CustomErrorHandler {});
| ----------- ^^^^^^^^^^^^^^^^^^^^^ the trait `ErrorHandler` is not implemented for `CustomErrorHandler`
| |
| required by a bound introduced by this call
|
note: required by a bound in `cnb_runtime`
--> /Users/emorley/src/testcase-rustc-crate-version-mismatch/c-v0.2/src/lib.rs:3:41
|
3 | pub fn cnb_runtime(_error_handler: impl ErrorHandler) {}
| ^^^^^^^^^^^^ required by this bound in `cnb_runtime`
help: trait impl with same name found
--> /Users/emorley/src/testcase-rustc-crate-version-mismatch/b/src/lib.rs:3
|
LL | impl c::ErrorHandler for CustomErrorHandler {}
| ^^^^^^^^^^^^^^^^^^^
= note: Perhaps two different versions of crate `c` are being used?
For more information about this error, try `rustc --explain E0277`.
error: could not compile `a` due to previous error