Skip to content

NLL: unconstrained lifetimes can be returned via associated types #47470

Closed
@arielb1

Description

@arielb1

This compiles, runs, and is UB (with NLL) - it errors correctly the return type is specified explicitly.

#![feature(nll)]

struct Foo<'a>(&'a ());
trait Bar {
    type Assoc;
    fn get(self) -> Self::Assoc;
}

impl<'a> Bar for Foo<'a> {
    type Assoc = &'a u32;
    // using `-> &'a u32` here results in a correct error
    fn get(self) -> Self::Assoc {
        let local = 42;
        &local
    }
}

fn main() {
    let f = Foo(&()).get();
    println!("{}", f);
}

cc @nikomatsakis

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions