We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
trait Y { fn f(&self) { } } struct X; impl Y for X { } struct Z<Trait: ?Sized> { _data: std::marker::PhantomData<Trait>, } fn f<Y: ?Sized>(y: &Y) -> Z<Y> { Z { _data: std::marker::PhantomData } } fn main() { { let arc = std::sync::Arc::new(X); f(&*arc as &Y) }; }
test4.rs:18:13: 18:16 error: `arc` does not live long enough test4.rs:18 f(&*arc as &Y) ^~~
The text was updated successfully, but these errors were encountered:
Worked on monday.
Sorry, something went wrong.
#22230 and/or #21972. This works:
trait Y { fn f(&self) { } } struct X; impl Y for X { } struct Z<Trait: ?Sized> { _data: std::marker::PhantomData<Trait>, } fn f<Y: ?Sized>(y: &Y) -> Z<Y> { Z { _data: std::marker::PhantomData } } fn main() { { let arc = std::sync::Arc::new(X); f(&*arc as &(Y+'static)) }; }
Ah, I tried this with &'a (Y+'b) but it didn't work. Using 'static seems to solve the problem.
It's a bit surprising that the lifetimes cannot be specified in the function signature, e.g.
fn f<'a, Y: ?Sized+'static>(y: &'a Y) -> Z<Y> { Z { _data: std::marker::PhantomData } }
alone does not solve the problem. But once you know that you have to specify the 'static in the as it's clear.
as
No branches or pull requests
The text was updated successfully, but these errors were encountered: