Missed unconditional recursion warning in Default trait implementation. #83534
Labels
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Uh oh!
There was an error while loading. Please reload this page.
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=97f86e28bd7cd07f59f1507f35a9c7a3
The current output is:
Ideally the output should look like:
The above code should produce a warning because it is impossible for
Foo::default()
to return without recursing. This likely occurs because the compiler is conservative when it comes to function calls (ex: it's possible that1.0f32.floor()
could panic and hence never return) but this should still be rejected because any path that actually would return would require unconditional recursion.Note that this does not occur if
x
doesn't make a function or method call. For example, this code properly warns about unconditional recursion.I ran into this accidentally when implementing default.
The text was updated successfully, but these errors were encountered: