Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dtolnay/proc-macro2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.0.65
Choose a base ref
...
head repository: dtolnay/proc-macro2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.0.66
Choose a head ref

Commits on Jul 16, 2023

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    e4be003 View commit details
  2. Resolve unnested_or_patterns pedantic clippy lint

        warning: unnested or-patterns
           --> src/parse.rs:387:17
            |
        387 | /                 Some((_, 'n')) | Some((_, 'r')) | Some((_, 't')) | Some((_, '\\'))
        388 | |                 | Some((_, '\'')) | Some((_, '"')) | Some((_, '0')) => {}
            | |___________________________________________________________________^
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
        help: nest the patterns
            |
        387 |                 Some((_, 'n' | 'r' | 't' | '\\' | '\'' | '"' | '0')) => {}
            |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        warning: unnested or-patterns
           --> src/parse.rs:392:17
            |
        392 |                 Some((newline, ch @ '\n')) | Some((newline, ch @ '\r')) => {
            |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
        help: nest the patterns
            |
        392 |                 Some((newline, ch @ ('\n' | '\r'))) => {
            |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        warning: unnested or-patterns
           --> src/parse.rs:450:17
            |
        450 | /                 Some((_, b'n')) | Some((_, b'r')) | Some((_, b't')) | Some((_, b'\\'))
        451 | |                 | Some((_, b'0')) | Some((_, b'\'')) | Some((_, b'"')) => {}
            | |______________________________________________________________________^
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
        help: nest the patterns
            |
        450 |                 Some((_, b'n' | b'r' | b't' | b'\\' | b'0' | b'\'' | b'"')) => {}
            |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        warning: unnested or-patterns
           --> src/parse.rs:452:17
            |
        452 |                 Some((newline, b @ b'\n')) | Some((newline, b @ b'\r')) => {
            |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
        help: nest the patterns
            |
        452 |                 Some((newline, b @ (b'\n' | b'\r'))) => {
            |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        warning: unnested or-patterns
           --> src/parse.rs:553:17
            |
        553 | /                 Some((_, 'n')) | Some((_, 'r')) | Some((_, 't')) | Some((_, '\\'))
        554 | |                 | Some((_, '\'')) | Some((_, '"')) => {}
            | |__________________________________________________^
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
        help: nest the patterns
            |
        553 |                 Some((_, 'n' | 'r' | 't' | '\\' | '\'' | '"')) => {}
            |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        warning: unnested or-patterns
           --> src/parse.rs:560:17
            |
        560 |                 Some((newline, ch @ '\n')) | Some((newline, ch @ '\r')) => {
            |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
        help: nest the patterns
            |
        560 |                 Some((newline, ch @ ('\n' | '\r'))) => {
            |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        warning: unnested or-patterns
           --> src/parse.rs:580:13
            |
        580 | /             Some(b'n') | Some(b'r') | Some(b't') | Some(b'\\') | Some(b'0') | Some(b'\'')
        581 | |             | Some(b'"') => true,
            | |________________________^
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
        help: nest the patterns
            |
        580 |             Some(b'n' | b'r' | b't' | b'\\' | b'0' | b'\'' | b'"') => true,
            |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        warning: unnested or-patterns
           --> src/parse.rs:604:13
            |
        604 |             Some('n') | Some('r') | Some('t') | Some('\\') | Some('0') | Some('\'') | Some('"') => {
            |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
        help: nest the patterns
            |
        604 |             Some('n' | 'r' | 't' | '\\' | '0' | '\'' | '"') => {
            |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        warning: unnested or-patterns
           --> src/parse.rs:695:13
            |
        695 | /             Some((_, b @ b' ')) | Some((_, b @ b'\t')) | Some((_, b @ b'\n'))
        696 | |             | Some((_, b @ b'\r')) => {
            | |__________________________________^
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
        help: nest the patterns
            |
        695 |             Some((_, b @ (b' ' | b'\t' | b'\n' | b'\r'))) => {
            |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    dtolnay committed Jul 16, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    8dba582 View commit details
  3. Resolve mem_replace_with_default clippy lint

        warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
          --> src/rcvec.rs:56:13
           |
        56 |             mem::replace(owned, Vec::new())
           |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(owned)`
           |
           = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default
           = note: `-W clippy::mem-replace-with-default` implied by `-W clippy::all`
    dtolnay committed Jul 16, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    54873fd View commit details
  4. Ignore manual_range_contains clippy lint

        warning: manual `RangeInclusive::contains` implementation
           --> src/parse.rs:714:21
            |
        714 |         Some(ch) if ch >= '0' && ch <= '9' => {}
            |                     ^^^^^^^^^^^^^^^^^^^^^^ help: use: `('0'..='9').contains(&ch)`
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
            = note: `-W clippy::manual-range-contains` implied by `-W clippy::all`
    
        warning: manual `RangeInclusive::contains` implementation
           --> src/fallback.rs:772:35
            |
        772 |     if string.bytes().all(|digit| digit >= b'0' && digit <= b'9') {
            |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(b'0'..=b'9').contains(&digit)`
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
    
        warning: manual `RangeInclusive::contains` implementation
           --> src/fallback.rs:948:45
            |
        948 |                         .starts_with(|next| '0' <= next && next <= '7')
            |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `('0'..='7').contains(&next)`
            |
            = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
    dtolnay committed Jul 16, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    7560c99 View commit details
  5. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    5235d37 View commit details
  6. Update to 2021 edition

    dtolnay committed Jul 16, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    238e346 View commit details
  7. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    72fc798 View commit details
  8. Delete rustc minimum version check from build.rs

    Now enforced by `rust-version` in Cargo.toml.
    dtolnay committed Jul 16, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    4b2c896 View commit details
  9. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    673f460 View commit details
  10. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    5b5ec10 View commit details
  11. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    1148346 View commit details
  12. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    0f00381 View commit details
  13. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    467a0b4 View commit details
  14. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    56c04ea View commit details
  15. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    3f96a77 View commit details
  16. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    2d8dd97 View commit details
  17. Inline compiler_literal_from_str

    This function only made sense when compilers older than 1.54 needed to
    use a different implementation.
    dtolnay committed Jul 16, 2023
    Copy the full SHA
    346cc05 View commit details
  18. Copy the full SHA
    00360bc View commit details
  19. Copy the full SHA
    177c700 View commit details
  20. Revert "Fix test failure due to quoting change in str's Debug"

    No longer required as compilers older than 1.56 are not supported.
    
    This reverts commit 51608bb.
    dtolnay committed Jul 16, 2023
    Copy the full SHA
    fc8af0d View commit details
  21. Copy the full SHA
    11d8cab View commit details
  22. Release 1.0.66

    dtolnay committed Jul 16, 2023
    Copy the full SHA
    64b4608 View commit details
Showing with 42 additions and 224 deletions.
  1. +1 −1 .github/workflows/ci.yml
  2. +3 −3 Cargo.toml
  3. +1 −1 README.md
  4. +1 −38 build.rs
  5. +0 −19 src/convert.rs
  6. +2 −18 src/extra.rs
  7. +5 −23 src/fallback.rs
  8. +5 −8 src/lib.rs
  9. +2 −2 src/marker.rs
  10. +12 −19 src/parse.rs
  11. +4 −4 src/rcvec.rs
  12. +3 −68 src/wrapper.rs
  13. +0 −1 tests/marker.rs
  14. +2 −18 tests/test.rs
  15. +1 −1 tests/test_fmt.rs
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rust: [1.31.0, stable, beta]
rust: [1.56.0, stable, beta]
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "proc-macro2"
version = "1.0.65" # remember to update html_root_url
version = "1.0.66" # remember to update html_root_url
authors = ["David Tolnay <dtolnay@gmail.com>", "Alex Crichton <alex@alexcrichton.com>"]
autobenches = false
categories = ["development-tools::procedural-macro-helpers"]
description = "A substitute implementation of the compiler's `proc_macro` API to decouple token-based libraries from the procedural macro use case."
documentation = "https://docs.rs/proc-macro2"
edition = "2018"
edition = "2021"
keywords = ["macros", "syn"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/proc-macro2"
rust-version = "1.31"
rust-version = "1.56"

[package.metadata.docs.rs]
rustc-args = ["--cfg", "procmacro2_semver_exempt"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ proc-macro2 by default.

To opt into the additional APIs available in the most recent nightly compiler,
the `procmacro2_semver_exempt` config flag must be passed to rustc. We will
polyfill those nightly-only APIs back to Rust 1.31.0. As these are unstable APIs
polyfill those nightly-only APIs back to Rust 1.56.0. As these are unstable APIs
that track the nightly compiler, minor versions of proc-macro2 may make breaking
changes to them at any time.

39 changes: 1 addition & 38 deletions build.rs
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
// 1.57+.

use std::env;
use std::process::{self, Command};
use std::process::Command;
use std::str;
use std::u32;

@@ -47,11 +47,6 @@ fn main() {
nightly: false,
});

if version.minor < 31 {
eprintln!("Minimum supported rustc version is 1.31");
process::exit(1);
}

let docs_rs = env::var_os("DOCS_RS").is_some();
let semver_exempt = cfg!(procmacro2_semver_exempt) || docs_rs;
if semver_exempt {
@@ -63,38 +58,6 @@ fn main() {
println!("cargo:rustc-cfg=span_locations");
}

if version.minor < 32 {
println!("cargo:rustc-cfg=no_libprocmacro_unwind_safe");
}

if version.minor < 34 {
println!("cargo:rustc-cfg=no_try_from");
}

if version.minor < 39 {
println!("cargo:rustc-cfg=no_bind_by_move_pattern_guard");
}

if version.minor < 44 {
println!("cargo:rustc-cfg=no_lexerror_display");
}

if version.minor < 45 {
println!("cargo:rustc-cfg=no_hygiene");
}

if version.minor < 47 {
println!("cargo:rustc-cfg=no_ident_new_raw");
}

if version.minor < 54 {
println!("cargo:rustc-cfg=no_literal_from_str");
}

if version.minor < 55 {
println!("cargo:rustc-cfg=no_group_open_close");
}

if version.minor < 57 {
println!("cargo:rustc-cfg=no_is_available");
}
19 changes: 0 additions & 19 deletions src/convert.rs

This file was deleted.

20 changes: 2 additions & 18 deletions src/extra.rs
Original file line number Diff line number Diff line change
@@ -22,9 +22,7 @@ enum DelimSpanEnum {
#[cfg(wrap_proc_macro)]
Compiler {
join: proc_macro::Span,
#[cfg(not(no_group_open_close))]
open: proc_macro::Span,
#[cfg(not(no_group_open_close))]
close: proc_macro::Span,
},
Fallback(fallback::Span),
@@ -36,9 +34,7 @@ impl DelimSpan {
let inner = match group {
imp::Group::Compiler(group) => DelimSpanEnum::Compiler {
join: group.span(),
#[cfg(not(no_group_open_close))]
open: group.span_open(),
#[cfg(not(no_group_open_close))]
close: group.span_close(),
},
imp::Group::Fallback(group) => DelimSpanEnum::Fallback(group.span()),
@@ -66,13 +62,7 @@ impl DelimSpan {
pub fn open(&self) -> Span {
match &self.inner {
#[cfg(wrap_proc_macro)]
DelimSpanEnum::Compiler {
#[cfg(not(no_group_open_close))]
open,
#[cfg(no_group_open_close)]
join: open,
..
} => Span::_new(imp::Span::Compiler(*open)),
DelimSpanEnum::Compiler { open, .. } => Span::_new(imp::Span::Compiler(*open)),
DelimSpanEnum::Fallback(span) => Span::_new_fallback(span.first_byte()),
}
}
@@ -81,13 +71,7 @@ impl DelimSpan {
pub fn close(&self) -> Span {
match &self.inner {
#[cfg(wrap_proc_macro)]
DelimSpanEnum::Compiler {
#[cfg(not(no_group_open_close))]
close,
#[cfg(no_group_open_close)]
join: close,
..
} => Span::_new(imp::Span::Compiler(*close)),
DelimSpanEnum::Compiler { close, .. } => Span::_new(imp::Span::Compiler(*close)),
DelimSpanEnum::Fallback(span) => Span::_new_fallback(span.last_byte()),
}
}
28 changes: 5 additions & 23 deletions src/fallback.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ use core::cell::RefCell;
#[cfg(span_locations)]
use core::cmp;
use core::fmt::{self, Debug, Display, Write};
use core::iter::FromIterator;
use core::mem::ManuallyDrop;
use core::ops::RangeBounds;
use core::ptr;
@@ -71,7 +70,6 @@ impl TokenStream {
fn push_token_from_proc_macro(mut vec: RcVecMut<TokenTree>, token: TokenTree) {
// https://github.com/dtolnay/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),
@@ -81,20 +79,6 @@ fn push_token_from_proc_macro(mut vec: RcVecMut<TokenTree>, token: TokenTree) {
}) if literal.repr.starts_with('-') => {
push_negative_literal(vec, 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.repr.starts_with('-') {
push_negative_literal(vec, literal);
} else {
vec.push(TokenTree::Literal(crate::Literal::_new_fallback(literal)));
}
}
_ => vec.push(token),
}

@@ -479,7 +463,6 @@ impl Span {
Span { lo: 0, hi: 0 }
}

#[cfg(not(no_hygiene))]
pub fn mixed_site() -> Self {
Span::call_site()
}
@@ -769,7 +752,7 @@ fn validate_ident(string: &str, raw: bool) {
panic!("Ident is not allowed to be empty; use Option<Ident>");
}

if string.bytes().all(|digit| digit >= b'0' && digit <= b'9') {
if string.bytes().all(|digit| b'0' <= digit && digit <= b'9') {
panic!("Ident cannot be a number; use Literal instead");
}

@@ -1020,27 +1003,26 @@ impl Literal {

#[cfg(span_locations)]
{
use crate::convert::usize_to_u32;
use core::ops::Bound;

let lo = match range.start_bound() {
Bound::Included(start) => {
let start = usize_to_u32(*start)?;
let start = u32::try_from(*start).ok()?;
self.span.lo.checked_add(start)?
}
Bound::Excluded(start) => {
let start = usize_to_u32(*start)?;
let start = u32::try_from(*start).ok()?;
self.span.lo.checked_add(start)?.checked_add(1)?
}
Bound::Unbounded => self.span.lo,
};
let hi = match range.end_bound() {
Bound::Included(end) => {
let end = usize_to_u32(*end)?;
let end = u32::try_from(*end).ok()?;
self.span.lo.checked_add(end)?.checked_add(1)?
}
Bound::Excluded(end) => {
let end = usize_to_u32(*end)?;
let end = u32::try_from(*end).ok()?;
self.span.lo.checked_add(end)?
}
Bound::Unbounded => self.span.hi,
13 changes: 5 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@
//!
//! To opt into the additional APIs available in the most recent nightly
//! compiler, the `procmacro2_semver_exempt` config flag must be passed to
//! rustc. We will polyfill those nightly-only APIs back to Rust 1.31.0. As
//! rustc. We will polyfill those nightly-only APIs back to Rust 1.56.0. As
//! these are unstable APIs that track the nightly compiler, minor versions of
//! proc-macro2 may make breaking changes to them at any time.
//!
@@ -86,7 +86,7 @@
//! 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.65")]
#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.66")]
#![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))]
#![cfg_attr(super_unstable, feature(proc_macro_def_site))]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
@@ -97,6 +97,7 @@
clippy::items_after_statements,
clippy::let_underscore_untyped,
clippy::manual_assert,
clippy::manual_range_contains,
clippy::must_use_candidate,
clippy::needless_doctest_main,
clippy::new_without_default,
@@ -117,6 +118,8 @@ compile_error! {"\
build script as well.
"}

extern crate alloc;

#[cfg(feature = "proc-macro")]
extern crate proc_macro;

@@ -140,8 +143,6 @@ use crate::fallback as imp;
#[cfg(wrap_proc_macro)]
mod imp;

#[cfg(span_locations)]
mod convert;
#[cfg(span_locations)]
mod location;

@@ -150,7 +151,6 @@ use crate::marker::Marker;
use core::cmp::Ordering;
use core::fmt::{self, Debug, Display};
use core::hash::{Hash, Hasher};
use core::iter::FromIterator;
use core::ops::RangeBounds;
use core::str::FromStr;
use std::error::Error;
@@ -402,9 +402,6 @@ impl Span {
/// The span located at the invocation of the procedural macro, but with
/// local variables, labels, and `$crate` resolved at the definition site
/// of the macro. This is the same hygiene behavior as `macro_rules`.
///
/// This function requires Rust 1.45 or later.
#[cfg(not(no_hygiene))]
pub fn mixed_site() -> Self {
Span::_new(imp::Span::mixed_site())
}
4 changes: 2 additions & 2 deletions src/marker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::rc::Rc;
use core::marker::PhantomData;
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::rc::Rc;
use core::panic::{RefUnwindSafe, UnwindSafe};

// Zero sized marker with the correct set of autotrait impls we want all proc
// macro types to have.
31 changes: 12 additions & 19 deletions src/parse.rs
Original file line number Diff line number Diff line change
@@ -384,12 +384,11 @@ fn cooked_string(mut input: Cursor) -> Result<Cursor, Reject> {
Some((_, 'x')) => {
backslash_x_char(&mut chars)?;
}
Some((_, 'n')) | Some((_, 'r')) | Some((_, 't')) | Some((_, '\\'))
| Some((_, '\'')) | Some((_, '"')) | Some((_, '0')) => {}
Some((_, 'n' | 'r' | 't' | '\\' | '\'' | '"' | '0')) => {}
Some((_, 'u')) => {
backslash_u(&mut chars)?;
}
Some((newline, ch @ '\n')) | Some((newline, ch @ '\r')) => {
Some((newline, ch @ ('\n' | '\r'))) => {
input = input.advance(newline + 1);
trailing_backslash(&mut input, ch as u8)?;
chars = input.char_indices();
@@ -447,9 +446,8 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> {
Some((_, b'x')) => {
backslash_x_byte(&mut bytes)?;
}
Some((_, b'n')) | Some((_, b'r')) | Some((_, b't')) | Some((_, b'\\'))
| Some((_, b'0')) | Some((_, b'\'')) | Some((_, b'"')) => {}
Some((newline, b @ b'\n')) | Some((newline, b @ b'\r')) => {
Some((_, b'n' | b'r' | b't' | b'\\' | b'0' | b'\'' | b'"')) => {}
Some((newline, b @ (b'\n' | b'\r'))) => {
input = input.advance(newline + 1);
trailing_backslash(&mut input, b)?;
bytes = input.bytes().enumerate();
@@ -550,14 +548,13 @@ fn cooked_c_string(mut input: Cursor) -> Result<Cursor, Reject> {
Some((_, 'x')) => {
backslash_x_nonzero(&mut chars)?;
}
Some((_, 'n')) | Some((_, 'r')) | Some((_, 't')) | Some((_, '\\'))
| Some((_, '\'')) | Some((_, '"')) => {}
Some((_, 'n' | 'r' | 't' | '\\' | '\'' | '"')) => {}
Some((_, 'u')) => {
if backslash_u(&mut chars)? == '\0' {
break;
}
}
Some((newline, ch @ '\n')) | Some((newline, ch @ '\r')) => {
Some((newline, ch @ ('\n' | '\r'))) => {
input = input.advance(newline + 1);
trailing_backslash(&mut input, ch as u8)?;
chars = input.char_indices();
@@ -577,8 +574,7 @@ fn byte(input: Cursor) -> Result<Cursor, Reject> {
let ok = match bytes.next().map(|(_, b)| b) {
Some(b'\\') => match bytes.next().map(|(_, b)| b) {
Some(b'x') => backslash_x_byte(&mut bytes).is_ok(),
Some(b'n') | Some(b'r') | Some(b't') | Some(b'\\') | Some(b'0') | Some(b'\'')
| Some(b'"') => true,
Some(b'n' | b'r' | b't' | b'\\' | b'0' | b'\'' | b'"') => true,
_ => false,
},
b => b.is_some(),
@@ -601,9 +597,7 @@ fn character(input: Cursor) -> Result<Cursor, Reject> {
Some('\\') => match chars.next().map(|(_, ch)| ch) {
Some('x') => backslash_x_char(&mut chars).is_ok(),
Some('u') => backslash_u(&mut chars).is_ok(),
Some('n') | Some('r') | Some('t') | Some('\\') | Some('0') | Some('\'') | Some('"') => {
true
}
Some('n' | 'r' | 't' | '\\' | '0' | '\'' | '"') => true,
_ => false,
},
ch => ch.is_some(),
@@ -617,10 +611,10 @@ fn character(input: Cursor) -> Result<Cursor, Reject> {
}

macro_rules! next_ch {
($chars:ident @ $pat:pat $(| $rest:pat)*) => {
($chars:ident @ $pat:pat) => {
match $chars.next() {
Some((_, ch)) => match ch {
$pat $(| $rest)* => ch,
$pat => ch,
_ => return Err(Reject),
},
None => return Err(Reject),
@@ -692,8 +686,7 @@ fn trailing_backslash(input: &mut Cursor, mut last: u8) -> Result<(), Reject> {
return Err(Reject);
}
match whitespace.next() {
Some((_, b @ b' ')) | Some((_, b @ b'\t')) | Some((_, b @ b'\n'))
| Some((_, b @ b'\r')) => {
Some((_, b @ (b' ' | b'\t' | b'\n' | b'\r'))) => {
last = b;
}
Some((offset, _)) => {
@@ -718,7 +711,7 @@ fn float(input: Cursor) -> Result<Cursor, Reject> {
fn float_digits(input: Cursor) -> Result<Cursor, Reject> {
let mut chars = input.chars().peekable();
match chars.next() {
Some(ch) if ch >= '0' && ch <= '9' => {}
Some(ch) if '0' <= ch && ch <= '9' => {}
_ => return Err(Reject),
}

8 changes: 4 additions & 4 deletions src/rcvec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use alloc::rc::Rc;
use alloc::vec;
use core::mem;
use core::panic::RefUnwindSafe;
use core::slice;
use std::panic::RefUnwindSafe;
use std::rc::Rc;
use std::vec;

pub(crate) struct RcVec<T> {
inner: Rc<Vec<T>>,
@@ -53,7 +53,7 @@ impl<T> RcVec<T> {
T: Clone,
{
let vec = if let Some(owned) = Rc::get_mut(&mut self.inner) {
mem::replace(owned, Vec::new())
mem::take(owned)
} else {
Vec::clone(&self.inner)
};
71 changes: 3 additions & 68 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ use crate::detection::inside_proc_macro;
use crate::location::LineColumn;
use crate::{fallback, Delimiter, Punct, Spacing, TokenTree};
use core::fmt::{self, Debug, Display};
use core::iter::FromIterator;
use core::ops::RangeBounds;
use core::str::FromStr;
use std::panic;
@@ -286,15 +285,7 @@ impl Debug for LexError {
impl Display for LexError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
#[cfg(not(no_lexerror_display))]
LexError::Compiler(e) => Display::fmt(e, f),
#[cfg(no_lexerror_display)]
LexError::Compiler(_e) => Display::fmt(
&fallback::LexError {
span: fallback::Span::call_site(),
},
f,
),
LexError::Fallback(e) => Display::fmt(e, f),
}
}
@@ -406,7 +397,6 @@ impl Span {
}
}

#[cfg(not(no_hygiene))]
pub fn mixed_site() -> Self {
if inside_proc_macro() {
Span::Compiler(proc_macro::Span::mixed_site())
@@ -426,27 +416,15 @@ impl Span {

pub fn resolved_at(&self, other: Span) -> Span {
match (self, other) {
#[cfg(not(no_hygiene))]
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.resolved_at(b)),

// Name resolution affects semantics, but location is only cosmetic
#[cfg(no_hygiene)]
(Span::Compiler(_), Span::Compiler(_)) => other,

(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.resolved_at(b)),
_ => mismatch(),
}
}

pub fn located_at(&self, other: Span) -> Span {
match (self, other) {
#[cfg(not(no_hygiene))]
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.located_at(b)),

// Name resolution affects semantics, but location is only cosmetic
#[cfg(no_hygiene)]
(Span::Compiler(_), Span::Compiler(_)) => *self,

(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.located_at(b)),
_ => mismatch(),
}
@@ -602,20 +580,14 @@ impl Group {

pub fn span_open(&self) -> Span {
match self {
#[cfg(not(no_group_open_close))]
Group::Compiler(g) => Span::Compiler(g.span_open()),
#[cfg(no_group_open_close)]
Group::Compiler(g) => Span::Compiler(g.span()),
Group::Fallback(g) => Span::Fallback(g.span_open()),
}
}

pub fn span_close(&self) -> Span {
match self {
#[cfg(not(no_group_open_close))]
Group::Compiler(g) => Span::Compiler(g.span_close()),
#[cfg(no_group_open_close)]
Group::Compiler(g) => Span::Compiler(g.span()),
Group::Fallback(g) => Span::Fallback(g.span_close()),
}
}
@@ -676,27 +648,7 @@ impl Ident {

pub fn new_raw(string: &str, span: Span) -> Self {
match span {
#[cfg(not(no_ident_new_raw))]
Span::Compiler(s) => Ident::Compiler(proc_macro::Ident::new_raw(string, s)),
#[cfg(no_ident_new_raw)]
Span::Compiler(s) => {
let _ = proc_macro::Ident::new(string, s);
// At this point the un-r#-prefixed string is known to be a
// valid identifier. Try to produce a valid raw identifier by
// running the `TokenStream` parser, and unwrapping the first
// token as an `Ident`.
let raw_prefixed = format!("r#{}", string);
if let Ok(ts) = raw_prefixed.parse::<proc_macro::TokenStream>() {
let mut iter = ts.into_iter();
if let (Some(proc_macro::TokenTree::Ident(mut id)), None) =
(iter.next(), iter.next())
{
id.set_span(s);
return Ident::Compiler(id);
}
}
panic!("not allowed as a raw identifier: `{}`", raw_prefixed)
}
Span::Fallback(s) => Ident::Fallback(fallback::Ident::new_raw(string, s)),
}
}
@@ -798,7 +750,7 @@ macro_rules! unsuffixed_integers {
impl Literal {
pub unsafe fn from_str_unchecked(repr: &str) -> Self {
if inside_proc_macro() {
Literal::Compiler(compiler_literal_from_str(repr).expect("invalid literal"))
Literal::Compiler(proc_macro::Literal::from_str(repr).expect("invalid literal"))
} else {
Literal::Fallback(fallback::Literal::from_str_unchecked(repr))
}
@@ -921,32 +873,15 @@ impl FromStr for Literal {

fn from_str(repr: &str) -> Result<Self, Self::Err> {
if inside_proc_macro() {
compiler_literal_from_str(repr).map(Literal::Compiler)
let literal = proc_macro::Literal::from_str(repr)?;
Ok(Literal::Compiler(literal))
} else {
let literal = fallback::Literal::from_str(repr)?;
Ok(Literal::Fallback(literal))
}
}
}

fn compiler_literal_from_str(repr: &str) -> Result<proc_macro::Literal, LexError> {
#[cfg(not(no_literal_from_str))]
{
proc_macro::Literal::from_str(repr).map_err(LexError::Compiler)
}
#[cfg(no_literal_from_str)]
{
let tokens = proc_macro_parse(repr)?;
let mut iter = tokens.into_iter();
if let (Some(proc_macro::TokenTree::Literal(literal)), None) = (iter.next(), iter.next()) {
if literal.to_string().len() == repr.len() {
return Ok(literal);
}
}
Err(LexError::call_site())
}
}

impl Display for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
1 change: 0 additions & 1 deletion tests/marker.rs
Original file line number Diff line number Diff line change
@@ -62,7 +62,6 @@ mod semver_exempt {
assert_impl!(SourceFile is not Send or Sync);
}

#[cfg(not(no_libprocmacro_unwind_safe))]
mod unwind_safe {
use proc_macro2::{
Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
20 changes: 2 additions & 18 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@

use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use std::iter;
use std::panic;
use std::str::{self, FromStr};

#[test]
@@ -90,24 +89,9 @@ fn lifetime_number() {
}

#[test]
#[should_panic(expected = r#""'a#" is not a valid Ident"#)]
fn lifetime_invalid() {
let result = panic::catch_unwind(|| Ident::new("'a#", Span::call_site()));
match result {
Err(box_any) => {
let message = box_any.downcast_ref::<String>().unwrap();
let expected1 = r#""\'a#" is not a valid Ident"#; // 1.31.0 .. 1.53.0
let expected2 = r#""'a#" is not a valid Ident"#; // 1.53.0 ..
assert!(
message == expected1 || message == expected2,
"panic message does not match expected string\n\
\x20 panic message: `{:?}`\n\
\x20expected message: `{:?}`",
message,
expected2,
);
}
Ok(_) => panic!("test did not panic as expected"),
}
Ident::new("'a#", Span::call_site());
}

#[test]
2 changes: 1 addition & 1 deletion tests/test_fmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::from_iter_instead_of_collect)]

use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
use std::iter::{self, FromIterator};
use std::iter;

#[test]
fn test_fmt_group() {