Skip to content

impl Trait lifetimes regression 1.67 #108591

Closed
@aliemjay

Description

@aliemjay

Some regressions of #103491 that I previously reported in #105826 (comment), but they were missed:

struct MyTy<'a>(Vec<u8>, &'a ());

impl MyTy<'_> {
    fn one(&mut self) -> &mut impl Sized {
        &mut self.0
    }
    fn two(&mut self) -> &mut (impl Sized + 'static) {
        self.one()
        //~^ ERROR lifetime may not live long enough
    }
}
#![feature(type_alias_impl_trait)]
type Opaque<'a> = impl Sized;
fn define<'a>() -> Opaque<'a> {}

fn test<'a>() {
    None::<&'static Opaque<'a>>;
    //~^ ERROR lifetime may not live long enough
}
fn one<'a, 'b: 'b>() -> &'a impl Sized {
    &()
}
fn two<'a, 'b>() {
    one::<'a, 'b>();
    //~^ ERROR lifetime may not live long enough
}

I guess the way to fix this is to ignore non-captured lifetimes of opaque types here

cc @cjgillot

@rustbot label C-bug regression-from-stable-to-stable T-types T-compiler A-impl-trait

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions