dtolnay / quote

Rust quasi-quoting
Apache License 2.0
1.32k stars 90 forks source link

format_ident! does not support spans with capturing format strings #206

Open msrd0 opened 2 years ago

msrd0 commented 2 years ago

format_ident! seems to support the new capturing format strings introduced in Rust 1.58 on first glance. However, format_ident!("{name}") with a captured variable name: Ident produces an Ident with Span::call_site(), whereas format_ident!("{}", name) produces an Ident that keeps the span of name.

k9withabone commented 8 months ago

This behavior really should be documented. As someone who started learning Rust at the beginning of 2023, I use the "{name}" syntax for format strings by default and expected format_ident! to work similar to every other format macro. I only figured out that the described behavior occurs when I was trying to use format_ident! with a syn::Member and the compiler was complaining that syn::Member doesn't implement Display.

CGMossa commented 7 months ago

Maybe related indirectly: format_ident!("{}", id) would drop r#, but format_ident!("{id}") won't strip off r#. Can this be remedied somehow?