-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Rust stable, fatal runtime error: stack overflow, PartialEq #57299
Comments
The self==other will call back into the same impl, which is unbounded recursion that then overflows the stack |
"The self==other will call back into the same impl, which is unbounded recursion that then overflows the stack" Perhaps, but 'RLS' cannot find a recursion in this case |
Empty.. |
|
CC #45838 |
I have the same problem.
Minimal repro: #![allow(dead_code, unused_mut)]
fn main() {
let container_1 = Container::new(123);
let mut container_2 = Container::new(123);
container_2.set(234);
println!("equal: {}", container_1 == container_2);
}
#[derive(Debug)]
pub struct Container<T: PartialEq> {
old: T,
new: Option<T>,
}
impl<T: PartialEq> Container<T> {
pub fn new(value: T) -> Self {
Self {
old: value,
new: None,
}
}
pub fn set(&mut self, value: T) {
self.new = Some(value);
}
}
impl<T: PartialEq> PartialEq for Container<T> {
fn eq(&self, other: &Self) -> bool {
// Warning: "function cannot return without recursing".
// *self == *other
// No warning; just a stack overflow at runtime!
&*self == &*other
// My workaround.
// self.new
// .as_ref()
// .unwrap_or(&self.old)
// .eq(other.new.as_ref().unwrap_or(&other.old))
}
} |
Error
Rust Version
Code
Run
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5bacc9a73f0ae7a38100da9d196b08d0
The text was updated successfully, but these errors were encountered: