rust-lang / trait-system-refactor-initiative

The Rustc Trait System Refactor Initiative
21 stars 0 forks source link

Ambiguity for projection candidates that aren't equal, but *are* equal modulo normalization #4

Open compiler-errors opened 1 year ago

compiler-errors commented 1 year ago

edit: after https://github.com/rust-lang/rust/pull/119106 this only affects higher ranked aliases and should not be an issue in practice

fn needs_iter(_: impl Iterator<Item = i32>) {}

fn main() {
    needs_iter(IntoIterator::into_iter([0i32; 32]))
}

Bails out with two ambiguous candidates:

Candidate { source: Impl(DefId(2:3663 ~ core[523c]::array::iter::{impl#2})), result: Canonical { value: Response { certainty: Yes, var_values: CanonicalVarValues { var_values: [i32] }, external_constraints: ExternalConstraints(Interned(ExternalConstraintsData { region_constraints: QueryRegionConstraints { outlives: [], member_constraints: [] }, opaque_types: [] }, PrivateZst)) }, max_universe: U0, variables: [] } },
  Candidate { source: AliasBound, result: Canonical { value: Response { certainty: Yes, var_values: CanonicalVarValues { var_values: [<[i32; 32] as std::iter::IntoIterator>::Item] }, external_constraints: ExternalConstraints(Interned(ExternalConstraintsData { region_constraints: QueryRegionConstraints { outlives: [], member_constraints: [] }, opaque_types: [] }, PrivateZst)) }, max_universe: U0, variables: [] } }]

That is, we have that <[i32; 32] as IntoIterator>::Item normalizes to either i32 or <[i32; 32] as std::iter::IntoIterator>::Item via an impl or alias bound, respectively.

compiler-errors commented 7 months ago

This is no longer ambiguous because we only assemble alias-bound candidates for rigid aliases.

compiler-errors commented 7 months ago

Actually maybe I'll open this back up because I didn't see the edit note above.

compiler-errors commented 5 months ago

cc @jdno your repo syncs will close random cross-org issues

jdno commented 5 months ago

What the... šŸ˜³ Thanks for letting me know. I'll look into this.

compiler-errors commented 5 months ago

possibly because you've got owner permission for all the repos via t-infra?