You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While implementing fmt::Display on this enum below, I accidentally used "{}" instead of "{:?}" or "{:#}".
use std::fmt;
#[derive(Debug)]
pub enum Lang {
English
}
impl fmt::Display for Lang {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
}
}
pub fn test_1() {
println!("{}", Lang::English);
}
fn main() {
test_1()
}
This program bails with a fatal runtime error: stack overflow. There's no exception output provided while running w/ RUST_BACKTRACE=1 so it makes it hard to dig into the root cause.
Interestingly, if I remove the custom fmt function the compiler gives a nice explanation of what you need to do here:
error[E0277]: `Lang` doesn't implement `std::fmt::Display`
--> src/main.rs:15:20
|
15 | println!("{}", Lang::English);
| ^^^^^^^^^^^^^ `Lang` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Lang`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: required by `std::fmt::Display::fmt`
My issue here is that it would've been nice for the compiler to warn on the bad string binding pattern in the fmt function (similar to [E0277]).
The text was updated successfully, but these errors were encountered:
Maybe the unconditional recursion lint could catch this if it would inspect entire SCCs of the call graph (currently I think it just catches a function directly calling itself)
While implementing
fmt::Display
on this enum below, I accidentally used "{}" instead of "{:?}" or "{:#}".This program bails with a
fatal runtime error: stack overflow
. There's no exception output provided while running w/ RUST_BACKTRACE=1 so it makes it hard to dig into the root cause.Interestingly, if I remove the custom fmt function the compiler gives a nice explanation of what you need to do here:
My issue here is that it would've been nice for the compiler to warn on the bad string binding pattern in the fmt function (similar to [E0277]).
The text was updated successfully, but these errors were encountered: