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.20
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.21
Choose a head ref
  • 11 commits
  • 10 files changed
  • 1 contributor

Commits on Sep 9, 2020

  1. Import PhantomData

    dtolnay committed Sep 9, 2020

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    8600142 View commit details
  2. Sort imports below mod

    dtolnay committed Sep 9, 2020

    Verified

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

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    951423e View commit details
  4. Revert "Add ui test for the not-Send error message"

    This makes it too complicated to test the --no-default-features
    configuration, due to trybuild depending transitively on proc-macro2's
    default features and Cargo not handling optional dev dependencies.
    dtolnay committed Sep 9, 2020

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    3099596 View commit details
  5. Add ui test in subdirectory

    dtolnay committed Sep 9, 2020

    Verified

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

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

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

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    5ef63e0 View commit details
  9. Remove unwind-safe test on rust 1.31.0

    On 1.31.0:
    
        error[E0277]: the type `std::cell::UnsafeCell<std::option::Option<syntax::tokenstream::TokenStream>>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
          --> tests/marker.rs:9:13
           |
        9  |               assert_implemented::<$ty>();
           |               ^^^^^^^^^^^^^^^^^^^^^^^^^ `std::cell::UnsafeCell<std::option::Option<syntax::tokenstream::TokenStream>>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
        ...
        74 | /     assert_unwind_safe! {
        75 | |         Delimiter
        76 | |         Group
        77 | |         Ident
        ...  |
        84 | |         TokenTree
        85 | |     }
           | |_____- in this macro invocation
           |
           = help: within `(syntax::parse::token::Nonterminal, syntax::parse::token::LazyTokenStream)`, the trait `std::panic::RefUnwindSafe` is not implemented for `std::cell::UnsafeCell<std::option::Option<syntax::tokenstream::TokenStream>>`
           = note: required because it appears within the type `std::cell::RefCell<std::option::Option<syntax::tokenstream::TokenStream>>`
           = note: required because it appears within the type `rustc_data_structures::sync::Lock<std::option::Option<syntax::tokenstream::TokenStream>>`
           = note: required because it appears within the type `syntax::parse::token::LazyTokenStream`
           = note: required because it appears within the type `(syntax::parse::token::Nonterminal, syntax::parse::token::LazyTokenStream)`
           = note: required because of the requirements on the impl of `std::panic::UnwindSafe` for `std::rc::Rc<(syntax::parse::token::Nonterminal, syntax::parse::token::LazyTokenStream)>`
           = note: required because it appears within the type `syntax::parse::token::Token`
           = note: required because it appears within the type `syntax::tokenstream::TokenTree`
           = note: required because it appears within the type `syntax::tokenstream::TokenStreamKind`
           = note: required because it appears within the type `syntax::tokenstream::TokenStream`
           = note: required because it appears within the type `proc_macro::TokenStream`
           = note: required because it appears within the type `proc_macro2::imp::DeferredTokenStream`
           = note: required because it appears within the type `proc_macro2::imp::TokenStream`
           = note: required because it appears within the type `proc_macro2::TokenStream`
        note: required by `unwind_safe::TokenStream::assert_implemented`
          --> tests/marker.rs:8:13
           |
        8  |               fn assert_implemented<T: $($marker +)+>() {}
           |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        ...
        74 | /     assert_unwind_safe! {
        75 | |         Delimiter
        76 | |         Group
        77 | |         Ident
        ...  |
        84 | |         TokenTree
        85 | |     }
           | |_____- in this macro invocation
    dtolnay committed Sep 9, 2020

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    23b7dd9 View commit details
  10. Merge pull request #251 from alexcrichton/marker

    Provide UnwindSafe for all types, matching libproc_macro
    dtolnay authored Sep 9, 2020

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    c85cef2 View commit details
  11. Release 1.0.21

    dtolnay committed Sep 9, 2020

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Copy the full SHA
    285269e View commit details
Showing with 136 additions and 33 deletions.
  1. +1 −0 .github/workflows/ci.yml
  2. +2 −2 Cargo.toml
  3. +4 −0 build.rs
  4. +30 −31 src/lib.rs
  5. +18 −0 src/marker.rs
  6. +33 −0 tests/marker.rs
  7. +13 −0 tests/ui/Cargo.toml
  8. +5 −0 tests/ui/compiletest.rs
  9. +6 −0 tests/ui/test-not-send.rs
  10. +24 −0 tests/ui/test-not-send.stderr
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ jobs:
- run: cargo test --no-default-features
- run: cargo test --no-default-features -- --ignored # run the ignored test to make sure the `proc-macro` feature is disabled
- run: cargo test --features span-locations
- run: cargo test --manifest-path tests/ui/Cargo.toml
- run: RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test
- run: RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test --no-default-features
- run: RUSTFLAGS='-Z allow-features=' cargo test
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "proc-macro2"
version = "1.0.20" # remember to update html_root_url
version = "1.0.21" # 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"
@@ -40,7 +40,7 @@ span-locations = []
nightly = []

[workspace]
members = ["benches/bench-libproc-macro"]
members = ["benches/bench-libproc-macro", "tests/ui"]

[patch.crates-io]
# Our doc tests depend on quote which depends on proc-macro2. Without this line,
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -61,6 +61,10 @@ fn main() {
println!("cargo:rustc-cfg=span_locations");
}

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

if version.minor < 39 {
println!("cargo:rustc-cfg=no_bind_by_move_pattern_guard");
}
61 changes: 30 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -78,25 +78,15 @@
//! 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.20")]
#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.21")]
#![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::{self, Debug, Display};
use std::hash::{Hash, Hasher};
use std::iter::FromIterator;
use std::marker;
use std::ops::RangeBounds;
#[cfg(procmacro2_semver_exempt)]
use std::path::PathBuf;
use std::rc::Rc;
use std::str::FromStr;

mod marker;
mod parse;

#[cfg(wrap_proc_macro)]
@@ -113,6 +103,16 @@ use crate::fallback as imp;
#[cfg(wrap_proc_macro)]
mod imp;

use crate::marker::Marker;
use std::cmp::Ordering;
use std::fmt::{self, Debug, Display};
use std::hash::{Hash, Hasher};
use std::iter::FromIterator;
use std::ops::RangeBounds;
#[cfg(procmacro2_semver_exempt)]
use std::path::PathBuf;
use std::str::FromStr;

/// An abstract stream of tokens, or more concretely a sequence of token trees.
///
/// This type provides interfaces for iterating over token trees and for
@@ -123,27 +123,27 @@ mod imp;
#[derive(Clone)]
pub struct TokenStream {
inner: imp::TokenStream,
_marker: marker::PhantomData<Rc<()>>,
_marker: Marker,
}

/// Error returned from `TokenStream::from_str`.
pub struct LexError {
inner: imp::LexError,
_marker: marker::PhantomData<Rc<()>>,
_marker: Marker,
}

impl TokenStream {
fn _new(inner: imp::TokenStream) -> TokenStream {
TokenStream {
inner,
_marker: marker::PhantomData,
_marker: Marker,
}
}

fn _new_stable(inner: fallback::TokenStream) -> TokenStream {
TokenStream {
inner: inner.into(),
_marker: marker::PhantomData,
_marker: Marker,
}
}

@@ -180,7 +180,7 @@ impl FromStr for TokenStream {
fn from_str(src: &str) -> Result<TokenStream, LexError> {
let e = src.parse().map_err(|e| LexError {
inner: e,
_marker: marker::PhantomData,
_marker: Marker,
})?;
Ok(TokenStream::_new(e))
}
@@ -261,15 +261,15 @@ impl Debug for LexError {
#[derive(Clone, PartialEq, Eq)]
pub struct SourceFile {
inner: imp::SourceFile,
_marker: marker::PhantomData<Rc<()>>,
_marker: Marker,
}

#[cfg(procmacro2_semver_exempt)]
impl SourceFile {
fn _new(inner: imp::SourceFile) -> Self {
SourceFile {
inner,
_marker: marker::PhantomData,
_marker: Marker,
}
}

@@ -338,21 +338,21 @@ impl PartialOrd for LineColumn {
#[derive(Copy, Clone)]
pub struct Span {
inner: imp::Span,
_marker: marker::PhantomData<Rc<()>>,
_marker: Marker,
}

impl Span {
fn _new(inner: imp::Span) -> Span {
Span {
inner,
_marker: marker::PhantomData,
_marker: Marker,
}
}

fn _new_stable(inner: fallback::Span) -> Span {
Span {
inner: inner.into(),
_marker: marker::PhantomData,
_marker: Marker,
}
}

@@ -840,14 +840,14 @@ impl Debug for Punct {
#[derive(Clone)]
pub struct Ident {
inner: imp::Ident,
_marker: marker::PhantomData<Rc<()>>,
_marker: Marker,
}

impl Ident {
fn _new(inner: imp::Ident) -> Ident {
Ident {
inner,
_marker: marker::PhantomData,
_marker: Marker,
}
}

@@ -968,7 +968,7 @@ impl Debug for Ident {
#[derive(Clone)]
pub struct Literal {
inner: imp::Literal,
_marker: marker::PhantomData<Rc<()>>,
_marker: Marker,
}

macro_rules! suffixed_int_literals {
@@ -1015,14 +1015,14 @@ impl Literal {
fn _new(inner: imp::Literal) -> Literal {
Literal {
inner,
_marker: marker::PhantomData,
_marker: Marker,
}
}

fn _new_stable(inner: fallback::Literal) -> Literal {
Literal {
inner: inner.into(),
_marker: marker::PhantomData,
_marker: Marker,
}
}

@@ -1181,10 +1181,9 @@ impl Display for Literal {

/// Public implementation details for the `TokenStream` type, such as iterators.
pub mod token_stream {
use crate::marker::Marker;
use crate::{imp, TokenTree};
use std::fmt::{self, Debug};
use std::marker;
use std::rc::Rc;

pub use crate::TokenStream;

@@ -1195,7 +1194,7 @@ pub mod token_stream {
#[derive(Clone)]
pub struct IntoIter {
inner: imp::TokenTreeIter,
_marker: marker::PhantomData<Rc<()>>,
_marker: Marker,
}

impl Iterator for IntoIter {
@@ -1219,7 +1218,7 @@ pub mod token_stream {
fn into_iter(self) -> IntoIter {
IntoIter {
inner: self.inner.into_iter(),
_marker: marker::PhantomData,
_marker: Marker,
}
}
}
18 changes: 18 additions & 0 deletions src/marker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::marker::PhantomData;
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::rc::Rc;

// Zero sized marker with the correct set of autotrait impls we want all proc
// macro types to have.
pub(crate) type Marker = PhantomData<ProcMacroAutoTraits>;

pub(crate) use self::value::*;

mod value {
pub(crate) use std::marker::PhantomData as Marker;
}

pub(crate) struct ProcMacroAutoTraits(Rc<()>);

impl UnwindSafe for ProcMacroAutoTraits {}
impl RefUnwindSafe for ProcMacroAutoTraits {}
33 changes: 33 additions & 0 deletions tests/marker.rs
Original file line number Diff line number Diff line change
@@ -57,3 +57,36 @@ mod semver_exempt {

assert_impl!(SourceFile is not Send or Sync);
}

#[cfg(not(no_libprocmacro_unwind_safe))]
mod unwind_safe {
use super::*;
use std::panic::{RefUnwindSafe, UnwindSafe};

macro_rules! assert_unwind_safe {
($($types:ident)*) => {
$(
assert_impl!($types is UnwindSafe and RefUnwindSafe);
)*
};
}

assert_unwind_safe! {
Delimiter
Group
Ident
LexError
Literal
Punct
Spacing
Span
TokenStream
TokenTree
}

#[cfg(procmacro2_semver_exempt)]
assert_unwind_safe! {
LineColumn
SourceFile
}
}
13 changes: 13 additions & 0 deletions tests/ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "proc-macro2-ui-test"
version = "0.0.0"
edition = "2018"
publish = false

[[test]]
name = "compiletest"
path = "compiletest.rs"

[dev-dependencies]
proc-macro2 = { path = "../.." }
trybuild = { version = "1.0", features = ["diff"] }
5 changes: 5 additions & 0 deletions tests/ui/compiletest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("test-*.rs");
}
6 changes: 6 additions & 0 deletions tests/ui/test-not-send.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use proc_macro2::Span;

fn main() {
fn requires_send<T: Send>() {}
requires_send::<Span>();
}
24 changes: 24 additions & 0 deletions tests/ui/test-not-send.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error[E0277]: `proc_macro::Span` cannot be sent between threads safely
--> $DIR/test-not-send.rs:5:5
|
4 | fn requires_send<T: Send>() {}
| ---- required by this bound in `requires_send`
5 | requires_send::<Span>();
| ^^^^^^^^^^^^^^^^^^^^^ `proc_macro::Span` cannot be sent between threads safely
|
= help: within `Span`, the trait `Send` is not implemented for `proc_macro::Span`
= note: required because it appears within the type `proc_macro2::imp::Span`
= note: required because it appears within the type `Span`

error[E0277]: `Rc<()>` cannot be sent between threads safely
--> $DIR/test-not-send.rs:5:5
|
4 | fn requires_send<T: Send>() {}
| ---- required by this bound in `requires_send`
5 | requires_send::<Span>();
| ^^^^^^^^^^^^^^^^^^^^^ `Rc<()>` cannot be sent between threads safely
|
= help: within `Span`, the trait `Send` is not implemented for `Rc<()>`
= note: required because it appears within the type `proc_macro2::marker::ProcMacroAutoTraits`
= note: required because it appears within the type `PhantomData<proc_macro2::marker::ProcMacroAutoTraits>`
= note: required because it appears within the type `Span`