Closed
Description
#![feature(type_alias_impl_trait)]
mod lifetime_params {
type Ty<'a> = impl Sized + 'a;
fn define(s: &str) -> Ty<'_> { s }
type BadFnSig = fn(Ty<'_>) -> &str;
type BadTraitRef = dyn Fn(Ty<'_>) -> &str;
}
mod type_params {
type Ty<T> = impl Sized;
fn define<T>(s: T) -> Ty<T> { s }
type BadFnSig = fn(Ty<&str>) -> &str;
type BadTraitRef = dyn Fn(Ty<&str>) -> &str;
}
Prior to #96903, these types were rejected with this error:
error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
--> /tmp/test9.rs:7:35
|
7 | type BadFnSig = fn(Ty<'_>) -> &str;
| ^^^^
|
= note: lifetimes appearing in an associated type are not considered constrained
Currently, they're accepted.
Based on the assumption that generic parameters on opaque type are not constrained (see Niko's comment #95474 (comment)), I believe the previous behavior is correct.
CC: @oli-obk
@rustbot label F-type_alias_impl_trait A-impl-trait T-compiler A-lifetimes
Metadata
Metadata
Assignees
Labels
Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: Lifetimes / regionsCategory: This is a bug.`#[feature(type_alias_impl_trait)]`Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.
Type
Projects
Status
Done