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

Async method taking a reference argument fails to compile #61

Closed
Wesmania opened this issue Dec 2, 2020 · 0 comments · Fixed by #62
Closed

Async method taking a reference argument fails to compile #61

Wesmania opened this issue Dec 2, 2020 · 0 comments · Fixed by #62

Comments

@Wesmania
Copy link

Wesmania commented Dec 2, 2020

I have this minimal example:

#[cfg(test)]
use mocktopus::macros::*;
pub struct Foo { }
#[cfg_attr(test, mockable)]
impl Foo {
    pub async fn read(&mut self, buf: &mut[u8]) {
        let _ = buf;
    }
}

It builds fine without tests, but fails with tests enabled with:

error[E0621]: explicit lifetime required in the type of `buf`
  --> src/main.rs:13:5
   |
12 |       pub async fn read(&mut self, buf: &mut[u8]) -> ()
   |                                         -------- help: add explicit lifetime `'mocktopus` to the type of `buf`: `&'mocktopus mut [u8]`
13 | /     {
14 | |         let _ = buf;
15 | |     }
   | |_____^ lifetime `'mocktopus` required

Using pub async fn read<'a>(&mut self, buf: &'a mut[u8]) instead silences the error. I have no idea if it's a good workaround.

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

Successfully merging a pull request may close this issue.

1 participant