diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:40:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:40:32 +0000 |
commit | 86cc98ac45d2fe735c5103cb89040db0e159e1f5 (patch) | |
tree | b32ea97ff2eef869149f1750a0e6f55c9fcff65c | |
parent | Releasing progress-linux version 1.0.81-1~progress7.99u1. (diff) | |
download | rust-proc-macro2-86cc98ac45d2fe735c5103cb89040db0e159e1f5.tar.xz rust-proc-macro2-86cc98ac45d2fe735c5103cb89040db0e159e1f5.zip |
Merging upstream version 1.0.85.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 18 | ||||
-rw-r--r-- | Cargo.toml | 36 | ||||
-rw-r--r-- | Cargo.toml.orig | 6 | ||||
-rw-r--r-- | build.rs | 19 | ||||
-rw-r--r-- | src/extra.rs | 2 | ||||
-rw-r--r-- | src/fallback.rs | 10 | ||||
-rw-r--r-- | src/lib.rs | 36 | ||||
-rw-r--r-- | src/location.rs | 2 | ||||
-rw-r--r-- | tests/test.rs | 1 | ||||
-rw-r--r-- | tests/test_size.rs | 89 |
11 files changed, 180 insertions, 41 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 3c80686..9687534 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "fd2c998967a65d3378f06f2480abd4d34f4697ab" + "sha1": "5ee1cabadb40abe12abe27e3b34de8fc6f60bc0a" }, "path_in_vcs": "" }
\ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2715f2a..10c21e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,7 @@ jobs: with: components: rust-src - name: Enable type layout randomization - run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV + run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout\ --cfg=randomize_layout >> $GITHUB_ENV - run: cargo check env: RUSTFLAGS: --cfg procmacro2_nightly_testing ${{env.RUSTFLAGS}} @@ -78,6 +78,22 @@ jobs: env: RUSTFLAGS: -Z allow-features= --cfg procmacro2_backtrace ${{env.RUSTFLAGS}} + layout: + name: Layout + needs: pre_ci + if: needs.pre_ci.outputs.continue + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly + with: + components: rust-src + - run: cargo test --test test_size + - run: cargo test --test test_size --features span-locations + - run: cargo test --test test_size --no-default-features + - run: cargo test --test test_size --no-default-features --features span-locations + msrv: name: Rust 1.56.0 needs: pre_ci @@ -13,11 +13,15 @@ edition = "2021" rust-version = "1.56" name = "proc-macro2" -version = "1.0.81" +version = "1.0.85" authors = [ "David Tolnay <dtolnay@gmail.com>", "Alex Crichton <alex@alexcrichton.com>", ] +build = "build.rs" +autobins = false +autoexamples = false +autotests = false autobenches = false 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" @@ -38,8 +42,6 @@ rustc-args = [ rustdoc-args = [ "--cfg", "procmacro2_semver_exempt", - "--cfg", - "doc_cfg", "--generate-link-to-definition", ] targets = ["x86_64-unknown-linux-gnu"] @@ -48,8 +50,34 @@ targets = ["x86_64-unknown-linux-gnu"] features = ["span-locations"] [lib] +name = "proc_macro2" +path = "src/lib.rs" doc-scrape-examples = false +[[test]] +name = "comments" +path = "tests/comments.rs" + +[[test]] +name = "test_fmt" +path = "tests/test_fmt.rs" + +[[test]] +name = "features" +path = "tests/features.rs" + +[[test]] +name = "marker" +path = "tests/marker.rs" + +[[test]] +name = "test_size" +path = "tests/test_size.rs" + +[[test]] +name = "test" +path = "tests/test.rs" + [dependencies.unicode-ident] version = "1.0" @@ -58,7 +86,7 @@ version = "1.0" [dev-dependencies.quote] version = "1.0" -default_features = false +default-features = false [dev-dependencies.rayon] version = "1.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index f543d9b..abb7f05 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "proc-macro2" -version = "1.0.81" +version = "1.0.85" authors = ["David Tolnay <dtolnay@gmail.com>", "Alex Crichton <alex@alexcrichton.com>"] autobenches = false categories = ["development-tools::procedural-macro-helpers"] @@ -14,7 +14,7 @@ rust-version = "1.56" [package.metadata.docs.rs] rustc-args = ["--cfg", "procmacro2_semver_exempt"] -rustdoc-args = ["--cfg", "procmacro2_semver_exempt", "--cfg", "doc_cfg", "--generate-link-to-definition"] +rustdoc-args = ["--cfg", "procmacro2_semver_exempt", "--generate-link-to-definition"] targets = ["x86_64-unknown-linux-gnu"] [package.metadata.playground] @@ -25,7 +25,7 @@ unicode-ident = "1.0" [dev-dependencies] flate2 = "1.0" -quote = { version = "1.0", default_features = false } +quote = { version = "1.0", default-features = false } rayon = "1.0" rustversion = "1" tar = "0.4" @@ -34,6 +34,9 @@ // macro API and catching a panic if it isn't available. Enabled on Rust // 1.57+. +#![allow(unknown_lints)] +#![allow(unexpected_cfgs)] + use std::env; use std::ffi::OsString; use std::iter; @@ -44,6 +47,22 @@ use std::str; fn main() { let rustc = rustc_minor_version().unwrap_or(u32::MAX); + if rustc >= 80 { + println!("cargo:rustc-check-cfg=cfg(fuzzing)"); + println!("cargo:rustc-check-cfg=cfg(no_is_available)"); + println!("cargo:rustc-check-cfg=cfg(no_literal_byte_character)"); + println!("cargo:rustc-check-cfg=cfg(no_literal_c_string)"); + println!("cargo:rustc-check-cfg=cfg(no_source_text)"); + println!("cargo:rustc-check-cfg=cfg(proc_macro_span)"); + println!("cargo:rustc-check-cfg=cfg(procmacro2_backtrace)"); + println!("cargo:rustc-check-cfg=cfg(procmacro2_nightly_testing)"); + println!("cargo:rustc-check-cfg=cfg(procmacro2_semver_exempt)"); + println!("cargo:rustc-check-cfg=cfg(randomize_layout)"); + println!("cargo:rustc-check-cfg=cfg(span_locations)"); + println!("cargo:rustc-check-cfg=cfg(super_unstable)"); + println!("cargo:rustc-check-cfg=cfg(wrap_proc_macro)"); + } + let docs_rs = env::var_os("DOCS_RS").is_some(); let semver_exempt = cfg!(procmacro2_semver_exempt) || docs_rs; if semver_exempt { diff --git a/src/extra.rs b/src/extra.rs index 543ec1d..522a90e 100644 --- a/src/extra.rs +++ b/src/extra.rs @@ -69,7 +69,7 @@ use core::fmt::{self, Debug}; /// This function is not applicable to and will panic if called from a /// procedural macro. #[cfg(span_locations)] -#[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] +#[cfg_attr(docsrs, doc(cfg(feature = "span-locations")))] pub fn invalidate_current_thread_spans() { crate::imp::invalidate_current_thread_spans(); } diff --git a/src/fallback.rs b/src/fallback.rs index b42537b..2d1c991 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -781,7 +781,7 @@ impl Debug for Group { #[derive(Clone)] pub(crate) struct Ident { - sym: String, + sym: Box<str>, span: Span, raw: bool, } @@ -795,7 +795,7 @@ impl Ident { pub fn new_unchecked(string: &str, span: Span) -> Self { Ident { - sym: string.to_owned(), + sym: Box::from(string), span, raw: false, } @@ -809,7 +809,7 @@ impl Ident { pub fn new_raw_unchecked(string: &str, span: Span) -> Self { Ident { - sym: string.to_owned(), + sym: Box::from(string), span, raw: true, } @@ -886,9 +886,9 @@ where fn eq(&self, other: &T) -> bool { let other = other.as_ref(); if self.raw { - other.starts_with("r#") && self.sym == other[2..] + other.starts_with("r#") && *self.sym == other[2..] } else { - self.sym == other + *self.sym == *other } } } @@ -86,10 +86,10 @@ //! 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.81")] +#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.85")] #![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))] +#![cfg_attr(docsrs, feature(doc_cfg))] #![deny(unsafe_op_in_unsafe_fn)] #![allow( clippy::cast_lossless, @@ -175,7 +175,7 @@ use std::ffi::CStr; use std::path::PathBuf; #[cfg(span_locations)] -#[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] +#[cfg_attr(docsrs, doc(cfg(feature = "span-locations")))] pub use crate::location::LineColumn; /// An abstract stream of tokens, or more concretely a sequence of token trees. @@ -252,7 +252,7 @@ impl FromStr for TokenStream { } #[cfg(feature = "proc-macro")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "proc-macro")))] +#[cfg_attr(docsrs, doc(cfg(feature = "proc-macro")))] impl From<proc_macro::TokenStream> for TokenStream { fn from(inner: proc_macro::TokenStream) -> Self { TokenStream::_new(inner.into()) @@ -260,7 +260,7 @@ impl From<proc_macro::TokenStream> for TokenStream { } #[cfg(feature = "proc-macro")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "proc-macro")))] +#[cfg_attr(docsrs, doc(cfg(feature = "proc-macro")))] impl From<TokenStream> for proc_macro::TokenStream { fn from(inner: TokenStream) -> Self { inner.inner.into() @@ -339,7 +339,7 @@ impl Error for LexError {} /// /// This type is semver exempt and not exposed by default. #[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))] -#[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))] +#[cfg_attr(docsrs, doc(cfg(procmacro2_semver_exempt)))] #[derive(Clone, PartialEq, Eq)] pub struct SourceFile { inner: imp::SourceFile, @@ -428,7 +428,7 @@ impl Span { /// /// This method is semver exempt and not exposed by default. #[cfg(procmacro2_semver_exempt)] - #[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))] + #[cfg_attr(docsrs, doc(cfg(procmacro2_semver_exempt)))] pub fn def_site() -> Self { Span::_new(imp::Span::def_site()) } @@ -471,7 +471,7 @@ impl Span { /// /// This method is semver exempt and not exposed by default. #[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))] - #[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))] + #[cfg_attr(docsrs, doc(cfg(procmacro2_semver_exempt)))] pub fn source_file(&self) -> SourceFile { SourceFile::_new(self.inner.source_file()) } @@ -486,7 +486,7 @@ impl Span { /// procedural macro, such as main.rs or build.rs, the byte range is always /// accurate regardless of toolchain. #[cfg(span_locations)] - #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] + #[cfg_attr(docsrs, doc(cfg(feature = "span-locations")))] pub fn byte_range(&self) -> Range<usize> { self.inner.byte_range() } @@ -501,7 +501,7 @@ impl Span { /// outside of a procedural macro, such as main.rs or build.rs, the /// line/column are always meaningful regardless of toolchain. #[cfg(span_locations)] - #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] + #[cfg_attr(docsrs, doc(cfg(feature = "span-locations")))] pub fn start(&self) -> LineColumn { self.inner.start() } @@ -516,7 +516,7 @@ impl Span { /// outside of a procedural macro, such as main.rs or build.rs, the /// line/column are always meaningful regardless of toolchain. #[cfg(span_locations)] - #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] + #[cfg_attr(docsrs, doc(cfg(feature = "span-locations")))] pub fn end(&self) -> LineColumn { self.inner.end() } @@ -538,7 +538,7 @@ impl Span { /// /// This method is semver exempt and not exposed by default. #[cfg(procmacro2_semver_exempt)] - #[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))] + #[cfg_attr(docsrs, doc(cfg(procmacro2_semver_exempt)))] pub fn eq(&self, other: &Span) -> bool { self.inner.eq(&other.inner) } @@ -685,6 +685,18 @@ pub enum Delimiter { /// operator priorities in cases like `$var * 3` where `$var` is `1 + 2`. /// Invisible delimiters may not survive roundtrip of a token stream through /// a string. + /// + /// <div class="warning"> + /// + /// Note: rustc currently can ignore the grouping of tokens delimited by `None` in the output + /// of a proc_macro. Only `None`-delimited groups created by a macro_rules macro in the input + /// of a proc_macro macro are preserved, and only in very specific circumstances. + /// Any `None`-delimited groups (re)created by a proc_macro will therefore not preserve + /// operator priorities as indicated above. The other `Delimiter` variants should be used + /// instead in this context. This is a rustc bug. For details, see + /// [rust-lang/rust#67062](https://github.com/rust-lang/rust/issues/67062). + /// + /// </div> None, } diff --git a/src/location.rs b/src/location.rs index 463026c..7190e2d 100644 --- a/src/location.rs +++ b/src/location.rs @@ -3,7 +3,7 @@ use core::cmp::Ordering; /// A line-column pair representing the start or end of a `Span`. /// /// This type is semver exempt and not exposed by default. -#[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] +#[cfg_attr(docsrs, doc(cfg(feature = "span-locations")))] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct LineColumn { /// The 1-indexed line in the source file on which the span starts or ends diff --git a/tests/test.rs b/tests/test.rs index 3923d33..0d7c88d 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -541,7 +541,6 @@ testing 123 } #[cfg(procmacro2_semver_exempt)] -#[cfg(not(nightly))] #[test] fn default_span() { let start = Span::call_site().start(); diff --git a/tests/test_size.rs b/tests/test_size.rs index 46e58db..49ca68e 100644 --- a/tests/test_size.rs +++ b/tests/test_size.rs @@ -2,41 +2,106 @@ extern crate proc_macro; use std::mem; -#[rustversion::attr(before(1.32), ignore)] +#[rustversion::attr(before(1.64), ignore)] +#[rustversion::attr( + since(1.64), + cfg_attr(any(randomize_layout, not(target_pointer_width = "64")), ignore) +)] #[test] -fn test_proc_macro_span_size() { +fn test_proc_macro_size() { assert_eq!(mem::size_of::<proc_macro::Span>(), 4); assert_eq!(mem::size_of::<Option<proc_macro::Span>>(), 4); + assert_eq!(mem::size_of::<proc_macro::Group>(), 20); + assert_eq!(mem::size_of::<proc_macro::Ident>(), 12); + assert_eq!(mem::size_of::<proc_macro::Punct>(), 8); + assert_eq!(mem::size_of::<proc_macro::Literal>(), 16); + assert_eq!(mem::size_of::<proc_macro::TokenStream>(), 4); } -#[cfg_attr(not(all(not(wrap_proc_macro), not(span_locations))), ignore)] +#[cfg_attr( + any( + randomize_layout, + not(target_pointer_width = "64"), + wrap_proc_macro, + span_locations + ), + ignore +)] #[test] -fn test_proc_macro2_fallback_span_size_without_locations() { +fn test_proc_macro2_fallback_size_without_locations() { assert_eq!(mem::size_of::<proc_macro2::Span>(), 0); assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 1); + assert_eq!(mem::size_of::<proc_macro2::Group>(), 16); + assert_eq!(mem::size_of::<proc_macro2::Ident>(), 24); + assert_eq!(mem::size_of::<proc_macro2::Punct>(), 8); + assert_eq!(mem::size_of::<proc_macro2::Literal>(), 24); + assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 8); } -#[cfg_attr(not(all(not(wrap_proc_macro), span_locations)), ignore)] +#[cfg_attr( + any( + randomize_layout, + not(target_pointer_width = "64"), + wrap_proc_macro, + not(span_locations) + ), + ignore +)] #[test] -fn test_proc_macro2_fallback_span_size_with_locations() { +fn test_proc_macro2_fallback_size_with_locations() { assert_eq!(mem::size_of::<proc_macro2::Span>(), 8); assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 12); + assert_eq!(mem::size_of::<proc_macro2::Group>(), 24); + assert_eq!(mem::size_of::<proc_macro2::Ident>(), 32); + assert_eq!(mem::size_of::<proc_macro2::Punct>(), 16); + assert_eq!(mem::size_of::<proc_macro2::Literal>(), 32); + assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 8); } -#[rustversion::attr(before(1.32), ignore)] +#[rustversion::attr(before(1.71), ignore)] #[rustversion::attr( - since(1.32), - cfg_attr(not(all(wrap_proc_macro, not(span_locations))), ignore) + since(1.71), + cfg_attr( + any( + randomize_layout, + not(target_pointer_width = "64"), + not(wrap_proc_macro), + span_locations + ), + ignore + ) )] #[test] -fn test_proc_macro2_wrapper_span_size_without_locations() { +fn test_proc_macro2_wrapper_size_without_locations() { assert_eq!(mem::size_of::<proc_macro2::Span>(), 4); assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 8); + assert_eq!(mem::size_of::<proc_macro2::Group>(), 24); + assert_eq!(mem::size_of::<proc_macro2::Ident>(), 24); + assert_eq!(mem::size_of::<proc_macro2::Punct>(), 12); + assert_eq!(mem::size_of::<proc_macro2::Literal>(), 24); + assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 32); } -#[cfg_attr(not(all(wrap_proc_macro, span_locations)), ignore)] +#[rustversion::attr(before(1.65), ignore)] +#[rustversion::attr( + since(1.65), + cfg_attr( + any( + randomize_layout, + not(target_pointer_width = "64"), + not(wrap_proc_macro), + not(span_locations) + ), + ignore + ) +)] #[test] -fn test_proc_macro2_wrapper_span_size_with_locations() { +fn test_proc_macro2_wrapper_size_with_locations() { assert_eq!(mem::size_of::<proc_macro2::Span>(), 12); assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 12); + assert_eq!(mem::size_of::<proc_macro2::Group>(), 32); + assert_eq!(mem::size_of::<proc_macro2::Ident>(), 32); + assert_eq!(mem::size_of::<proc_macro2::Punct>(), 20); + assert_eq!(mem::size_of::<proc_macro2::Literal>(), 32); + assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 32); } |