diff --git a/build.rs b/build.rs deleted file mode 100644 index b108148..0000000 --- a/build.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::env; -use std::process::Command; -use std::str; - -// The rustc-cfg strings below are *not* public API. Please let us know by -// opening a GitHub issue if your build environment requires some way to enable -// these cfgs other than by executing our build script. -fn main() { - let minor = match rustc_minor_version() { - Some(minor) => minor, - None => return, - }; - - // The $:literal matcher in macro_rules stabilized in 1.32: - // https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#macro-improvements - if minor < 32 { - println!("cargo:rustc-cfg=no_literal_matcher"); - } -} - -fn rustc_minor_version() -> Option { - let rustc = env::var_os("RUSTC")?; - let output = Command::new(rustc).arg("--version").output().ok()?; - let version = str::from_utf8(&output.stdout).ok()?; - let mut pieces = version.split('.'); - if pieces.next() != Some("rustc 1") { - return None; - } - pieces.next()?.parse().ok() -} diff --git a/src/lib.rs b/src/lib.rs index c2589aa..9f44b44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1074,28 +1074,6 @@ macro_rules! quote_token { $crate::__private::push_underscore(&mut $tokens); }; - ($tokens:ident $other:tt) => { - $crate::quote_literal_or_token!($tokens $other); - }; -} - -#[cfg(not(no_literal_matcher))] -#[macro_export] -#[doc(hidden)] -macro_rules! quote_literal_or_token { - ($tokens:ident $literal:literal) => { - $crate::__private::push_literal(&mut $tokens, stringify!($literal)); - }; - - ($tokens:ident $other:tt) => { - $crate::__private::parse(&mut $tokens, stringify!($other)); - }; -} - -#[cfg(no_literal_matcher)] -#[macro_export] -#[doc(hidden)] -macro_rules! quote_literal_or_token { ($tokens:ident $other:tt) => { $crate::__private::parse(&mut $tokens, stringify!($other)); }; @@ -1319,28 +1297,6 @@ macro_rules! quote_token_spanned { $crate::__private::push_underscore_spanned(&mut $tokens, $span); }; - ($tokens:ident $span:ident $other:tt) => { - $crate::quote_literal_or_token_spanned!($tokens $span $other); - }; -} - -#[cfg(not(no_literal_matcher))] -#[macro_export] -#[doc(hidden)] -macro_rules! quote_literal_or_token_spanned { - ($tokens:ident $span:ident $literal:literal) => { - $crate::__private::push_literal_spanned(&mut $tokens, $span, stringify!($literal)); - }; - - ($tokens:ident $span:ident $other:tt) => { - $crate::__private::parse_spanned(&mut $tokens, $span, stringify!($other)); - }; -} - -#[cfg(no_literal_matcher)] -#[macro_export] -#[doc(hidden)] -macro_rules! quote_literal_or_token_spanned { ($tokens:ident $span:ident $other:tt) => { $crate::__private::parse_spanned(&mut $tokens, $span, stringify!($other)); }; diff --git a/src/runtime.rs b/src/runtime.rs index fe5fd04..fc40f39 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -1,6 +1,5 @@ use crate::{IdentFragment, ToTokens, TokenStreamExt}; use std::fmt; -use std::iter; use std::ops::BitOr; pub use proc_macro2::*; @@ -292,34 +291,6 @@ pub fn push_lifetime_spanned(tokens: &mut TokenStream, span: Span, lifetime: &st }); } -pub fn push_literal(tokens: &mut TokenStream, repr: &str) { - // Macro_rules's $literal matcher also matches `true`, `-true`, `false`, - // `-false` which are not considered valid values for a proc_macro::Literal. - if is_boolean_literal(repr) { - parse(tokens, repr); - } else { - let literal = unsafe { Literal::from_str_unchecked(repr) }; - tokens.extend(iter::once(TokenTree::Literal(literal))); - } -} - -pub fn push_literal_spanned(tokens: &mut TokenStream, span: Span, repr: &str) { - if is_boolean_literal(repr) { - parse_spanned(tokens, span, repr); - } else { - let mut literal = unsafe { Literal::from_str_unchecked(repr) }; - literal.set_span(span); - tokens.extend(iter::once(TokenTree::Literal(literal))); - } -} - -fn is_boolean_literal(mut repr: &str) -> bool { - if repr.starts_with('-') { - repr = &repr[1..]; - } - repr.starts_with(&['t', 'f'][..]) -} - macro_rules! push_punct { ($name:ident $spanned:ident $char1:tt) => { pub fn $name(tokens: &mut TokenStream) {