Skip to content

Dependence on fmt::Debug #296

Description

@kornelski

I'm proposing an option to disable fmt::Debug, mainly to reduce executable sizes, and to thoroughly strip symbol names from executables.

When testing it, it quickly became apparent that thiserror uses fmt::Debug, and this is a common pattern in proc macros.

impl ToTokens for Trait {
    fn to_tokens(&self, tokens: &mut TokenStream) {
        let trait_name = format_ident!("{}", format!("{:?}", self));
        tokens.extend(quote!(::core::fmt::#trait_name));
    }
}

I wanted to check how you feel about an option "breaking" fmt::Debug. Shall fmt::Debug be guaranteed to work in proc-macros? Would you be okay changing the implementation to use something else to stringify enums? (strum's Display, or manual match … => "…"). I'm also proposing to add #[cfg(debug_fmt_detail = "full")] to let crates use fmt::Debug when it's on, and fall back to something else when it's a no-op.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions