Closed
Description
mod banana {
pub struct Chaenomeles;
pub trait Apple {
fn pick(&self) {}
}
impl Apple for Chaenomeles {}
pub trait Peach {
fn pick(&self, a: &mut ()) {}
}
impl<Mango: Peach> Peach for Box<Mango> {}
impl Peach for Chaenomeles {}
}
fn main() {
banana::Chaenomeles.pick()
}
Produces the output as such:
error[[E0599]](https://doc.rust-lang.org/stable/error-index.html#E0599): no method named `pick` found for struct `Chaenomeles` in the current scope
[--> src/main.rs:17:25
](https://play.rust-lang.org/#) |
2 | pub struct Chaenomeles;
| ----------------------- method `pick` not found for this
...
10 | fn pick(&self, a: &mut ()) {}
| ---- the method is available for `Box<Chaenomeles>` here
...
17 | banana::Chaenomeles.pick()
| ^^^^ method not found in `Chaenomeles`
|
= help: items from traits can only be used if the trait is in scope
help: consider wrapping the receiver expression with the appropriate type
|
17 | Box::new(banana::Chaenomeles).pick()
| +++++++++ +
help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
|
1 | use crate::banana::Apple;
|
1 | use crate::banana::Peach;
|
Note that the message suggests wrapping the receiver expression in a Box::new
even though it won't really help much unless the traits are imported. And if the trait was imported in the first place, the receiver type would've been fine either way.