Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Paste sometimes produces keywords #74

Open
simon-bourne opened this issue Jan 12, 2022 · 2 comments
Open

Paste sometimes produces keywords #74

simon-bourne opened this issue Jan 12, 2022 · 2 comments

Comments

@simon-bourne
Copy link

simon-bourne commented Jan 12, 2022

Paste will produce a keyword instead of an identifier in some cases:

use paste::paste;

macro_rules! empty_items{
    ($name:ident $(- $name_tail:ident)*) => { paste!{
        struct [< $name:camel $( $name_tail)* >];

        fn [< $name:snake $( _ $name_tail:snake)* >]() {}
    }}
}

empty_items!(r#loop); // Error: expected identifier, found keyword `loop`
empty_items!(se-lf); // Error: expected identifier, found keyword `Self`
empty_items!(Loop); // Error: expected identifier, found keyword `loop`
empty_items!(r#loop-xyz); // Ok

Note that fixing this would be a breaking change as currently paste could be (ab)used to remove the r# from raw idents (say, for stringify!).

Maybe it's also worth thinking about whether, for example, paste!{ [< loop >] } should produce a raw identifier, rather than a keyword.

@IridiumXOR
Copy link

IridiumXOR commented Dec 15, 2022

I have a similar problem with . and ::
How can I join the identifier $self to attribute to obtain $self.attribute? Becuase . is interpreted as special character not as a single char of a string

@FlorianUekermann
Copy link

Maybe it's also worth thinking about whether, for example, paste!{ [< loop >] } should produce a raw identifier, rather than a keyword.

Maybe paste! should always produce raw identifiers or there should be an alternative of [< use >] that does, like {< use >} or [< r# use >].

The issue seems really hard to work around atm. Any chance this can be implemented soonish @dtolnay ?

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

No branches or pull requests

3 participants