Repository navigation
relating higher-ranked projections can unexpectedly constrain inference #107268
Copy link
Copy link
Open
Labels
A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-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.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.
Description
Activity
- addedA-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.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.I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
on Jan 24, 2023 Here is a variant
that shows why it's unsound; Inference ambiguity is accepted here:pub trait Trait { type Ty<'a>; } fn my_fn<T: Trait>(_: T::Ty<'_>) {} fn test<A, B>() -> impl Fn(A::Ty<'static>) where A: Trait, B: for<'a> Trait<Ty<'a> = A::Ty<'a>>, { my_fn::<_> // A and B are both valid options; We pick A! }
I think this needs a better example for the unsoundness. The inference variable being constrained by one where-clause predicate over the other is not unsound, regardless of whether we think that the behavior is surprising.
At least, this is totally fine to do inside of a function body, I thought?
After the discussion in a zulip thread, I agree that this is not necessarily a soundness bug. 😅
@rustbot label -I-unsound
- removedI-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/Soundness
on Jan 27, 2023 - changed the title
[-]relating higher-ranked projections can unsoundly constrain inference[/-][+]relating higher-ranked projections can unexpectedly constrain inference[/+]on Jan 27, 2023 WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-medium
- addedP-mediumMedium priorityMedium priorityand removedI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
on Jan 31, 2023 - addedA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)
on Sep 24, 2024 - addedfixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.
on May 1, 2025
Metadata
Metadata
Assignees
Labels
A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-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.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.
The following compiles (although it shouldn't, arguably, see below for reasoning): https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=05d31c1cc2a9e8752d7a3fc05e9446ea
It stops compiling with a trivial change that gets rid of higher-ranked regions:
This was discovered by @BoxyUwU in #96912.
@rustbot label T-types C-bug I-unsound A-inference