I found myself today writing some stupid code. Once I figured out what I'd done, I was surprised that rustc didn't at least warn me about how dumb I was being. MyStruct had some other traits that it implemented that had similar methods, but I didn't pay enough attention to thinking about how Rust would figure out what method it needs to call, so I effectively wrote the following:
brendondaugherty@brendons-laptop clippy_test % rustc --version
rustc 1.71.0 (8ede3aae2 2023-07-12)
brendondaugherty@brendons-laptop clippy_test % rustup default
stable-aarch64-apple-darwin (default)
brendondaugherty@brendons-laptop clippy_test % cargo build
warning: function cannot return without recursing
--> src/main.rs:18:5
|
18 | fn my_sync_method(&self) {
| ^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
19 | self.my_sync_method()
| --------------------- recursive call site
|
= help: a `loop` may express intention better if this is on purpose
= note: `#[warn(unconditional_recursion)]` on by default
warning: function cannot return without recursing
--> src/main.rs:27:1
|
27 | fn i_obviously_infinite_loop() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
28 | i_obviously_infinite_loop()
| --------------------------- recursive call site
|
= help: a `loop` may express intention better if this is on purpose
warning: function `i_obviously_infinite_loop` is never used
--> src/main.rs:27:4
|
27 | fn i_obviously_infinite_loop() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `clippy_test` (bin "clippy_test") generated 3 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
I realize that once the macro is expanded, this code looks fairly different, and thus rustc isn't able to tell that it's unconditional_recursion. Would it be possible to maintain that we still catch unconditional recursion in the same way?
I found myself today writing some stupid code. Once I figured out what I'd done, I was surprised that rustc didn't at least warn me about how dumb I was being.
MyStruct
had some other traits that it implemented that had similar methods, but I didn't pay enough attention to thinking about how Rust would figure out what method it needs to call, so I effectively wrote the following:This failed pretty poorly and I ended up with some sweet sweet stack overflows.
Because of this, I was curious if Rust would catch the synchronous versions / non-trait versions, and yay! It did!
I realize that once the macro is expanded, this code looks fairly different, and thus rustc isn't able to tell that it's
unconditional_recursion
. Would it be possible to maintain that we still catch unconditional recursion in the same way?To be honest, I don't really understand why rustc doesn't see this as unconditional_recursion.
Let me know if I should file this instead on
rustc
itself, (but I thought I would start here) or if you think it's just not worth it!