Closed
Description
As a mentor on exercism.io I came across the following code:
impl Display for Clock {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}", self.to_string())
}
}
This causes a stack overflow: The reason for that being that to_string is automatically implemented by the Display trait - which generates a loop. At least that is my explaination.
Is there a way for the compiler to catch mistakes like this? This is actually the first time i really saw someone generate a runtime error with safe rust (except for panics of course).