Skip to content

RPIT hidden types can be ill-formed #114728

@aliemjay

Description

@aliemjay

The following UB shouldn't compile:

type Static<'a> = &'static &'a ();
trait Extend<'a> {
    fn extend(self, _: &'a str) -> &'static str;
}
impl<'a> Extend<'a> for Static<'a> {
    fn extend(self, s: &'a str) -> &'static str {
        s
    }
}
fn boom<'a>(arg: Static<'_>) -> impl Extend<'a> {
    arg
}
fn main() {
    let y = boom(&&()).extend(&String::from("temporary"));
    println!("{}", y);
}

This regressed in v1.61. I guess it is #94081.

Discovered when investigating #114572.

Metadata

Metadata

Assignees

Labels

A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-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

Status

Completed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions