Skip to content

Mocks closures respect no lifetime constraints #38

Description

@CodeSandwich

This code compiles causing conversion of &str to &'static str:

#[mockable]
fn terrible(_: &str) -> &'static str {
    "a"
}

#[test]
fn terrible_test() {
    // This closure has type `for <'a> fn(&'a str) -> MockResult<(&'a str,), &'a str>`
    terrible.mock_safe(|a| MockResult::Return(a));
    let x = "abc".to_string();
    let y = x.as_str();
    let z: &'static str = terrible(y);
    assert_eq!("abc", z);
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions