Confusing error message when traits from different modules have the same name
This error looks pretty bizarre, right? Especially the "help:" message, which is clearly not helpful at all. (This is from the current nightly.)
error[E0277]: the trait bound `B: Basics` is not satisfied
--> src\collision_detection\simple_grid.rs:115:1
|
115 | pub fn insert_predictors <B: Basics, Settings: TimeStewardSettings <B>> (s
ettings: Settings) {
| ^ trait `B: Basics` not satisfied
|
= help: consider adding a `where B: Basics` bound
= note: required by `TimeStewardSettings`
What happened is that I had two traits named Basics, one in the crate root and one in the current module. Presumably, the compiler could give a clearer error message in this situation, although I'm not sure what the best way to handle it is – it would obviously be bad to give the full path for every trait mentioned in an error message. Maybe it should give the full path exactly when there are two traits (or other objects) with the same name?
Doesn't seem to be an issue anymore. The compiler spits out the trait's path when it emits an error.
trait MyTrait { } struct Wrapper<T: MyTrait>(std::marker::PhantomData<T>); struct Value; impl MyTrait for Value { } mod inner { trait MyTrait { } fn method<T: MyTrait>() { } fn call() { method::<super::Wrapper<super::Value>>(); } }the trait
inner::MyTraitis not implemented forWrapper<Value>EDIT: Nevermind, I misunderstood the issue.
I've created an mcve:
trait MyTrait { } trait Wrapper<T: MyTrait> { } mod inner { trait MyTrait { } fn method<T: MyTrait, W: super::Wrapper<T>>() { } } fn main() {}Jezza at 2019-12-03 13:42:54
@rustbot modify labels: -E-needs-mcve
Squirrel at 2019-12-16 08:21:56
-
error[E0277]: the trait bound `T: MyTrait` is not satisfied --> src/main.rs:10:27 | 10 | fn method<T: MyTrait, W: super::Wrapper<T>>() { | ^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `T` | note: required by a bound in `Wrapper` --> src/main.rs:4:18 | 4 | trait Wrapper<T: MyTrait> { | ^^^^^^^ required by this bound in `Wrapper` help: consider further restricting this bound | 10 | fn method<T: MyTrait + MyTrait, W: super::Wrapper<T>>() { | +++++++++but it should be
help: consider further restricting this bound | 10 | fn method<T: MyTrait + crate::MyTrait, W: super::Wrapper<T>>() { | ++++++++++++++++Esteban Kuber at 2023-07-24 20:10:45