-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.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.
Description
It's possible to write a impl of fmt::Display which compiles successfully and produces a stack overflow.
A minimal repro is available here: https://play.rust-lang.org/?gist=fb115e1e625e1b8038cdd13c5f9cdbb8&version=stable
The code is here for completeness of the bug report:
use std::fmt;
fn main() {
println!("Hello, world!");
let test = Test::Alpha;
println!("Preparing to stack overflow");
let test_string = test.to_string();
println!("test string: {}", test_string);
}
pub enum Test {
Alpha,
Bravo,
}
impl fmt::Display for Test {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string())
}
}
I would expect an error at compile time
Instead the error occurs at runtime as a stack overflow.
Meta
rustc 1.21.0 (3b72af97e 2017-10-09)
binary: rustc
commit-hash: 3b72af97e42989b2fe104d8edbaee123cdf7c58f
commit-date: 2017-10-09
host: x86_64-apple-darwin
release: 1.21.0
LLVM version: 4.0
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Abort trap: 6
demurgos, jonas-schievink, Rotwang, jufajardini, let4be and 2 more
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.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.