-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
I tried this code (playground):
use std::ops::Add;
struct A<T>(T);
impl<T> Add<A<T>> for i32
where
i32: Add<T, Output = T>,
{
type Output = A<T>;
fn add(self, rhs: A<T>) -> Self::Output {
A(Add::add(self, rhs.0))
}
}
fn main() {}
I think this code should compile. However, I got the following compile error:
error[E0275]: overflow evaluating the requirement `i32: Add<A<_>>`
--> src/lib.rs:12:11
|
12 | ... A(Add::add(self, rhs.0))
| ^^^^^^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`geometry`)
note: required for `i32` to implement `Add<A<A<_>>>`
--> src/lib.rs:5:9
|
5 | impl<T> Add<A<T>> for i32
| ^^^^^^^^^ ^^^
6 | where
7 | i32: Add<T, Output = T>,
| ---------- unsatisfied trait bound introduced here
= note: 127 redundant requirements hidden
= note: required for `i32` to implement `Add<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<_>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
Changing A(Add::add(self, rhs.0))
to A(self + rhs.0)
or A(Add::<T>::add(self, rhs.0))
results in a successful compilation. Maybe related to #39959?
Meta
rustc --version --verbose
:
rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: aarch64-apple-darwin
release: 1.68.2
LLVM version: 15.0.6
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.