From 3cef6de22a05f9cd49224ddcab7c84a1620ff300 Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Mon, 6 Feb 2023 08:49:26 +0100 Subject: Upgrade proc-macro2 to 1.0.51 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/proc-macro2 For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Change-Id: Id99ee0dd41a6dbbe8d3f4a80bf5c555912db8da7 --- .cargo_vcs_info.json | 2 +- .github/workflows/ci.yml | 22 ++++++++++++++++++- Android.bp | 8 ++----- Cargo.toml | 5 ++++- Cargo.toml.orig | 5 ++++- LICENSE-APACHE | 25 --------------------- LICENSE-MIT | 2 -- METADATA | 10 ++++----- README.md | 2 +- src/fallback.rs | 14 +++++------- src/lib.rs | 57 +++++++++++++----------------------------------- src/location.rs | 29 ++++++++++++++++++++++++ src/parse.rs | 4 ++++ src/wrapper.rs | 40 +++++++++++++-------------------- tests/test.rs | 26 +++++++++++++++++++++- 15 files changed, 131 insertions(+), 120 deletions(-) create mode 100644 src/location.rs diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 99281c2..3b65b55 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "47c91c8525088a055bbfec5df6ea4cd131d01504" + "sha1": "bc369f088f1b4067bc08848e8c6060b51a00e9df" }, "path_in_vcs": "" } \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32773a6..9d17e0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,13 +12,19 @@ env: RUSTFLAGS: -Dwarnings jobs: + pre_ci: + uses: dtolnay/.github/.github/workflows/pre_ci.yml@master + test: name: Rust ${{matrix.rust}} + needs: pre_ci + if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust: [1.31.0, stable, beta] + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master @@ -38,7 +44,10 @@ jobs: nightly: name: Rust nightly + needs: pre_ci + if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@nightly @@ -63,7 +72,10 @@ jobs: webassembly: name: WebAssembly + needs: pre_ci + if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@nightly @@ -73,17 +85,21 @@ jobs: fuzz: name: Fuzz + needs: pre_ci + if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@nightly - uses: dtolnay/install@cargo-fuzz - - run: cargo fuzz build -O + - run: cargo fuzz check clippy: name: Clippy runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@clippy @@ -92,7 +108,10 @@ jobs: miri: name: Miri + needs: pre_ci + if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@miri @@ -104,6 +123,7 @@ jobs: name: Outdated runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/install@cargo-outdated diff --git a/Android.bp b/Android.bp index 58461ea..e792ecb 100644 --- a/Android.bp +++ b/Android.bp @@ -41,7 +41,7 @@ rust_library_host { name: "libproc_macro2", crate_name: "proc_macro2", cargo_env_compat: true, - cargo_pkg_version: "1.0.47", + cargo_pkg_version: "1.0.51", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -59,17 +59,13 @@ rust_library_host { "libunicode_ident", ], compile_multilib: "first", - apex_available: [ - "//apex_available:platform", - "//apex_available:anyapex", - ], } rust_defaults { name: "proc-macro2_test_defaults", crate_name: "proc_macro2", cargo_env_compat: true, - cargo_pkg_version: "1.0.47", + cargo_pkg_version: "1.0.51", test_suites: ["general-tests"], auto_gen_config: true, edition: "2018", diff --git a/Cargo.toml b/Cargo.toml index 1bda7e3..092933e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" rust-version = "1.31" name = "proc-macro2" -version = "1.0.47" +version = "1.0.51" authors = [ "David Tolnay ", "Alex Crichton ", @@ -46,6 +46,9 @@ targets = ["x86_64-unknown-linux-gnu"] [package.metadata.playground] features = ["span-locations"] +[lib] +doc-scrape-examples = false + [dependencies.unicode-ident] version = "1.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 273683a..d653e6f 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "proc-macro2" -version = "1.0.47" # remember to update html_root_url +version = "1.0.51" # remember to update html_root_url authors = ["David Tolnay ", "Alex Crichton "] autobenches = false categories = ["development-tools::procedural-macro-helpers"] @@ -37,6 +37,9 @@ span-locations = [] # This feature no longer means anything. nightly = [] +[lib] +doc-scrape-examples = false + [workspace] members = ["benches/bench-libproc-macro", "tests/ui"] diff --git a/LICENSE-APACHE b/LICENSE-APACHE index 16fe87b..1b5ec8b 100644 --- a/LICENSE-APACHE +++ b/LICENSE-APACHE @@ -174,28 +174,3 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT index 39e0ed6..31aa793 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,5 +1,3 @@ -Copyright (c) 2014 Alex Crichton - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the diff --git a/METADATA b/METADATA index ffab613..5d76bb6 100644 --- a/METADATA +++ b/METADATA @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/proc-macro2/proc-macro2-1.0.47.crate" + value: "https://static.crates.io/crates/proc-macro2/proc-macro2-1.0.51.crate" } - version: "1.0.47" + version: "1.0.51" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 12 - day: 13 + year: 2023 + month: 2 + day: 6 } } diff --git a/README.md b/README.md index 70b6c86..131ba51 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [github](https://github.com/dtolnay/proc-macro2) [crates.io](https://crates.io/crates/proc-macro2) [docs.rs](https://docs.rs/proc-macro2) -[build status](https://github.com/dtolnay/proc-macro2/actions?query=branch%3Amaster) +[build status](https://github.com/dtolnay/proc-macro2/actions?query=branch%3Amaster) A wrapper around the procedural macro API of the compiler's `proc_macro` crate. This library serves two purposes: diff --git a/src/fallback.rs b/src/fallback.rs index fe4f248..587395d 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -1,3 +1,5 @@ +#[cfg(span_locations)] +use crate::location::LineColumn; use crate::parse::{self, Cursor}; use crate::rcvec::{RcVec, RcVecBuilder, RcVecIntoIter, RcVecMut}; use crate::{Delimiter, Spacing, TokenTree}; @@ -232,7 +234,7 @@ impl Debug for TokenStream { #[cfg(use_proc_macro)] impl From for TokenStream { - fn from(inner: proc_macro::TokenStream) -> TokenStream { + fn from(inner: proc_macro::TokenStream) -> Self { inner .to_string() .parse() @@ -242,7 +244,7 @@ impl From for TokenStream { #[cfg(use_proc_macro)] impl From for proc_macro::TokenStream { - fn from(inner: TokenStream) -> proc_macro::TokenStream { + fn from(inner: TokenStream) -> Self { inner .to_string() .parse() @@ -251,7 +253,7 @@ impl From for proc_macro::TokenStream { } impl From for TokenStream { - fn from(tree: TokenTree) -> TokenStream { + fn from(tree: TokenTree) -> Self { let mut stream = RcVecBuilder::new(); push_token_from_proc_macro(stream.as_mut(), tree); TokenStream { @@ -332,12 +334,6 @@ impl Debug for SourceFile { } } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub(crate) struct LineColumn { - pub line: usize, - pub column: usize, -} - #[cfg(span_locations)] thread_local! { static SOURCE_MAP: RefCell = RefCell::new(SourceMap { diff --git a/src/lib.rs b/src/lib.rs index 3fda02d..261c167 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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.47")] +#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.51")] #![cfg_attr( any(proc_macro_span, super_unstable), feature(proc_macro_span, proc_macro_span_shrink) @@ -139,6 +139,9 @@ use crate::fallback as imp; #[cfg(wrap_proc_macro)] mod imp; +#[cfg(span_locations)] +mod location; + use crate::marker::Marker; use core::cmp::Ordering; use core::fmt::{self, Debug, Display}; @@ -150,6 +153,9 @@ use std::error::Error; #[cfg(procmacro2_semver_exempt)] use std::path::PathBuf; +#[cfg(span_locations)] +pub use crate::location::LineColumn; + /// An abstract stream of tokens, or more concretely a sequence of token trees. /// /// This type provides interfaces for iterating over token trees and for @@ -225,14 +231,14 @@ impl FromStr for TokenStream { #[cfg(use_proc_macro)] impl From for TokenStream { - fn from(inner: proc_macro::TokenStream) -> TokenStream { + fn from(inner: proc_macro::TokenStream) -> Self { TokenStream::_new(inner.into()) } } #[cfg(use_proc_macro)] impl From for proc_macro::TokenStream { - fn from(inner: TokenStream) -> proc_macro::TokenStream { + fn from(inner: TokenStream) -> Self { inner.inner.into() } } @@ -356,37 +362,6 @@ impl Debug for SourceFile { } } -/// A line-column pair representing the start or end of a `Span`. -/// -/// This type is semver exempt and not exposed by default. -#[cfg(span_locations)] -#[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub struct LineColumn { - /// The 1-indexed line in the source file on which the span starts or ends - /// (inclusive). - pub line: usize, - /// The 0-indexed column (in UTF-8 characters) in the source file on which - /// the span starts or ends (inclusive). - pub column: usize, -} - -#[cfg(span_locations)] -impl Ord for LineColumn { - fn cmp(&self, other: &Self) -> Ordering { - self.line - .cmp(&other.line) - .then(self.column.cmp(&other.column)) - } -} - -#[cfg(span_locations)] -impl PartialOrd for LineColumn { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - /// A region of source code, along with macro expansion information. #[derive(Copy, Clone)] pub struct Span { @@ -492,8 +467,7 @@ impl Span { #[cfg(span_locations)] #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] pub fn start(&self) -> LineColumn { - let imp::LineColumn { line, column } = self.inner.start(); - LineColumn { line, column } + self.inner.start() } /// Get the ending line/column in the source file for this span. @@ -508,8 +482,7 @@ impl Span { #[cfg(span_locations)] #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] pub fn end(&self) -> LineColumn { - let imp::LineColumn { line, column } = self.inner.end(); - LineColumn { line, column } + self.inner.end() } /// Creates an empty span pointing to directly before this span. @@ -601,25 +574,25 @@ impl TokenTree { } impl From for TokenTree { - fn from(g: Group) -> TokenTree { + fn from(g: Group) -> Self { TokenTree::Group(g) } } impl From for TokenTree { - fn from(g: Ident) -> TokenTree { + fn from(g: Ident) -> Self { TokenTree::Ident(g) } } impl From for TokenTree { - fn from(g: Punct) -> TokenTree { + fn from(g: Punct) -> Self { TokenTree::Punct(g) } } impl From for TokenTree { - fn from(g: Literal) -> TokenTree { + fn from(g: Literal) -> Self { TokenTree::Literal(g) } } diff --git a/src/location.rs b/src/location.rs new file mode 100644 index 0000000..463026c --- /dev/null +++ b/src/location.rs @@ -0,0 +1,29 @@ +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")))] +#[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 + /// (inclusive). + pub line: usize, + /// The 0-indexed column (in UTF-8 characters) in the source file on which + /// the span starts or ends (inclusive). + pub column: usize, +} + +impl Ord for LineColumn { + fn cmp(&self, other: &Self) -> Ordering { + self.line + .cmp(&other.line) + .then(self.column.cmp(&other.column)) + } +} + +impl PartialOrd for LineColumn { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} diff --git a/src/parse.rs b/src/parse.rs index 307e065..2a87948 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -472,6 +472,10 @@ fn raw_string(input: Cursor) -> Result { _ => return Err(Reject), } } + if n > 255 { + // https://github.com/rust-lang/rust/pull/95251 + return Err(Reject); + } while let Some((i, ch)) = chars.next() { match ch { '"' if input.rest[i + 1..].starts_with(&input.rest[..n]) => { diff --git a/src/wrapper.rs b/src/wrapper.rs index 47d1494..f5ec06b 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -1,4 +1,6 @@ use crate::detection::inside_proc_macro; +#[cfg(span_locations)] +use crate::location::LineColumn; use crate::{fallback, Delimiter, Punct, Spacing, TokenTree}; use core::fmt::{self, Debug, Display}; use core::iter::FromIterator; @@ -129,13 +131,13 @@ impl Display for TokenStream { } impl From for TokenStream { - fn from(inner: proc_macro::TokenStream) -> TokenStream { + fn from(inner: proc_macro::TokenStream) -> Self { TokenStream::Compiler(DeferredTokenStream::new(inner)) } } impl From for proc_macro::TokenStream { - fn from(inner: TokenStream) -> proc_macro::TokenStream { + fn from(inner: TokenStream) -> Self { match inner { TokenStream::Compiler(inner) => inner.into_token_stream(), TokenStream::Fallback(inner) => inner.to_string().parse().unwrap(), @@ -144,7 +146,7 @@ impl From for proc_macro::TokenStream { } impl From for TokenStream { - fn from(inner: fallback::TokenStream) -> TokenStream { + fn from(inner: fallback::TokenStream) -> Self { TokenStream::Fallback(inner) } } @@ -168,7 +170,7 @@ fn into_compiler_token(token: TokenTree) -> proc_macro::TokenTree { } impl From for TokenStream { - fn from(token: TokenTree) -> TokenStream { + fn from(token: TokenTree) -> Self { if inside_proc_macro() { TokenStream::Compiler(DeferredTokenStream::new(into_compiler_token(token).into())) } else { @@ -261,13 +263,13 @@ impl LexError { } impl From for LexError { - fn from(e: proc_macro::LexError) -> LexError { + fn from(e: proc_macro::LexError) -> Self { LexError::Compiler(e) } } impl From for LexError { - fn from(e: fallback::LexError) -> LexError { + fn from(e: fallback::LexError) -> Self { LexError::Fallback(e) } } @@ -389,12 +391,6 @@ impl Debug for SourceFile { } } -#[cfg(any(super_unstable, feature = "span-locations"))] -pub(crate) struct LineColumn { - pub line: usize, - pub column: usize, -} - #[derive(Copy, Clone)] pub(crate) enum Span { Compiler(proc_macro::Span), @@ -471,7 +467,7 @@ impl Span { } } - #[cfg(any(super_unstable, feature = "span-locations"))] + #[cfg(span_locations)] pub fn start(&self) -> LineColumn { match self { #[cfg(proc_macro_span)] @@ -481,14 +477,11 @@ impl Span { } #[cfg(not(proc_macro_span))] Span::Compiler(_) => LineColumn { line: 0, column: 0 }, - Span::Fallback(s) => { - let fallback::LineColumn { line, column } = s.start(); - LineColumn { line, column } - } + Span::Fallback(s) => s.start(), } } - #[cfg(any(super_unstable, feature = "span-locations"))] + #[cfg(span_locations)] pub fn end(&self) -> LineColumn { match self { #[cfg(proc_macro_span)] @@ -498,10 +491,7 @@ impl Span { } #[cfg(not(proc_macro_span))] Span::Compiler(_) => LineColumn { line: 0, column: 0 }, - Span::Fallback(s) => { - let fallback::LineColumn { line, column } = s.end(); - LineColumn { line, column } - } + Span::Fallback(s) => s.end(), } } @@ -549,13 +539,13 @@ impl Span { } impl From for crate::Span { - fn from(proc_span: proc_macro::Span) -> crate::Span { + fn from(proc_span: proc_macro::Span) -> Self { crate::Span::_new(Span::Compiler(proc_span)) } } impl From for Span { - fn from(inner: fallback::Span) -> Span { + fn from(inner: fallback::Span) -> Self { Span::Fallback(inner) } } @@ -939,7 +929,7 @@ impl Literal { } impl From for Literal { - fn from(s: fallback::Literal) -> Literal { + fn from(s: fallback::Literal) -> Self { Literal::Fallback(s) } } diff --git a/tests/test.rs b/tests/test.rs index 8f5624d..e0af151 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,6 +1,11 @@ -#![allow(clippy::assertions_on_result_states, clippy::non_ascii_literal)] +#![allow( + clippy::assertions_on_result_states, + clippy::items_after_statements, + clippy::non_ascii_literal +)] use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree}; +use std::iter; use std::panic; use std::str::{self, FromStr}; @@ -114,6 +119,25 @@ fn literal_string() { #[test] fn literal_raw_string() { "r\"\r\n\"".parse::().unwrap(); + + fn raw_string_literal_with_hashes(n: usize) -> String { + let mut literal = String::new(); + literal.push('r'); + literal.extend(iter::repeat('#').take(n)); + literal.push('"'); + literal.push('"'); + literal.extend(iter::repeat('#').take(n)); + literal + } + + raw_string_literal_with_hashes(255) + .parse::() + .unwrap(); + + // https://github.com/rust-lang/rust/pull/95251 + raw_string_literal_with_hashes(256) + .parse::() + .unwrap_err(); } #[test] -- cgit v1.2.3