Multiple different versions note when using main.rs + lib.rs and `use crate_name`
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
// main.rs
// mentioning `use testing` is important
use testing::{};
struct S1 {}
struct S2 {}
fn main() {
<S1 as MainTrait>::test();
}
// :Sized + return Self and no Sized and Box<Self> still trigger this
trait MainTrait {
fn test();
}
impl MainTrait for S2 {
fn test() {
todo!()
}
}
// lib.rs
pub trait LibTrait {}
Current output
Checking testing v0.1.0 (/home/ved-s/code/Rust/testing)
warning: unused import: `testing::{}`
--> src/main.rs:1:5
|
1 | use testing::{};
| ^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0277]: the trait bound `S1: MainTrait` is not satisfied
--> src/main.rs:8:6
|
8 | <S1 as MainTrait>::test();
| ^^ the trait `MainTrait` is not implemented for `S1`
|
note: there are multiple different versions of crate `testing` in the dependency graph
--> src/main.rs:12:1
|
1 | use testing::{};
| ------- one version of crate `testing` used here, as a direct dependency of the current crate
2 |
3 | struct S1 {}
| --------- this type doesn't implement the required trait
...
12 | trait MainTrait {
| ^^^^^^^^^^^^^^^ this is the required trait
|
::: /home/ved-s/code/Rust/testing/src/lib.rs:1:1
|
1 | pub trait LibTrait {}
| ------------------ this is the found trait
= help: you can use `cargo tree` to explore your dependency tree
For more information about this error, try `rustc --explain E0277`.
warning: `testing` (bin "testing") generated 1 warning
error: could not compile `testing` (bin "testing") due to 1 previous error; 1 warning emitted
Desired output
no `multiple different versions` note and pointing to the first trait in the lib.rs
Rationale and extra context
No response
Other cases
Rust Version
rustc 1.86.0-nightly (854f22563 2025-01-31)
binary: rustc
commit-hash: 854f22563c8daf92709fae18ee6aed52953835cd
commit-date: 2025-01-31
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the E0277 diagnostic with the reported main.rs and lib.rs snippets on the specified Rust nightly. Compare the current and desired output, then add regression coverage showing that the multiple-versions note is omitted and the relevant trait location in lib.rs is reported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100