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

Trivial bounds with associated types regression #134238

Open
konnorandrews opened this issue Dec 13, 2024 · 2 comments
Open

Trivial bounds with associated types regression #134238

konnorandrews opened this issue Dec 13, 2024 · 2 comments
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@konnorandrews
Copy link

Code

I tried writing some macro code that in some cases generates code similar to:

pub trait A {
    type X;
}

pub trait B: A<X = Self::Y> {
    type Y: C;
}

impl<L> A for L {
    type X = L;
}

pub trait C {}

impl C for () {}

impl<T> B for T 
where
    T: A,
    T::X: C,
{
    type Y = T::X;
}

fn demo() where for<'a> (): B {}

I expected to see this happen: The code should compile without error.

Instead, this happened: The following compile error happens.

error[E0284]: type annotations needed
  --> <source>:25:1
   |
25 | fn demo() where for<'a> (): B {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
   |
   = note: cannot satisfy `<() as B>::Y == _`

error[E0284]: type annotations needed
  --> <source>:25:29
   |
25 | fn demo() where for<'a> (): B {}
   |                             ^ cannot infer type
   |
   = note: cannot satisfy `<() as B>::Y == _`

Discussing with @compiler-errors some it would appear #122791 is the cause of the change. The above code does compile if it isn't a trivial bound. For example when you do this instead:

fn demo<T>() where T: B {}

fn other() {
    demo::<()>();
}

For more context on 1.78.0 and before if you remove the for<'a> you get the following.

error[E0271]: type mismatch resolving `<() as A>::X == <() as B>::Y`
  --> <source>:25:17
   |
25 | fn demo() where (): B {}
   |                 ^^^^^ type mismatch resolving `<() as A>::X == <() as B>::Y`
   |
note: expected this to be `()`
  --> <source>:10:14
   |
10 |     type X = L;
   |              ^
   = note:    expected unit type `()`
           found associated type `<() as B>::Y`
   = help: consider constraining the associated type `<() as B>::Y` to `()`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
   = help: see issue #48214

Version it worked on

It most recently worked on: 1.78.0

Version with regression

All versions including 1.79.0 and after. Specifically starting with nightly-2024-04-04 (found with a bisection).

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

@konnorandrews konnorandrews added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Dec 13, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-untriaged Untriaged performance or correctness regression. labels Dec 13, 2024
@compiler-errors
Copy link
Member

This regressed in #122791. Probably something due to no longer winnowing cyclical candidates that are known to fail or something. I don't expect us to be able to fix this.

@compiler-errors compiler-errors added P-low Low priority A-trait-system Area: Trait system and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 13, 2024
@compiler-errors
Copy link
Member

For the record this is fixed by the new trait solver.

@fmease fmease added fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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

4 participants