-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Overflow evaluating the requirement [stable/nightly] #89275
Comments
It's worth noting that if you use the turbofish syntax the compiler gives the correct error message:
|
For a little more context, this issue was filed from a discussion on reddit. |
It's possible to trigger this issue with use num_traits as _;
struct Ratio<T>(T);
pub trait Pow {
fn pow(self);
}
impl<'a, T> Pow for &'a Ratio<T>
where
&'a T: Pow,
{
fn pow(self) {
unimplemented!()
}
}
struct Foo;
impl Foo {
fn downcast<W>(&self) -> &W {
todo!()
}
}
struct Other;
fn main() {
let other: &mut Other = Foo.downcast();
} |
I am having a similar issue with |
For info here is a backtrace of the compiler during compilation of this Minimal reproduction (with recursion limit set to 8 for more brevity) Backtrace
I believe we start to go awry at around line 68 - it looks like it's perhaps inferring the wrong return type for the method downcast() (line 71) and recursing from there but I'm fairly new to debugging the compiler and I could be extremely off on my guesswork. I will try running a backtrace on some of the other reproductions of this and see if they're similar |
Version with no dependencies: #![recursion_limit = "5"] // To reduce noise
struct Ratio<T>(T);
pub trait Pow {
fn pow(self) -> Self;
}
impl<'a, T> Pow for &'a Ratio<T>
where
&'a T: Pow,
{
fn pow(self) -> Self {
self
}
}
fn downcast<'a, W: ?Sized>() -> &'a W {
todo!()
}
struct Other;
fn main() {
let other: &mut Other = downcast();
} |
From chatting to some people on the rust Zulip this is happening because the error reporting system is trying to find a valid conversion method to put as a suggestion in the mutability error. It's iterating over every trait implementation in scope to check for a conversion method on &_ so either we need a way to tell the error reporting system not to report new errors if it encounters one or fix which span the error is reported on |
Given the following code snippet:
One would expect the code to error, explaining that the types differ in mutability (we will come back to this in a moment).
However, it instead leaves a long and confusing error:
If you follow the suggestion of increasing the recursion limit each time, it will eventually segfault once you have
#![recursion_limit="2048"]
Furthermore, removing the import of
num-rational
leads to the program erroring as expectedMeta
rustc --version --verbose
:This error exists on stable, too.
Backtrace
The text was updated successfully, but these errors were encountered: