Skip to content

Commit

Permalink
Delete $:literal codepath
Browse files Browse the repository at this point in the history
It turns out this breaks non-builtin literal suffixes, such as in
`quote!(1u256)`. Those match fine against $:tt, but if you match them
against $:literal they eagerly fail the macro expansion without falling
through to the next macro_rules arm.

    error: invalid width `256` for integer literal
     --> repro.rs:4:9
      |
    4 |         1u256
      |         ^^^^^
      |
      = help: valid widths are 8, 16, 32, 64 and 128
  • Loading branch information
dtolnay committed Dec 28, 2021
1 parent b8b6e42 commit f621fe6
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 103 deletions.
30 changes: 0 additions & 30 deletions build.rs

This file was deleted.

44 changes: 0 additions & 44 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
Expand Down Expand Up @@ -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));
};
Expand Down
29 changes: 0 additions & 29 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{IdentFragment, ToTokens, TokenStreamExt};
use std::fmt;
use std::iter;
use std::ops::BitOr;

pub use proc_macro2::*;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f621fe6

Please sign in to comment.