-
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
Infinite recursion is not catched by the compiler. #70727
Comments
Thanks for the report! Very slightly trimmed test case: #![deny(unconditional_recursion)]
struct Object;
trait ToObject {
fn to_object(&self) -> &Object;
}
impl ToObject for Object {
fn to_object(&self) -> &Object {
self
}
}
impl<T: ToObject> ObjectOps for T {}
trait ObjectOps : ToObject {
fn foo(&self) -> f32 {
self.to_object().foo()
}
}
fn main() {
let x = Object;
println!("{}", x.foo());
} The (false?) negative for #![deny(unconditional_recursion)]
fn bar() {
foo();
}
fn foo() {
bar();
}
fn main() {
foo();
} ie, when the cycle in the callgraph is formed with at least one other function. This is because the lint currently only fires if a function directly calls itself, eg: fn foo() {
foo();
} Relevant comment here: rust/src/librustc_mir_build/lints.rs Lines 29 to 37 in 548afdb
|
Part of #57965 |
Is this the same issue or should I open an extra issue? struct Floaty {}
impl From<f64> for Floaty {
fn from(value: f64) -> Floaty {
value.into()
}
}
fn main() {
let _: Floaty = 1.0.into();
} This does not generate any recursion warnings. On musl any recursion segfaults, which I reported here: #75667. The above was my original case, util I realized that it segfaults for any recursions. |
@Etherealist Yeah, same issue |
Maybe this is also same issue:
Maybe it is calling recursively to Display::fmt but the compiler does not detect it is calling to itself when it is a trait. Edit: I see now #45838, maybe this is like that other issue more than like this issue. |
Hi, consider this code:
It works fine. Let's rename
foo
tofoo2
next to the comment "RENAME HERE". What happens is that this code has infinite recursion now andrustc
doesn't report any error nor warning despite the usage of#![deny(unconditional_recursion)]
.This is a serious problem, as a simple refactoring can cause something like that and it is very, very hard to debug, especially on WASM platform, where infinite recursion can just return a random number (it is UB). This problem could be solvable if I was able to write somehow
MAGIC::Object::foo(self.to_object())
instead ofself.to_object().foo()
but in such a way, that the methods fromObjectOps
would not be visible inMAGIC::Object
. Currently, when refactoring such code we can get infinite recursion and spend hours debugging it :(The text was updated successfully, but these errors were encountered: