Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error should be raised for bad implementations of Display in an unit struct context #68968

Closed
c410-f3r opened this issue Feb 8, 2020 · 1 comment

Comments

@c410-f3r
Copy link
Contributor

c410-f3r commented Feb 8, 2020

The following overflows the stack:

use core::fmt;

struct Foo;

impl fmt::Display for Foo {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self)
    }
}

fn main() {
    println!("{}", Foo);
}
@jonas-schievink
Copy link
Contributor

The first one shows

error[E0277]: `fn(i32) -> Foo {Foo}` doesn't implement `std::fmt::Display`

because you're passing the type constructor function, not an instance of Foo. Change it to Foo(123) and it also overflows the stack.

The unconditional recursion lint not triggering on Display impls is a well known issue tracked (primarily) by #57965, so closing in favor of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants