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

Confusing error overflow evaluating the requirement caused by duplicate trait impl #119839

Open
swlynch99 opened this issue Jan 11, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@swlynch99
Copy link

swlynch99 commented Jan 11, 2024

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
@swlynch99 swlynch99 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 11, 2024
@jieyouxu
Copy link
Member

@rustbot label +D-confusing +S-has-mcve -needs-triage

@rustbot rustbot added D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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

3 participants