-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Incomprehensible error message involving lifetimes adding extension methods to dyn Trait
#71341
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Current output:
|
Minimized: trait OtherTrait<'a> {}
impl<'a> OtherTrait<'a> for &'a () {}
trait ObjectTrait {}
trait MyTrait {
fn use_self(&self) -> &();
}
impl MyTrait for dyn ObjectTrait {
fn use_self(&self) -> &() { panic!() }
}
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
val.use_self()
}
The very non-obvious fix is to change The issue here is that |
@Aaron1011 with #73783 applied: I would love it if we could have a more reliable way of addressing this, but at least it is a start. |
…time, r=nikomatsakis Detect when `'static` obligation might come from an `impl` Partly address rust-lang#71341.
…time, r=nikomatsakis Detect when `'static` obligation might come from an `impl` Partly address rust-lang#71341.
…time, r=nikomatsakis Detect when `'static` obligation might come from an `impl` Partly address rust-lang#71341.
Current output:
I think this ticket can be closed now, but for some reason I didn't with the PR (and I don't recall why). |
I agree, thanks for fixing this!!! |
I'm defining a trait that adds extension methods to
dyn <another-trait>
:Complete example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9918f3c4541601415f65606b4bfa0790
Rust stable and nightly both give
This is confusing. Obviously, adding a lifetime parameter identical to one already present doesn't seem sensible. Furthermore there is no clue here indicating what the error actually is. I spent over an hour thrashing around and ended up with https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fda63d48e1652dcfd0923002f723163c --- i.e. I need to add a lifetime bound to the
dyn
type I'm extending, not just the method(s) on the extension.I'm assuming that the compiler is correct here and it just needs a better error message. I'm not 100% sure about that though.
The text was updated successfully, but these errors were encountered: