Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False ambiguity due to overlap between higher-ranked and other where clause #27834

Open
nikomatsakis opened this issue Aug 14, 2015 · 3 comments
Labels
A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-trait-system Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

The test at http://is.gd/xHYV2z was extracted from the qcollect-traits package on crates.io. It fails to compile due to a false ambiguity between the higher-ranked where-clause and the other one. This is particularly frustrating because the ambiguity occurs as part of projection and the higher-ranked where clause doesn't even list a binding for Output.

The correct fix is probably to prune one where clause or the other as part of selection, but this is a bit tricky with the current region setup due to #21974.

pub trait ImmutableSequenceTypes<'a, T:'a>{
    type Output;
}

pub trait MutableSequenceTypes<'a, T:'a>: ImmutableSequenceTypes<'a, T> {
}

fn foo<'t,X,T:'t>()
    where X: for<'a> ImmutableSequenceTypes<'a, T>,
          X: ImmutableSequenceTypes<'t, T, Output=&'t T>
{
    bar::<<X as ImmutableSequenceTypes<'t,T>>::Output>();
}

fn bar<A>() { }

fn main() { }

(Due to this bug, PR #27641 causes a regression in qcollect-traits, but the problem is pre-existing.)

@nikomatsakis nikomatsakis added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 14, 2015
@steveklabnik
Copy link
Member

Triage: this still fails to compile today.

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@steveklabnik
Copy link
Member

Triage: this still fails to compile, with

error[E0282]: type annotations needed
  --> src/main.rs:8:1
   |
8  | / fn foo<'t,X,T:'t>()
9  | |     where X: for<'a> ImmutableSequenceTypes<'a, T>,
10 | |           X: ImmutableSequenceTypes<'t, T, Output=&'t T>
11 | | {
12 | |     bar::<<X as ImmutableSequenceTypes<'t,T>>::Output>();
13 | | }
   | |_^ cannot infer type

@estebank
Copy link
Contributor

Current output:

error[E0283]: type annotations needed: cannot satisfy `X: ImmutableSequenceTypes<'t, T>`
  --> f71.rs:10:14
   |
10 |           X: ImmutableSequenceTypes<'t, T, Output=&'t T>
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: multiple `impl`s or `where` clauses satisfying `X: ImmutableSequenceTypes<'t, T>` found
  --> f71.rs:9:14
   |
9  |     where X: for<'a> ImmutableSequenceTypes<'a, T>,
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10 |           X: ImmutableSequenceTypes<'t, T, Output=&'t T>
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@fmease fmease added A-trait-system Area: Trait system T-types Relevant to the types team, which will review and decide on the PR/issue. A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) labels Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-trait-system Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants