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

$crate is not a valid identifier inside paste::item! #3

Closed
softprops opened this issue Nov 3, 2018 · 3 comments
Closed

$crate is not a valid identifier inside paste::item! #3

softprops opened this issue Nov 3, 2018 · 3 comments

Comments

@softprops
Copy link

demo reproduction here https://github.com/dtolnay/paste/pull/2/files

I found that Im not able to refer to a crate local macro inside a paste::item! block, that is the ability to express $crate::foo! which is required to enable rust 2018 style imports ( aka ditching #[macro_use].

The specific context is here where I'm using paste to generate idents which are inputs for another crate local macro

@dtolnay
Copy link
Owner

dtolnay commented Nov 3, 2018

This looks like a rustc bug because I can reproduce it without any libraries.

repro/src/lib.rs

extern crate proc_macro;
use self::proc_macro::TokenStream;

#[proc_macro]
pub fn repro(input: TokenStream) -> TokenStream {
    input.into_iter().next();
    unimplemented!()
}

testing/src/lib.rs

macro_rules! m {
    () => {
        repro::repro!($crate);
    };
}

m!();
error: proc macro panicked                                                                                                     
 --> src/main.rs:3:9                                                                                                           
  |                                                                                                                            
3 |         repro::repro!($crate);                                                                                             
  |         ^^^^^^^^^^^^^^^^^^^^^^                                                                                             
...                                                                                                                            
7 | m!();                                                                                                                      
  | ----- in this macro invocation                                                                                             
  |                                                                                                                            
  = help: message: `"$crate"` is not a valid identifier

@dtolnay
Copy link
Owner

dtolnay commented Nov 3, 2018

Moved upstream: rust-lang/rust#55640.

@dtolnay dtolnay closed this as completed Nov 3, 2018
@softprops
Copy link
Author

Thanks @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

2 participants