Skip to content

Projections fail to unify projections in related obligations #108933

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

Open
AnthonyMikh opened this issue Mar 9, 2023 · 1 comment
Open

Projections fail to unify projections in related obligations #108933

AnthonyMikh opened this issue Mar 9, 2023 · 1 comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@AnthonyMikh
Copy link
Contributor

I tried this code:

trait Add<Rhs> {
    type Sum;
}

impl Add<()> for () {
    type Sum = ();
}

type Unit = <() as Add<()>>::Sum;

trait Trait<C> {
    type Output;
}

fn f<T>()
where
    T: Trait<()>,
    <T as Trait<()>>::Output: Sized,
{}

fn g<T>()
where
    T: Trait<Unit>,
    <T as Trait<()>>::Output: Sized,
{}

fn h<T>()
where
    T: Trait<()>,
    <T as Trait<Unit>>::Output: Sized,
{}

Function g is f with () replaced with Unit in first where clause, while function h is f with () replaced with Unit in second where clause. Since Unit is effectively a type alias for (), I expected all three functions to compile.

Instead, the compiler complains about g:

error[E0277]: the trait bound `T: Trait<()>` is not satisfied
  --> src/lib.rs:25:1
   |
25 | / fn g<T>()
26 | | where
27 | |     T: Trait<Unit>,
28 | |     <T as Trait<()>>::Output: Sized,
   | |____________________________________^ the trait `Trait<()>` is not implemented for `T`
   |
help: consider further restricting this bound
   |
27 |     T: Trait<Unit> + Trait<()>,
   |                    +++++++++++

error[E0277]: the trait bound `T: Trait<()>` is not satisfied
  --> src/lib.rs:25:4
   |
25 | fn g<T>()
   |    ^ the trait `Trait<()>` is not implemented for `T`
   |
help: consider further restricting this bound
   |
27 |     T: Trait<Unit> + Trait<()>,
   |                    +++++++++++

The compiler suggests adding Trait<()> on T, which should not be necessary since Trait<Unit> has exactly the same meaning as Trait<()> (and it actually works that way for h). Having Unit type alias is not essential, inlining it yields the same error.

(Also it complains about the same unsatisfied bound twice, but it is less of an issue, I guess)

Meta

I used the latest stable at the moment, 1.67.1, but it can also be reproduced on the latest beta (2023-03-06 b955c8271da80a1af8a1) and latest nigthly (2023-03-06 b955c8271da80a1af8a1) at the moment.

Probably related to #43049.

@rustbot label: +A-associated-items

@AnthonyMikh AnthonyMikh added the C-bug Category: This is a bug. label Mar 9, 2023
@rustbot rustbot added the A-associated-items Area: Associated items (types, constants & functions) label Mar 9, 2023
@compiler-errors compiler-errors added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Mar 13, 2023
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@lcnr
Copy link
Contributor

lcnr commented Nov 13, 2023

this has the same root cause as #41118 (comment)

@lcnr lcnr added the A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) label Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants