"correctly" check opaque type lifetimes to be unique params #113916
Labels
A-impl-trait
Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch.
C-bug
Category: This is a bug.
F-type_alias_impl_trait
`#[feature(type_alias_impl_trait)]`
T-types
Relevant to the types team, which will review and decide on the PR/issue.
see https://rust-lang.zulipchat.com/#narrow/stream/315482-t-compiler.2Fetc.2Fopaque-types/topic/non-defining.20uses.20due.20to.20equal.20lifetimes for more details. This did not get a "formal approval" yet but summarizes the previous discussion on zulip.
We currently don't check that the provided lifetimes are unique for RPIT and async function return values in
fn check_opaque_type_parameter_valid
. We do check them for TAIT. This currently results in somewhat inconsistent behavior:The issue here is that we don't have unique lifetimes to instantiate the TAITs here, as the lifetimes are required to be equal.
The reason
fn ok
works is because nll evaluates lifetime equality based on the constraint graph alone, ignoring the the environment bounds. This is a bug, not a feature.In #112842 I check type and const arguments for defined RPITs and async returns to be unique params but ignore parameters. This is the case as otherwise the following example breaks
Because of the implied bound from the self type and the explicit
'b: 'a
bound'a
and'b
are equal. This causes us to use the same region param multiple times while defining the RPIT. What we should instead do here is the following:This handling should allow us to check the region params for RPIT and async function return types, fixing buggy (but probably not unsound) behavior. It also allowsg the following code with TAIT:
Landing this change will require an FCP.
cc @rust-lang/initiative-impl-trait @aliemjay
related to #104477 #112841
The text was updated successfully, but these errors were encountered: