- Notifications
You must be signed in to change notification settings - Fork 14.1k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]``#[feature(type_alias_impl_trait)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
The following UB compiles: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4cc89e9d4c133a6398f297e6f56e07f2
#![feature(type_alias_impl_trait)] use core::fmt::Display; type Opaque<'a> = impl Sized + 'static; fn define<'a>() -> Opaque<'a> {} trait Trait { type Assoc: Display; } impl<'a> Trait for Opaque<'a> { type Assoc = &'a str; } // ======= Exploit ======= fn extend<T: Trait + 'static>(s: T::Assoc) -> Box<dyn Display> { Box::new(s) } fn main() { let val = extend::<Opaque<'_>>(&String::from("blah blah blah")); println!("{}", val); }The impl is invalid because the lifetime parameter 'a appears unconstrained in the impl header. It should be rejected for the same reason that projection types doesn't constraint impl generics:
impl<'a> Trait for <Opaque<'a> as Trait>::Assoc { //~^ ERROR the lifetime parameter `'a` is not constrained type Assoc = &'a str; }@rustbot label C-bug T-types I-unsound requires-nightly F-type_alias_impl_trait
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]``#[feature(type_alias_impl_trait)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.