impl From<T> for U triggers infinite recursion via .into() — not detected by unconditional_recursion
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Safe Rust code using impl From for String recursively calls .into() on a fresh E {} instance, leading to a stack overflow at runtime. The compiler does not emit a warning or lint, even though the recursion is unconditional and deterministic. This bypasses the compiler recursion check.
Example:
struct E;
impl E {
fn new() -> Self {
E {
}
}
}
impl From<E> for String {
fn from(value: E) -> Self {
E {}.into()
}
}
fn main() {
let v = String::from(E {});
}
When i run this i get
thread 'main' (6844) has overflowed its stack
I suggest to Emit a warning when From calls .into() on a fresh T without branching.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Rust example and compare its behavior with the existing unconditional_recursion compiler check. Determine how From and .into() calls are analyzed, then define tests showing the warning is emitted for unconditional recursion without incorrectly flagging valid conversions; done means the regression is covered and the diagnostic behavior is agreed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100