Skip to content

Converting "&'a &'b T" to "&'a T" in the presence of non-lexical lifetimes can be unsound #48803

Closed
@exists-forall

Description

@exists-forall

The following snippet should be rejected for allowing a value to be mutated while it is borrowed, but it is accepted on nightly when non-lexical lifetimes are enabled (playground):

#![feature(nll)]

fn flatten<'a, 'b, T>(x: &'a &'b T) -> &'a T {
    x
}

fn main() {
    let mut x = "original";
    let y = &x;
    let z = &y;
    let w = flatten(z);
    x = "modified";
    println!("{}", w); // prints "modified"
}

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessNLL-soundWorking towards the "invalid code does not compile" goalT-compilerRelevant to the compiler 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