Confusing error `overflow evaluating the requirement` caused by duplicate trait impl
Open
Nobody has claimed this yet.
A-diagnostics
D-confusing
S-has-mcve
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
use core::marker::PhantomData;
pub trait Trait {}
pub struct Wrap<T, TA>(PhantomData<(T, TA)>);
impl<T, TA> Trait for Wrap<TypeA<T>, TypeB<TA>> where Wrap<T, TA>: Trait {}
impl<T, TA> Trait for Wrap<TypeA<T>, TypeB<TA>> {}
pub struct TypeA<T>(PhantomData<T>);
pub struct TypeB<T>(PhantomData<T>);
Current output
error[E0275]: overflow evaluating the requirement `Wrap<TypeA<_>, TypeB<_>>: Trait`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`serde_with`)
note: required for `Wrap<TypeA<TypeA<_>>, TypeB<TypeB<_>>>` to implement `Trait`
--> serde_with/src/bundled.rs:7:13
|
7 | ...A> Trait for Wrap<TypeA<T>, TypeB<TA>> where Wrap<T, TA>: Trait {}
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ----- unsatisfied trait bound introduced here
= note: 126 redundant requirements hidden
= note: required for `Wrap<TypeA<TypeA<TypeA<TypeA<...>>>>, ...>` to implement `Trait`
= note: the full type name has been written to '/home/swlynch/iop-systems/serde_with/target/debug/deps/serde_with-1bf9aea32cc91d00.long-type-11176592250759541934.txt'
For more information about this error, try `rustc --explain E0275`.
error: could not compile `serde_with` (lib) due to 1 previous error
Desired output
No response
Rationale and extra context
No response
Other cases
If there is another impl Trait block before the duplicate one then the error message will refer to that first impl Trait block
use core::marker::PhantomData;
pub trait Trait {}
pub struct Wrap<T, TA>(PhantomData<(T, TA)>);
impl<'a, T, TA> Trait for Wrap<&'a T, &'a TA> where Wrap<T, TA>: Trait {}
impl<T, TA> Trait for Wrap<TypeA<T>, TypeB<TA>> where Wrap<T, TA>: Trait {}
impl<T, TA> Trait for Wrap<TypeA<T>, TypeB<TA>> {}
pub struct TypeA<T>(PhantomData<T>);
pub struct TypeB<T>(PhantomData<T>);
Error message referring to the first trait impl
error[E0275]: overflow evaluating the requirement `Wrap<&_, &_>: Trait`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`serde_with`)
note: required for `Wrap<&&_, &&_>` to implement `Trait`
--> serde_with/src/bundled.rs:7:17
|
7 | impl<'a, T, TA> Trait for Wrap<&'a T, &'a TA> where Wrap<T, TA>: Trait {}
| ^^^^^ ^^^^^^^^^^^^^^^^^^^ ----- unsatisfied trait bound introduced here
= note: 126 redundant requirements hidden
= note: required for `Wrap<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&..., ...>` to implement `Trait`
= note: the full type name has been written to '/home/swlynch/iop-systems/serde_with/target/debug/deps/serde_with-fc07121c1d09a764.long-type-9206076556922054995.txt'
For more information about this error, try `rustc --explain E0275`.
error: could not compile `serde_with` (lib) due to 1 previous error
Rust Version
rustc 1.77.0-nightly (ca663b06c 2024-01-08)
binary: rustc
commit-hash: ca663b06c5492ac2dde5e53cd11579fa8e4d68bd
commit-date: 2024-01-08
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the diagnostic with the Rust code in the issue and inspect the reported location in serde_with/src/bundled.rs. Compare the output when the duplicate impl is present and when the preceding impl is added; the work is done when this case no longer produces a confusing overflow error pointing at the wrong impl.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100