-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.L-unconditional_recursionLint: unconditional_recursionLint: unconditional_recursionT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
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 stackI suggest to Emit a warning when From calls .into() on a fresh T without branching.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.L-unconditional_recursionLint: unconditional_recursionLint: unconditional_recursionT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.