Skip to content

Commit

Permalink
Move modules outside the proc macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Apr 15, 2019
1 parent afeda72 commit baebf79
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/librustc_macros/src/symbols.rs
Expand Up @@ -129,37 +129,27 @@ pub fn symbols(input: TokenStream) -> TokenStream {
}

TokenStream::from(quote! {
#[allow(non_upper_case_globals)]
pub mod keywords {
use super::{Symbol, Ident};
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Keyword {
ident: Ident,
}
impl Keyword {
#[inline] pub fn ident(self) -> Ident { self.ident }
#[inline] pub fn name(self) -> Symbol { self.ident.name }
}

#keyword_stream

impl std::str::FromStr for Keyword {
type Err = ();

fn from_str(s: &str) -> Result<Self, ()> {
match s {
#from_str_stream
_ => Err(()),
macro_rules! keywords {
() => {
#keyword_stream

impl std::str::FromStr for Keyword {
type Err = ();

fn from_str(s: &str) -> Result<Self, ()> {
match s {
#from_str_stream
_ => Err(()),
}
}
}
}
}

#[allow(non_upper_case_globals)]
pub mod symbols {
use super::Symbol;

#symbols_stream
macro_rules! symbols {
() => {
#symbols_stream
}
}

impl Interner {
Expand Down
28 changes: 28 additions & 0 deletions src/libsyntax_pos/symbol.rs
Expand Up @@ -406,6 +406,34 @@ impl Interner {
}
}

pub mod keywords {
use super::{Symbol, Ident};

#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Keyword {
ident: Ident,
}

impl Keyword {
#[inline]
pub fn ident(self) -> Ident {
self.ident
}

#[inline]
pub fn name(self) -> Symbol {
self.ident.name
}
}

keywords!();
}

pub mod symbols {
use super::Symbol;
symbols!();
}

impl Symbol {
fn is_used_keyword_2018(self) -> bool {
self == keywords::Dyn.name()
Expand Down

0 comments on commit baebf79

Please sign in to comment.