Open
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
Metadata
Metadata
Assignees
Labels
Area: Lints (warnings about flaws in source code) such as unused_mut.Category: A feature request, i.e: not implemented / a PR.Call for participation: Hard difficulty. Experience needed to fix: A lot.Lint: unconditional_recursionRelevant to the compiler team, which will review and decide on the PR/issue.