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

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

Open
msrd0 opened this issue Jan 26, 2022 · 2 comments
Open

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

msrd0 opened this issue Jan 26, 2022 · 2 comments

Comments

@msrd0
Copy link

msrd0 commented Jan 26, 2022

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
Copy link

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
Copy link

CGMossa commented Mar 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants