Skip to content

Type alias definition changed during reexport #60113

Open
@Disasm

Description

@Disasm

Consider the following crate (test2):

pub trait Foo { }

pub type FooDyn = dyn Foo;

pub struct Bar;

impl Bar {
    pub fn bar(&self) -> &FooDyn {
        unimplemented!();
    }
}

Documentation for this crate says that FooDyn and bar signatures are the following:

type FooDyn = dyn Foo;
pub fn bar(&self) -> &FooDyn

You can assume that according to the lifetime elision rules you will get the following equivalent signature:

pub fn bar(&'a self) -> &'a FooDyn

However, it's not true. If you reexport FooDyn and Bar types in another crate (test1), you will get the following signatures in test1 crate:

type FooDyn = dyn Foo + 'static;
pub fn bar(&self) -> &(dyn Foo + 'static)

One of the ways of resolving the issue is the following declaration:

pub type FooDyn<'a> = dyn 'a + Foo;

As for me, it's strange to have 'static lifetime here by default, so maybe there should be an error if lifetime is omitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions