Skip to content

No obvious way to format unreadable literals in generated code #4094

Closed
@spease

Description

@spease

The string_cache_codegen crate uses quote to generate macros that consist of only an expression, and that expression in turn can contain a numeric literal. I was working on a patch to allow unreadable literals for that macro to push upstream to string_cache_codegen, but since you can't use attributes on expressions, it's a bit of a nonstarter. I shifted my approach to trying to figure out how to format numbers so as to separate via thousands, but so far I haven't found a way to do that either (save for maybe pulling in a third-party library).

EG: https://github.com/servo/string-cache/blob/435f62926456e5538c9f2a9612f07be1ea456710/string-cache-codegen/lib.rs#L196

The data gets passed to quote here:
https://github.com/servo/string-cache/blob/435f62926456e5538c9f2a9612f07be1ea456710/string-cache-codegen/lib.rs#L258

I'm not quite sure what the correct approach is here, but this seems like a bit of a hangup for certain cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-macrosType: Issues with macros and macro expansiongood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions