You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lifetime remover is a big boilerplate and actually a dirty hack.
Why is there lifetime remover anyway?
The lifetime remover is needed in cases, where Rust can't reason well enough about lifetimes of generics.
Example:
trait Trait<T> {
fn method() -> &'static str {
"method"
}
fn another() -> &'static str;
}
struct Struct();
impl<'a, T> Trait<&'a T> for Struct {
fn another() -> &'static str {
//<Self as Trait<&'a T>>::method() // FAILS TO COMPILE
<Self as Trait<&T>>::method() // COMPILES FINE
}
}
This is exactly the behavior that is needed in code generated in Mocktopus. It builds full UFC call to trait method of struct with exactly same generics params. Right now copying trait name from impl header Trait<&'a T> and putting it in <Self as Trait<&'a T>>::method() confuses the compiler, it can't find out, that &'a T implies T: 'a and complains, that T may not live as long as 'a. The workaround is to remove lifetimes from generic parameters and make it <Self as Trait<&T>>::method(). It works, because lifetimes are actually dropped during monomorphisation and Rust can prove this statement to be safe.
Solution
If I understand correctly, rust-lang/rust#44493 solves exactly the hole in Rust's lifetime reasoning, which forces Mocktopus to use lifetime remover
The text was updated successfully, but these errors were encountered:
Goal
Remove lifetime remover
Motivation
Lifetime remover is a big boilerplate and actually a dirty hack.
Why is there lifetime remover anyway?
The lifetime remover is needed in cases, where Rust can't reason well enough about lifetimes of generics.
Example:
This is exactly the behavior that is needed in code generated in Mocktopus. It builds full UFC call to trait method of struct with exactly same generics params. Right now copying trait name from impl header
Trait<&'a T>
and putting it in<Self as Trait<&'a T>>::method()
confuses the compiler, it can't find out, that&'a T
impliesT: 'a
and complains, thatT
may not live as long as'a
. The workaround is to remove lifetimes from generic parameters and make it<Self as Trait<&T>>::method()
. It works, because lifetimes are actually dropped during monomorphisation and Rust can prove this statement to be safe.Solution
If I understand correctly, rust-lang/rust#44493 solves exactly the hole in Rust's lifetime reasoning, which forces Mocktopus to use lifetime remover
The text was updated successfully, but these errors were encountered: