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

failure::format_err! inside try_stream! strange behavior #22

Closed
serejkaaa512 opened this issue Jan 27, 2020 · 2 comments
Closed

failure::format_err! inside try_stream! strange behavior #22

serejkaaa512 opened this issue Jan 27, 2020 · 2 comments

Comments

@serejkaaa512
Copy link

If using format_err! macro inside try_stream!:

use failure::*;

pub fn stream() -> impl Stream<Item = failure::Fallible<i32>> + Send {
    async_stream::try_stream! {
        Err(format_err!("adasdasd"))?;
        for i in (1..10) {
            yield 123;
        }
    }
}

It doesn't compile - *mut (dyn std::ops::Fn() + 'static) cannot be shared between threads safely.
But when using it without format_err!:

use failure::*;

#[derive(Debug, Fail)]
#[fail(display = "my error")]
pub struct MyError;

pub fn stream() -> impl Stream<Item = Fallible<i32>> + Send {
    async_stream::try_stream! {
        Err(MyError)?;
        for i in (1..10) {
            yield 123;
        }
    }
}

Compiler says all Ok.

@taiki-e
Copy link
Member

taiki-e commented Jan 27, 2020

failure::format_err! calls format! internally. And std::fmt::Arguments(called by format!) are not implemented Send, so any future containing them will not be implemented Send.

related: rust-lang/rust#64960, rust-lang/rust#64856

@carllerche
Copy link
Member

I will close the issue as this is an upstream thing.

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

No branches or pull requests

3 participants