aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA6
-rw-r--r--build.rs4
-rw-r--r--src/fallback.rs134
-rw-r--r--src/lib.rs83
-rw-r--r--src/parse.rs6
-rw-r--r--src/wrapper.rs76
-rw-r--r--tests/test.rs35
10 files changed, 212 insertions, 138 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index c2df147..42f9804 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
{
"git": {
- "sha1": "124cb2e77a83a54ec7fa9df9df9fc412b56c5410"
+ "sha1": "77c846d5907f32d1af5ee5631884f55838fc41a9"
}
}
diff --git a/Cargo.toml b/Cargo.toml
index 78e8bd5..fb1f84a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "proc-macro2"
-version = "1.0.17"
+version = "1.0.18"
authors = ["Alex Crichton <alex@alexcrichton.com>", "David Tolnay <dtolnay@gmail.com>"]
description = "A substitute implementation of the compiler's `proc_macro` API to decouple\ntoken-based libraries from the procedural macro use case.\n"
documentation = "https://docs.rs/proc-macro2"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index d09d858..ecbd375 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "proc-macro2"
-version = "1.0.17" # remember to update html_root_url
+version = "1.0.18" # remember to update html_root_url
authors = ["Alex Crichton <alex@alexcrichton.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT OR Apache-2.0"
readme = "README.md"
diff --git a/METADATA b/METADATA
index 9ac8e0b..35baf08 100644
--- a/METADATA
+++ b/METADATA
@@ -9,11 +9,11 @@ third_party {
type: GIT
value: "https://github.com/alexcrichton/proc-macro2"
}
- version: "1.0.17"
+ version: "1.0.18"
license_type: NOTICE
last_upgrade_date {
year: 2020
- month: 5
- day: 27
+ month: 6
+ day: 1
}
}
diff --git a/build.rs b/build.rs
index 89e2ab3..153e13f 100644
--- a/build.rs
+++ b/build.rs
@@ -61,6 +61,10 @@ fn main() {
println!("cargo:rustc-cfg=span_locations");
}
+ if version.minor < 39 {
+ println!("cargo:rustc-cfg=no_bind_by_move_pattern_guard");
+ }
+
if version.minor >= 45 {
println!("cargo:rustc-cfg=hygiene");
}
diff --git a/src/fallback.rs b/src/fallback.rs
index b1cc376..31d244b 100644
--- a/src/fallback.rs
+++ b/src/fallback.rs
@@ -4,8 +4,8 @@ use crate::{Delimiter, Spacing, TokenTree};
use std::cell::RefCell;
#[cfg(span_locations)]
use std::cmp;
-use std::fmt;
-use std::iter;
+use std::fmt::{self, Debug, Display};
+use std::iter::FromIterator;
use std::mem;
use std::ops::RangeBounds;
#[cfg(procmacro2_semver_exempt)]
@@ -49,6 +49,49 @@ impl TokenStream {
fn take_inner(&mut self) -> Vec<TokenTree> {
mem::replace(&mut self.inner, Vec::new())
}
+
+ fn push_token(&mut self, token: TokenTree) {
+ // https://github.com/alexcrichton/proc-macro2/issues/235
+ match token {
+ #[cfg(not(no_bind_by_move_pattern_guard))]
+ TokenTree::Literal(crate::Literal {
+ #[cfg(wrap_proc_macro)]
+ inner: crate::imp::Literal::Fallback(literal),
+ #[cfg(not(wrap_proc_macro))]
+ inner: literal,
+ ..
+ }) if literal.text.starts_with('-') => {
+ push_negative_literal(self, literal);
+ }
+ #[cfg(no_bind_by_move_pattern_guard)]
+ TokenTree::Literal(crate::Literal {
+ #[cfg(wrap_proc_macro)]
+ inner: crate::imp::Literal::Fallback(literal),
+ #[cfg(not(wrap_proc_macro))]
+ inner: literal,
+ ..
+ }) => {
+ if literal.text.starts_with('-') {
+ push_negative_literal(self, literal);
+ } else {
+ self.inner
+ .push(TokenTree::Literal(crate::Literal::_new_stable(literal)));
+ }
+ }
+ _ => self.inner.push(token),
+ }
+
+ #[cold]
+ fn push_negative_literal(stream: &mut TokenStream, mut literal: Literal) {
+ literal.text.remove(0);
+ let mut punct = crate::Punct::new('-', Spacing::Alone);
+ punct.set_span(crate::Span::_new_stable(literal.span));
+ stream.inner.push(TokenTree::Punct(punct));
+ stream
+ .inner
+ .push(TokenTree::Literal(crate::Literal::_new_stable(literal)));
+ }
+ }
}
// Nonrecursive to prevent stack overflow.
@@ -105,7 +148,7 @@ impl FromStr for TokenStream {
}
}
-impl fmt::Display for TokenStream {
+impl Display for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut joint = false;
for (i, tt) in self.inner.iter().enumerate() {
@@ -143,7 +186,7 @@ impl fmt::Display for TokenStream {
}
}
-impl fmt::Debug for TokenStream {
+impl Debug for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("TokenStream ")?;
f.debug_list().entries(self.clone()).finish()
@@ -172,27 +215,25 @@ impl From<TokenStream> for proc_macro::TokenStream {
impl From<TokenTree> for TokenStream {
fn from(tree: TokenTree) -> TokenStream {
- TokenStream { inner: vec![tree] }
+ let mut stream = TokenStream::new();
+ stream.push_token(tree);
+ stream
}
}
-impl iter::FromIterator<TokenTree> for TokenStream {
- fn from_iter<I: IntoIterator<Item = TokenTree>>(streams: I) -> Self {
- let mut v = Vec::new();
-
- for token in streams.into_iter() {
- v.push(token);
- }
-
- TokenStream { inner: v }
+impl FromIterator<TokenTree> for TokenStream {
+ fn from_iter<I: IntoIterator<Item = TokenTree>>(tokens: I) -> Self {
+ let mut stream = TokenStream::new();
+ stream.extend(tokens);
+ stream
}
}
-impl iter::FromIterator<TokenStream> for TokenStream {
+impl FromIterator<TokenStream> for TokenStream {
fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self {
let mut v = Vec::new();
- for mut stream in streams.into_iter() {
+ for mut stream in streams {
v.extend(stream.take_inner());
}
@@ -201,15 +242,14 @@ impl iter::FromIterator<TokenStream> for TokenStream {
}
impl Extend<TokenTree> for TokenStream {
- fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, streams: I) {
- self.inner.extend(streams);
+ fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, tokens: I) {
+ tokens.into_iter().for_each(|token| self.push_token(token));
}
}
impl Extend<TokenStream> for TokenStream {
fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I) {
- self.inner
- .extend(streams.into_iter().flat_map(|stream| stream));
+ self.inner.extend(streams.into_iter().flatten());
}
}
@@ -241,7 +281,7 @@ impl SourceFile {
}
}
-impl fmt::Debug for SourceFile {
+impl Debug for SourceFile {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("SourceFile")
.field("path", &self.path())
@@ -486,18 +526,25 @@ impl Span {
}
}
-impl fmt::Debug for Span {
+impl Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- #[cfg(procmacro2_semver_exempt)]
+ #[cfg(span_locations)]
return write!(f, "bytes({}..{})", self.lo, self.hi);
- #[cfg(not(procmacro2_semver_exempt))]
+ #[cfg(not(span_locations))]
write!(f, "Span")
}
}
pub(crate) fn debug_span_field_if_nontrivial(debug: &mut fmt::DebugStruct, span: Span) {
- if cfg!(procmacro2_semver_exempt) {
+ #[cfg(span_locations)]
+ {
+ if span.lo == 0 && span.hi == 0 {
+ return;
+ }
+ }
+
+ if cfg!(span_locations) {
debug.field("span", &span);
}
}
@@ -543,7 +590,7 @@ impl Group {
}
}
-impl fmt::Display for Group {
+impl Display for Group {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (left, right) = match self.delimiter {
Delimiter::Parenthesis => ("(", ")"),
@@ -553,20 +600,19 @@ impl fmt::Display for Group {
};
f.write_str(left)?;
- self.stream.fmt(f)?;
+ Display::fmt(&self.stream, f)?;
f.write_str(right)?;
Ok(())
}
}
-impl fmt::Debug for Group {
+impl Debug for Group {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let mut debug = fmt.debug_struct("Group");
debug.field("delimiter", &self.delimiter);
debug.field("stream", &self.stream);
- #[cfg(procmacro2_semver_exempt)]
- debug.field("span", &self.span);
+ debug_span_field_if_nontrivial(&mut debug, self.span);
debug.finish()
}
}
@@ -670,18 +716,18 @@ where
}
}
-impl fmt::Display for Ident {
+impl Display for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.raw {
- "r#".fmt(f)?;
+ f.write_str("r#")?;
}
- self.sym.fmt(f)
+ Display::fmt(&self.sym, f)
}
}
-impl fmt::Debug for Ident {
+impl Debug for Ident {
// Ident(proc_macro), Ident(r#union)
- #[cfg(not(procmacro2_semver_exempt))]
+ #[cfg(not(span_locations))]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut debug = f.debug_tuple("Ident");
debug.field(&format_args!("{}", self));
@@ -692,11 +738,11 @@ impl fmt::Debug for Ident {
// sym: proc_macro,
// span: bytes(128..138)
// }
- #[cfg(procmacro2_semver_exempt)]
+ #[cfg(span_locations)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut debug = f.debug_struct("Ident");
debug.field("sym", &format_args!("{}", self));
- debug.field("span", &self.span);
+ debug_span_field_if_nontrivial(&mut debug, self.span);
debug.finish()
}
}
@@ -766,7 +812,7 @@ impl Literal {
pub fn f32_unsuffixed(f: f32) -> Literal {
let mut s = f.to_string();
- if !s.contains(".") {
+ if !s.contains('.') {
s.push_str(".0");
}
Literal::_new(s)
@@ -774,7 +820,7 @@ impl Literal {
pub fn f64_unsuffixed(f: f64) -> Literal {
let mut s = f.to_string();
- if !s.contains(".") {
+ if !s.contains('.') {
s.push_str(".0");
}
Literal::_new(s)
@@ -811,6 +857,7 @@ impl Literal {
pub fn byte_string(bytes: &[u8]) -> Literal {
let mut escaped = "b\"".to_string();
for b in bytes {
+ #[allow(clippy::match_overlapping_arm)]
match *b {
b'\0' => escaped.push_str(r"\0"),
b'\t' => escaped.push_str(r"\t"),
@@ -839,18 +886,17 @@ impl Literal {
}
}
-impl fmt::Display for Literal {
+impl Display for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.text.fmt(f)
+ Display::fmt(&self.text, f)
}
}
-impl fmt::Debug for Literal {
+impl Debug for Literal {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let mut debug = fmt.debug_struct("Literal");
debug.field("lit", &format_args!("{}", self.text));
- #[cfg(procmacro2_semver_exempt)]
- debug.field("span", &self.span);
+ debug_span_field_if_nontrivial(&mut debug, self.span);
debug.finish()
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 25c0903..6a9b680 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -78,15 +78,16 @@
//! a different thread.
// Proc-macro2 types in rustdoc of other crates get linked to here.
-#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.17")]
+#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.18")]
#![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))]
#![cfg_attr(super_unstable, feature(proc_macro_raw_ident, proc_macro_def_site))]
+#![allow(clippy::needless_doctest_main)]
#[cfg(use_proc_macro)]
extern crate proc_macro;
use std::cmp::Ordering;
-use std::fmt;
+use std::fmt::{self, Debug, Display};
use std::hash::{Hash, Hasher};
use std::iter::FromIterator;
use std::marker;
@@ -234,22 +235,22 @@ impl FromIterator<TokenStream> for TokenStream {
/// convertible back into the same token stream (modulo spans), except for
/// possibly `TokenTree::Group`s with `Delimiter::None` delimiters and negative
/// numeric literals.
-impl fmt::Display for TokenStream {
+impl Display for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Display::fmt(&self.inner, f)
}
}
/// Prints token in a form convenient for debugging.
-impl fmt::Debug for TokenStream {
+impl Debug for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Debug::fmt(&self.inner, f)
}
}
-impl fmt::Debug for LexError {
+impl Debug for LexError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Debug::fmt(&self.inner, f)
}
}
@@ -297,9 +298,9 @@ impl SourceFile {
}
#[cfg(procmacro2_semver_exempt)]
-impl fmt::Debug for SourceFile {
+impl Debug for SourceFile {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Debug::fmt(&self.inner, f)
}
}
@@ -320,7 +321,9 @@ pub struct LineColumn {
#[cfg(span_locations)]
impl Ord for LineColumn {
fn cmp(&self, other: &Self) -> Ordering {
- self.line.cmp(&other.line).then(self.column.cmp(&other.column))
+ self.line
+ .cmp(&other.line)
+ .then(self.column.cmp(&other.column))
}
}
@@ -466,9 +469,9 @@ impl Span {
}
/// Prints a span in a form convenient for debugging.
-impl fmt::Debug for Span {
+impl Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Debug::fmt(&self.inner, f)
}
}
@@ -540,32 +543,32 @@ impl From<Literal> for TokenTree {
/// convertible back into the same token tree (modulo spans), except for
/// possibly `TokenTree::Group`s with `Delimiter::None` delimiters and negative
/// numeric literals.
-impl fmt::Display for TokenTree {
+impl Display for TokenTree {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- TokenTree::Group(t) => t.fmt(f),
- TokenTree::Ident(t) => t.fmt(f),
- TokenTree::Punct(t) => t.fmt(f),
- TokenTree::Literal(t) => t.fmt(f),
+ TokenTree::Group(t) => Display::fmt(t, f),
+ TokenTree::Ident(t) => Display::fmt(t, f),
+ TokenTree::Punct(t) => Display::fmt(t, f),
+ TokenTree::Literal(t) => Display::fmt(t, f),
}
}
}
/// Prints token tree in a form convenient for debugging.
-impl fmt::Debug for TokenTree {
+impl Debug for TokenTree {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Each of these has the name in the struct type in the derived debug,
// so don't bother with an extra layer of indirection
match self {
- TokenTree::Group(t) => t.fmt(f),
+ TokenTree::Group(t) => Debug::fmt(t, f),
TokenTree::Ident(t) => {
let mut debug = f.debug_struct("Ident");
debug.field("sym", &format_args!("{}", t));
imp::debug_span_field_if_nontrivial(&mut debug, t.span().inner);
debug.finish()
}
- TokenTree::Punct(t) => t.fmt(f),
- TokenTree::Literal(t) => t.fmt(f),
+ TokenTree::Punct(t) => Debug::fmt(t, f),
+ TokenTree::Literal(t) => Debug::fmt(t, f),
}
}
}
@@ -678,15 +681,15 @@ impl Group {
/// Prints the group as a string that should be losslessly convertible back
/// into the same group (modulo spans), except for possibly `TokenTree::Group`s
/// with `Delimiter::None` delimiters.
-impl fmt::Display for Group {
+impl Display for Group {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- fmt::Display::fmt(&self.inner, formatter)
+ Display::fmt(&self.inner, formatter)
}
}
-impl fmt::Debug for Group {
+impl Debug for Group {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- fmt::Debug::fmt(&self.inner, formatter)
+ Debug::fmt(&self.inner, formatter)
}
}
@@ -757,13 +760,13 @@ impl Punct {
/// Prints the punctuation character as a string that should be losslessly
/// convertible back into the same character.
-impl fmt::Display for Punct {
+impl Display for Punct {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.op.fmt(f)
+ Display::fmt(&self.op, f)
}
}
-impl fmt::Debug for Punct {
+impl Debug for Punct {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let mut debug = fmt.debug_struct("Punct");
debug.field("op", &self.op);
@@ -947,15 +950,15 @@ impl Hash for Ident {
/// Prints the identifier as a string that should be losslessly convertible back
/// into the same identifier.
-impl fmt::Display for Ident {
+impl Display for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Display::fmt(&self.inner, f)
}
}
-impl fmt::Debug for Ident {
+impl Debug for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Debug::fmt(&self.inner, f)
}
}
@@ -1167,22 +1170,22 @@ impl Literal {
}
}
-impl fmt::Debug for Literal {
+impl Debug for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Debug::fmt(&self.inner, f)
}
}
-impl fmt::Display for Literal {
+impl Display for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Display::fmt(&self.inner, f)
}
}
/// Public implementation details for the `TokenStream` type, such as iterators.
pub mod token_stream {
use crate::{imp, TokenTree};
- use std::fmt;
+ use std::fmt::{self, Debug};
use std::marker;
use std::rc::Rc;
@@ -1206,9 +1209,9 @@ pub mod token_stream {
}
}
- impl fmt::Debug for IntoIter {
+ impl Debug for IntoIter {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.inner.fmt(f)
+ Debug::fmt(&self.inner, f)
}
}
diff --git a/src/parse.rs b/src/parse.rs
index 954aff6..f4f8a47 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -768,7 +768,7 @@ fn doc_comment_contents(input: Cursor) -> PResult<(&str, bool)> {
}
let (input, s) = take_until_newline_or_eof(input);
Ok((input, (s, false)))
- } else if input.starts_with("/**") && !input.rest[3..].starts_with("*") {
+ } else if input.starts_with("/**") && !input.rest[3..].starts_with('*') {
let (input, s) = block_comment(input)?;
Ok((input, (&s[3..s.len() - 2], false)))
} else {
@@ -777,9 +777,9 @@ fn doc_comment_contents(input: Cursor) -> PResult<(&str, bool)> {
}
fn take_until_newline_or_eof(input: Cursor) -> (Cursor, &str) {
- let mut chars = input.char_indices();
+ let chars = input.char_indices();
- while let Some((i, ch)) = chars.next() {
+ for (i, ch) in chars {
if ch == '\n' {
return (input.advance(i), &input.rest[..i]);
} else if ch == '\r' && input.rest[i + 1..].starts_with('\n') {
diff --git a/src/wrapper.rs b/src/wrapper.rs
index b6dff27..3e38c54 100644
--- a/src/wrapper.rs
+++ b/src/wrapper.rs
@@ -1,7 +1,7 @@
use crate::detection::inside_proc_macro;
use crate::{fallback, Delimiter, Punct, Spacing, TokenTree};
-use std::fmt;
-use std::iter;
+use std::fmt::{self, Debug, Display};
+use std::iter::FromIterator;
use std::ops::RangeBounds;
use std::panic;
#[cfg(super_unstable)]
@@ -106,11 +106,11 @@ fn proc_macro_parse(src: &str) -> Result<proc_macro::TokenStream, LexError> {
.unwrap_or(Err(LexError::Fallback(fallback::LexError)))
}
-impl fmt::Display for TokenStream {
+impl Display for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- TokenStream::Compiler(tts) => tts.clone().into_token_stream().fmt(f),
- TokenStream::Fallback(tts) => tts.fmt(f),
+ TokenStream::Compiler(tts) => Display::fmt(&tts.clone().into_token_stream(), f),
+ TokenStream::Fallback(tts) => Display::fmt(tts, f),
}
}
}
@@ -164,7 +164,7 @@ impl From<TokenTree> for TokenStream {
}
}
-impl iter::FromIterator<TokenTree> for TokenStream {
+impl FromIterator<TokenTree> for TokenStream {
fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self {
if inside_proc_macro() {
TokenStream::Compiler(DeferredTokenStream::new(
@@ -176,7 +176,7 @@ impl iter::FromIterator<TokenTree> for TokenStream {
}
}
-impl iter::FromIterator<TokenStream> for TokenStream {
+impl FromIterator<TokenStream> for TokenStream {
fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self {
let mut streams = streams.into_iter();
match streams.next() {
@@ -228,11 +228,11 @@ impl Extend<TokenStream> for TokenStream {
}
}
-impl fmt::Debug for TokenStream {
+impl Debug for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- TokenStream::Compiler(tts) => tts.clone().into_token_stream().fmt(f),
- TokenStream::Fallback(tts) => tts.fmt(f),
+ TokenStream::Compiler(tts) => Debug::fmt(&tts.clone().into_token_stream(), f),
+ TokenStream::Fallback(tts) => Debug::fmt(tts, f),
}
}
}
@@ -249,11 +249,11 @@ impl From<fallback::LexError> for LexError {
}
}
-impl fmt::Debug for LexError {
+impl Debug for LexError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- LexError::Compiler(e) => e.fmt(f),
- LexError::Fallback(e) => e.fmt(f),
+ LexError::Compiler(e) => Debug::fmt(e, f),
+ LexError::Fallback(e) => Debug::fmt(e, f),
}
}
}
@@ -310,7 +310,7 @@ impl Iterator for TokenTreeIter {
}
}
-impl fmt::Debug for TokenTreeIter {
+impl Debug for TokenTreeIter {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("TokenTreeIter").finish()
}
@@ -346,11 +346,11 @@ impl SourceFile {
}
#[cfg(super_unstable)]
-impl fmt::Debug for SourceFile {
+impl Debug for SourceFile {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- SourceFile::Compiler(a) => a.fmt(f),
- SourceFile::Fallback(a) => a.fmt(f),
+ SourceFile::Compiler(a) => Debug::fmt(a, f),
+ SourceFile::Fallback(a) => Debug::fmt(a, f),
}
}
}
@@ -513,11 +513,11 @@ impl From<fallback::Span> for Span {
}
}
-impl fmt::Debug for Span {
+impl Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Span::Compiler(s) => s.fmt(f),
- Span::Fallback(s) => s.fmt(f),
+ Span::Compiler(s) => Debug::fmt(s, f),
+ Span::Fallback(s) => Debug::fmt(s, f),
}
}
}
@@ -623,20 +623,20 @@ impl From<fallback::Group> for Group {
}
}
-impl fmt::Display for Group {
+impl Display for Group {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self {
- Group::Compiler(group) => group.fmt(formatter),
- Group::Fallback(group) => group.fmt(formatter),
+ Group::Compiler(group) => Display::fmt(group, formatter),
+ Group::Fallback(group) => Display::fmt(group, formatter),
}
}
}
-impl fmt::Debug for Group {
+impl Debug for Group {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self {
- Group::Compiler(group) => group.fmt(formatter),
- Group::Fallback(group) => group.fmt(formatter),
+ Group::Compiler(group) => Debug::fmt(group, formatter),
+ Group::Fallback(group) => Debug::fmt(group, formatter),
}
}
}
@@ -718,20 +718,20 @@ where
}
}
-impl fmt::Display for Ident {
+impl Display for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Ident::Compiler(t) => t.fmt(f),
- Ident::Fallback(t) => t.fmt(f),
+ Ident::Compiler(t) => Display::fmt(t, f),
+ Ident::Fallback(t) => Display::fmt(t, f),
}
}
}
-impl fmt::Debug for Ident {
+impl Debug for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Ident::Compiler(t) => t.fmt(f),
- Ident::Fallback(t) => t.fmt(f),
+ Ident::Compiler(t) => Debug::fmt(t, f),
+ Ident::Fallback(t) => Debug::fmt(t, f),
}
}
}
@@ -879,20 +879,20 @@ impl From<fallback::Literal> for Literal {
}
}
-impl fmt::Display for Literal {
+impl Display for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Literal::Compiler(t) => t.fmt(f),
- Literal::Fallback(t) => t.fmt(f),
+ Literal::Compiler(t) => Display::fmt(t, f),
+ Literal::Fallback(t) => Display::fmt(t, f),
}
}
}
-impl fmt::Debug for Literal {
+impl Debug for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Literal::Compiler(t) => t.fmt(f),
- Literal::Fallback(t) => t.fmt(f),
+ Literal::Compiler(t) => Debug::fmt(t, f),
+ Literal::Fallback(t) => Debug::fmt(t, f),
}
}
}
diff --git a/tests/test.rs b/tests/test.rs
index a0133f6..8bd6bf9 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -118,6 +118,27 @@ fn literal_suffix() {
}
#[test]
+fn literal_iter_negative() {
+ let negative_literal = Literal::i32_suffixed(-3);
+ let tokens = TokenStream::from(TokenTree::Literal(negative_literal));
+ let mut iter = tokens.into_iter();
+ match iter.next().unwrap() {
+ TokenTree::Punct(punct) => {
+ assert_eq!(punct.as_char(), '-');
+ assert_eq!(punct.spacing(), Spacing::Alone);
+ }
+ unexpected => panic!("unexpected token {:?}", unexpected),
+ }
+ match iter.next().unwrap() {
+ TokenTree::Literal(literal) => {
+ assert_eq!(literal.to_string(), "3i32");
+ }
+ unexpected => panic!("unexpected token {:?}", unexpected),
+ }
+ assert!(iter.next().is_none());
+}
+
+#[test]
fn roundtrip() {
fn roundtrip(p: &str) {
println!("parse: {}", p);
@@ -278,11 +299,11 @@ fn raw_identifier() {
fn test_debug_ident() {
let ident = Ident::new("proc_macro", Span::call_site());
- #[cfg(not(procmacro2_semver_exempt))]
+ #[cfg(not(span_locations))]
let expected = "Ident(proc_macro)";
- #[cfg(procmacro2_semver_exempt)]
- let expected = "Ident { sym: proc_macro, span: bytes(0..0) }";
+ #[cfg(span_locations)]
+ let expected = "Ident { sym: proc_macro }";
assert_eq!(expected, format!("{:?}", ident));
}
@@ -291,7 +312,7 @@ fn test_debug_ident() {
fn test_debug_tokenstream() {
let tts = TokenStream::from_str("[a + 1]").unwrap();
- #[cfg(not(procmacro2_semver_exempt))]
+ #[cfg(not(span_locations))]
let expected = "\
TokenStream [
Group {
@@ -312,7 +333,7 @@ TokenStream [
]\
";
- #[cfg(not(procmacro2_semver_exempt))]
+ #[cfg(not(span_locations))]
let expected_before_trailing_commas = "\
TokenStream [
Group {
@@ -333,7 +354,7 @@ TokenStream [
]\
";
- #[cfg(procmacro2_semver_exempt)]
+ #[cfg(span_locations)]
let expected = "\
TokenStream [
Group {
@@ -358,7 +379,7 @@ TokenStream [
]\
";
- #[cfg(procmacro2_semver_exempt)]
+ #[cfg(span_locations)]
let expected_before_trailing_commas = "\
TokenStream [
Group {