1
Fork 0

Detect when 'static obligation might come from an impl

Address #71341.
This commit is contained in:
Esteban Küber 2020-06-26 18:52:00 -07:00
parent 9e92106d45
commit 6513148c14
13 changed files with 431 additions and 302 deletions

View file

@ -0,0 +1,37 @@
// run-rustfix
#![allow(dead_code)]
mod foo {
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() //~ ERROR cannot infer an appropriate lifetime
}
}
mod bar {
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) -> &'a () {
val.use_self() //~ ERROR cannot infer an appropriate lifetime
}
}
fn main() {}