Skip to content

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

Description

@Marwes
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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions