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

error: overflow evaluating the requirement without precise link to origin of the error #81785

Closed
gui1117 opened this issue Feb 5, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@gui1117
Copy link
Contributor

gui1117 commented Feb 5, 2021

When some type doesn't implement some trait, rust error message overflow evaluating the requirement (which is ok), but it fails to give a proper error message, as it doesn't show where the error comes from. It would be very more helpful if the error message points to where the failing evaluation comes from.

I tried this code:

pub struct Compact<T>(pub T);

pub trait Decode {}

pub trait WrapperTypeDecode {
	type Wrapped;
}

pub trait CompactAs {
	type As;
}

pub trait HasCompact {}


impl<T, X> Decode for X
where
	X: WrapperTypeDecode<Wrapped=T>,
	T: Decode,
{}

impl<T> HasCompact for T
where
	Compact<T>: Decode,
{}

impl<T> Decode for Compact<T>
where
	T: CompactAs,
	Compact<T::As>: Decode,
{}

fn _foo<T: HasCompact>() {}

fn bar<T>() { _foo::<T>() }

// The last line trigger the following error without span:
/*
error[E0275]: overflow evaluating the requirement `Compact<_>: Decode`
  |
  = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`playground`)
  = note: required because of the requirements on the impl of `Decode` for `Compact<_>`
  = note: 126 redundant requirements hidden
  = note: required because of the requirements on the impl of `Decode` for `Compact<_>`
*/

fn main() {}

I expected to see this happen: have a reference to what trigger the error, i.e. this call _foo::<T>()

Instead, this happened: a not very helpful error message:

error[E0275]: overflow evaluating the requirement `Compact<_>: Decode`
  |
  = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`playground`)
  = note: required because of the requirements on the impl of `Decode` for `Compact<_>`
  = note: 126 redundant requirements hidden
  = note: required because of the requirements on the impl of `Decode` for `Compact<_>`

Meta

the bug exist on stable, and nightly 2021-02-04

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0
@compiler-errors
Copy link
Member

Output now:

error[[E0277]](https://doc.rust-lang.org/nightly/error-index.html#E0277): the trait bound `Compact<T>: Decode` is not satisfied
  --> src/main.rs:35:22
   |
35 | fn bar<T>() { _foo::<T>() }
   |                      ^ the trait `Decode` is not implemented for `Compact<T>`
   |
   = help: the trait `Decode` is implemented for `Compact<T>`
note: required for `T` to implement `HasCompact`
  --> src/main.rs:22:9
   |
22 | impl<T> HasCompact for T
   |         ^^^^^^^^^^     ^
23 | where
24 |     Compact<T>: Decode,
   |                 ------ unsatisfied trait bound introduced here
note: required by a bound in `_foo`
  --> src/main.rs:33:12
   |
33 | fn _foo<T: HasCompact>() {}
   |            ^^^^^^^^^^ required by this bound in `_foo`

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 C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants