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

-Znext-solver overflow evaluating the requirement #137973

Open
konnorandrews opened this issue Mar 4, 2025 · 1 comment
Open

-Znext-solver overflow evaluating the requirement #137973

konnorandrews opened this issue Mar 4, 2025 · 1 comment
Labels
C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Comments

@konnorandrews
Copy link

I tried this code:

use std::ops::Add;

impl<S, const LEN: usize> MyTrait for [S; LEN]
where
    N<LEN>: ToNum,
    S: ToNum<Num: Add<Helper<LEN>, Output: Num>>,
{
}

type Helper<const LEN: usize> = <N<LEN> as ToNum>::Num;

trait MyTrait {}

struct N<const N: usize>;

trait ToNum {
    type Num: Num;
}

trait Num: ToNum<Num = Self> {}

I expected to see this happen: On the current trait solver the above code compiles so it would be expected that the new trait solver also does.

Instead, this happened: The new trait solver reports an overflow attempting to evaluate the trait bound.

error[E0275]: overflow evaluating the requirement `[S; LEN]: MyTrait`
 --> <source>:3:39
  |
3 | impl<S, const LEN: usize> MyTrait for [S; LEN]
  |                                       ^^^^^^^^

error[E0275]: overflow evaluating the requirement `<S as ToNum>::Num: Add<<N<LEN> as ToNum>::Num>`
 --> <source>:6:19
  |
6 |     S: ToNum<Num: Add<Helper<LEN>, Output: Num>>,
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0275]: overflow evaluating the requirement `<<S as ToNum>::Num as Add<<N<LEN> as ToNum>::Num>>::Output: Num`
 --> <source>:6:44
  |
6 |     S: ToNum<Num: Add<Helper<LEN>, Output: Num>>,
  |                                            ^^^

error[E0275]: overflow evaluating the requirement `<N<LEN> as ToNum>::Num: Sized`
 --> <source>:6:19
  |
6 |     S: ToNum<Num: Add<Helper<LEN>, Output: Num>>,
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: required by an implicit `Sized` bound in `Add`
 --> /rustc/f4a216d28ee635afce685b4206e713579f66e130/library/core/src/ops/arith.rs:78:1

error[E0275]: overflow evaluating the requirement `<<S as ToNum>::Num as Add<<N<LEN> as ToNum>::Num>>::Output well-formed`
 --> <source>:6:44
  |
6 |     S: ToNum<Num: Add<Helper<LEN>, Output: Num>>,
  |                                            ^^^

I isolated this from a project of mine that has hit this a few times. The core issue seems to be the

trait A: B<A = Self> {}

pattern seen in the code above. However, the failure to evaluate the bound doesn't always trigger when using a trait of that form.

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (f4a216d28 2025-03-02)
binary: rustc
commit-hash: f4a216d28ee635afce685b4206e713579f66e130
commit-date: 2025-03-02
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
@konnorandrews konnorandrews added the C-bug Category: This is a bug. label Mar 4, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 4, 2025
@konnorandrews
Copy link
Author

@rustbot label WG-trait-system-refactor

@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

No branches or pull requests

2 participants