Skip to content

Hidden lifetime in return types containing trait parameters #22606

@mahkoh

Description

@mahkoh
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)
                        ^~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions