Repository navigation
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-crate-version-mismatchDiagnostics: Errors or lints caused be the use of two different crate versions.Diagnostics: Errors or lints caused be the use of two different crate versions.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
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
Reacted by Ed Morley, Ragnar Groot Koerkamp, jyn, Eric Walkingshaw, bever1337 and Aliaksandr Rahalevich
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-crate-version-mismatchDiagnostics: Errors or lints caused be the use of two different crate versions.Diagnostics: Errors or lints caused be the use of two different crate versions.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.
Activity
pmarks commentedon Oct 15, 2021
We've seen a similar case recently where the
note: Perhaps two different versions of cratecare being used?should have been triggered. Not sure if it's the same bug or new one. Message we got is below. I can prepare a minimal test case and/or file a separate issue.konnorandrews commentedon Feb 4, 2022
I helped @JtotheThree on the Rust Discord server with a related setup. Its not exactly the same so I have create a test case for it here. However, this setup looks to be closely related to this class of help messages so I have included it here instead of making a new issue.
The contradictory seeming help message rustc provides caused confusion on what was happening. In the original code there was a macro involved that was suspected originally as ignoring use statements. After using the fully qualified syntax to invoke the trait function it was realized that the trait used was not the same version as the implementing version and the macro was not at fault.
This setup is also similar to @pmarks case above, but with an associated function instead of a method.
theCapypara commentedon Jul 22, 2022
I stumbled upon this issue today. In case it helps, here's my particular setup:
Crates involved:
amiquipprovides a trait and an impl as such:When trying to use pass a v0.8
TcpStreamto a method ofamiquipthat wants anIoStreamI get the following error:This is by far the worst error message the Rust compiler has given me so far.
It took me almost an hour until I realized what was going on, I thought I'd gone insane.
The compiler should output a hint about a possible version mismatch in this case.
estebank commentedon Aug 8, 2024
Interestingly, #124944 doesn't trigger for the case in the repro repository. I'll dig deeper.
Edit: I've found the discrepancy: currently the new note will trigger only if the type comes from another version of the same crate, but we need to also check "of all of the traits available, is there one with the same name, same crate name, and different crate
DefId?", which is different (and more general). I have a patch to account for this:Tweak detection of multiple crate versions to be more ecompassing
estebank commentedon Aug 8, 2024
Final output:
edmorley commentedon Aug 8, 2024
In the testcase none of the crates are named
ErrorHandler.It seems this perhaps should be either
trait ErrorHandlerorcrate 'c'?edmorley commentedon Aug 8, 2024
Oh and thank you for looking into fixing/improving this!
Tweak detection of multiple crate versions to be more ecompassing
estebank commentedon Aug 8, 2024
Thanks for pointing that out, I fixed it after I took the screenshot (
crate_name->trait_nametypo) :)Tweak detection of multiple crate versions to be more ecompassing
Tweak detection of multiple crate versions to be more ecompassing
Tweak detection of multiple crate versions to be more ecompassing
Tweak detection of multiple crate versions to be more ecompassing
Tweak detection of multiple crate versions to be more ecompassing
Auto merge of rust-lang#128849 - estebank:issue-89143, r=jackh726
Auto merge of rust-lang#128849 - estebank:issue-89143, r=jackh726