Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lifetime remover #17

Closed
CodeSandwich opened this issue Jan 15, 2018 · 1 comment
Closed

Remove lifetime remover #17

CodeSandwich opened this issue Jan 15, 2018 · 1 comment

Comments

@CodeSandwich
Copy link
Owner

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:

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

@CodeSandwich
Copy link
Owner Author

Fixed in 0.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant