Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple different versions note when using main.rs + lib.rs and use crate_name #136377

Open
Ved-s opened this issue Feb 1, 2025 · 4 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Ved-s
Copy link

Ved-s commented Feb 1, 2025

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

@Ved-s Ved-s added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 1, 2025
@hanna-kruppe
Copy link
Contributor

This does not reproduce 1.83 but does reproduce on 1.84, so it's a stable-to-stable regression. The note about there being multiple crates called testing is technically correct but unhelpful in this case.

Note that the unused import warning can be avoided while still reproducing the regression by writing extern crate testing; instead of use testing::{};.

@Ved-s
Copy link
Author

Ved-s commented Feb 1, 2025

@hanna-kruppe what about it pointing to the first trait in the lib.rs?

   |
1  | pub trait LibTrait {}
   | ------------------ this is the found trait

@Ved-s
Copy link
Author

Ved-s commented Feb 1, 2025

Also i had a compiler panic in the same place in the crate i was making, which then got replaced by this after updating from 1.84 nightly to 1.86 nightly, i can attach a crash log it made if that may be relevant

@hanna-kruppe
Copy link
Contributor

@hanna-kruppe what about it pointing to the first trait in the lib.rs?

   |
1  | pub trait LibTrait {}
   | ------------------ this is the found trait

The full output with 1.83, using main.rs exactly as in the issue except for use -> extern crate, is:

error[E0277]: the trait bound `S1: MainTrait` is not satisfied
 --> src/main.rs:9:6
  |
9 |     <S1 as MainTrait>::test();
  |      ^^ the trait `MainTrait` is not implemented for `S1`
  |
  = help: the trait `MainTrait` is implemented for `S2`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `testing` (bin "testing") due to 1 previous error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants