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

DebugMap::finish panics if a value returns fmt::Error #65231

Closed
Marwes opened this issue Oct 9, 2019 · 2 comments · Fixed by #65237
Closed

DebugMap::finish panics if a value returns fmt::Error #65231

Marwes opened this issue Oct 9, 2019 · 2 comments · Fixed by #65237
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Marwes
Copy link
Contributor

Marwes commented Oct 9, 2019

use std::fmt;

struct ErrorFmt;

impl fmt::Debug for ErrorFmt {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        Err(fmt::Error)
    }
}

struct A {
    field: ErrorFmt,
}

impl fmt::Debug for A {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_map()
            .entry(&"field", &ErrorFmt)
            .finish()
    }
}

fn main() {
    println!("{:?}", A { field: ErrorFmt });
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4376349fa408130a65c262873bf24055

thread 'main' panicked at 'attempted to finish a map with a partial entry', src/libcore/fmt/builders.rs:924:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

I think the assert should just be removed so that the error gets propagated up?

@Marwes Marwes changed the title DebugMap::finish panics if a value returns fmt::Eror DebugMap::finish panics if a value returns fmt::Error Oct 9, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Oct 9, 2019
@Centril
Copy link
Contributor

Centril commented Oct 9, 2019

cc @KodrAus

@KodrAus
Copy link
Contributor

KodrAus commented Oct 9, 2019

Ah we could probably shift those assertions so they're only checked so long as there isn't an error captured (by moving them within the and_then call inside DebugMap). They don't make any sense if you're already short-circuiting formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants