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.74
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.75
Choose a head ref
  • 8 commits
  • 5 files changed
  • 1 contributor

Commits on Jan 3, 2024

  1. Verified

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

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    8da8b88 View commit details
  3. Merge pull request #433 from dtolnay/mismatch

    Include line number in compiler/fallback mismatch panic
    dtolnay authored Jan 3, 2024

    Verified

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

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

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

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    662426c View commit details
  7. Merge pull request #434 from dtolnay/mismatch

    Fix compiler/fallback mismatch when catching rustc lex error panic
    dtolnay authored Jan 3, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    6d2899c View commit details
  8. Release 1.0.75

    dtolnay committed Jan 3, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    2a9b955 View commit details
Showing with 48 additions and 29 deletions.
  1. +1 −1 .github/workflows/ci.yml
  2. +1 −1 Cargo.toml
  3. +1 −1 src/fallback.rs
  4. +1 −1 src/lib.rs
  5. +44 −25 src/wrapper.rs
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ jobs:
- name: RUSTFLAGS='-Z allow-features=' cargo test
run: cargo test
env:
RUSTFLAGS: -Z allow-features= ${{env.RUSTFLAGS}}
RUSTFLAGS: -Z allow-features= --cfg procmacro2_backtrace ${{env.RUSTFLAGS}}

minimal:
name: Minimal versions
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "proc-macro2"
version = "1.0.74"
version = "1.0.75"
authors = ["David Tolnay <dtolnay@gmail.com>", "Alex Crichton <alex@alexcrichton.com>"]
autobenches = false
categories = ["development-tools::procedural-macro-helpers"]
2 changes: 1 addition & 1 deletion src/fallback.rs
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ impl LexError {
self.span
}

fn call_site() -> Self {
pub(crate) fn call_site() -> Self {
LexError {
span: Span::call_site(),
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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.74")]
#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.75")]
#![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))]
69 changes: 44 additions & 25 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -28,18 +28,23 @@ pub(crate) struct DeferredTokenStream {
pub(crate) enum LexError {
Compiler(proc_macro::LexError),
Fallback(fallback::LexError),
}

impl LexError {
fn call_site() -> Self {
LexError::Fallback(fallback::LexError {
span: fallback::Span::call_site(),
})
}
// Rustc was supposed to return a LexError, but it panicked instead.
// https://github.com/rust-lang/rust/issues/58736
CompilerPanic,
}

fn mismatch() -> ! {
panic!("compiler/fallback mismatch")
#[cold]
fn mismatch(line: u32) -> ! {
#[cfg(procmacro2_backtrace)]
{
let backtrace = std::backtrace::Backtrace::force_capture();
panic!("compiler/fallback mismatch #{}\n\n{}", line, backtrace)
}
#[cfg(not(procmacro2_backtrace))]
{
panic!("compiler/fallback mismatch #{}", line)
}
}

impl DeferredTokenStream {
@@ -88,13 +93,13 @@ impl TokenStream {
fn unwrap_nightly(self) -> proc_macro::TokenStream {
match self {
TokenStream::Compiler(s) => s.into_token_stream(),
TokenStream::Fallback(_) => mismatch(),
TokenStream::Fallback(_) => mismatch(line!()),
}
}

fn unwrap_stable(self) -> fallback::TokenStream {
match self {
TokenStream::Compiler(_) => mismatch(),
TokenStream::Compiler(_) => mismatch(line!()),
TokenStream::Fallback(s) => s,
}
}
@@ -117,7 +122,7 @@ impl FromStr for TokenStream {
// Work around https://github.com/rust-lang/rust/issues/58736.
fn proc_macro_parse(src: &str) -> Result<proc_macro::TokenStream, LexError> {
let result = panic::catch_unwind(|| src.parse().map_err(LexError::Compiler));
result.unwrap_or_else(|_| Err(LexError::call_site()))
result.unwrap_or_else(|_| Err(LexError::CompilerPanic))
}

impl Display for TokenStream {
@@ -198,14 +203,14 @@ impl FromIterator<TokenStream> for TokenStream {
first.evaluate_now();
first.stream.extend(streams.map(|s| match s {
TokenStream::Compiler(s) => s.into_token_stream(),
TokenStream::Fallback(_) => mismatch(),
TokenStream::Fallback(_) => mismatch(line!()),
}));
TokenStream::Compiler(first)
}
Some(TokenStream::Fallback(mut first)) => {
first.extend(streams.map(|s| match s {
TokenStream::Fallback(s) => s,
TokenStream::Compiler(_) => mismatch(),
TokenStream::Compiler(_) => mismatch(line!()),
}));
TokenStream::Fallback(first)
}
@@ -255,7 +260,7 @@ impl Debug for TokenStream {
impl LexError {
pub(crate) fn span(&self) -> Span {
match self {
LexError::Compiler(_) => Span::call_site(),
LexError::Compiler(_) | LexError::CompilerPanic => Span::call_site(),
LexError::Fallback(e) => Span::Fallback(e.span()),
}
}
@@ -278,6 +283,10 @@ impl Debug for LexError {
match self {
LexError::Compiler(e) => Debug::fmt(e, f),
LexError::Fallback(e) => Debug::fmt(e, f),
LexError::CompilerPanic => {
let fallback = fallback::LexError::call_site();
Debug::fmt(&fallback, f)
}
}
}
}
@@ -287,6 +296,10 @@ impl Display for LexError {
match self {
LexError::Compiler(e) => Display::fmt(e, f),
LexError::Fallback(e) => Display::fmt(e, f),
LexError::CompilerPanic => {
let fallback = fallback::LexError::call_site();
Display::fmt(&fallback, f)
}
}
}
}
@@ -418,15 +431,17 @@ impl Span {
match (self, other) {
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.resolved_at(b)),
(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.resolved_at(b)),
_ => mismatch(),
(Span::Compiler(_), Span::Fallback(_)) => mismatch(line!()),
(Span::Fallback(_), Span::Compiler(_)) => mismatch(line!()),
}
}

pub fn located_at(&self, other: Span) -> Span {
match (self, other) {
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.located_at(b)),
(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.located_at(b)),
_ => mismatch(),
(Span::Compiler(_), Span::Fallback(_)) => mismatch(line!()),
(Span::Fallback(_), Span::Compiler(_)) => mismatch(line!()),
}
}

@@ -493,7 +508,7 @@ impl Span {
fn unwrap_nightly(self) -> proc_macro::Span {
match self {
Span::Compiler(s) => s,
Span::Fallback(_) => mismatch(),
Span::Fallback(_) => mismatch(line!()),
}
}
}
@@ -596,14 +611,15 @@ impl Group {
match (self, span) {
(Group::Compiler(g), Span::Compiler(s)) => g.set_span(s),
(Group::Fallback(g), Span::Fallback(s)) => g.set_span(s),
_ => mismatch(),
(Group::Compiler(_), Span::Fallback(_)) => mismatch(line!()),
(Group::Fallback(_), Span::Compiler(_)) => mismatch(line!()),
}
}

fn unwrap_nightly(self) -> proc_macro::Group {
match self {
Group::Compiler(g) => g,
Group::Fallback(_) => mismatch(),
Group::Fallback(_) => mismatch(line!()),
}
}
}
@@ -674,14 +690,15 @@ impl Ident {
match (self, span) {
(Ident::Compiler(t), Span::Compiler(s)) => t.set_span(s),
(Ident::Fallback(t), Span::Fallback(s)) => t.set_span(s),
_ => mismatch(),
(Ident::Compiler(_), Span::Fallback(_)) => mismatch(line!()),
(Ident::Fallback(_), Span::Compiler(_)) => mismatch(line!()),
}
}

fn unwrap_nightly(self) -> proc_macro::Ident {
match self {
Ident::Compiler(s) => s,
Ident::Fallback(_) => mismatch(),
Ident::Fallback(_) => mismatch(line!()),
}
}
}
@@ -691,7 +708,8 @@ impl PartialEq for Ident {
match (self, other) {
(Ident::Compiler(t), Ident::Compiler(o)) => t.to_string() == o.to_string(),
(Ident::Fallback(t), Ident::Fallback(o)) => t == o,
_ => mismatch(),
(Ident::Compiler(_), Ident::Fallback(_)) => mismatch(line!()),
(Ident::Fallback(_), Ident::Compiler(_)) => mismatch(line!()),
}
}
}
@@ -850,7 +868,8 @@ impl Literal {
match (self, span) {
(Literal::Compiler(lit), Span::Compiler(s)) => lit.set_span(s),
(Literal::Fallback(lit), Span::Fallback(s)) => lit.set_span(s),
_ => mismatch(),
(Literal::Compiler(_), Span::Fallback(_)) => mismatch(line!()),
(Literal::Fallback(_), Span::Compiler(_)) => mismatch(line!()),
}
}

@@ -867,7 +886,7 @@ impl Literal {
fn unwrap_nightly(self) -> proc_macro::Literal {
match self {
Literal::Compiler(s) => s,
Literal::Fallback(_) => mismatch(),
Literal::Fallback(_) => mismatch(line!()),
}
}
}