Skip to content

Arc is invariant in its type parameter #29037

Closed
@bkoropoff

Description

@bkoropoff

I would expect it to be covariant. This seems to be an unintentional side-effect of using *mut internally.

Code

Playground

use std::sync::Arc;

fn works<'r>(x: Box<&'static str>) -> Box<&'r str> {
    x
}

fn also_works<'r,'w>(x: &'w &'static str) -> &'w &'r str {
    x
}

fn breaks<'r>(x: Arc<&'static str>) -> Arc<&'r str> {
    x
}

fn main() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions