-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-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-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-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
#![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
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-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-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-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.
Type
Projects
Status
Done