diff options
author | Jeffrey Vander Stoep <jeffv@google.com> | 2022-12-16 11:45:27 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-12-16 11:45:27 +0000 |
commit | 95820d40ba0c89389aebebd8143fc627a53f104c (patch) | |
tree | d55cd2272eea8a02740a628f3d81dad893c930ed | |
parent | cca2374f9c298b064df2d87cdbb68aa1d715ca5c (diff) | |
parent | 83f7ae1e164d134fdd0379e30a500b5c6adfdfa0 (diff) | |
download | paste-95820d40ba0c89389aebebd8143fc627a53f104c.tar.gz |
Merge "Upgrade paste to 1.0.10"main-16k-with-phones
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 45 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | Cargo.toml | 10 | ||||
-rw-r--r-- | Cargo.toml.orig | 10 | ||||
-rw-r--r-- | LICENSE-MIT | 2 | ||||
-rw-r--r-- | METADATA | 12 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | build.rs | 33 | ||||
-rw-r--r-- | src/lib.rs | 69 | ||||
-rw-r--r-- | tests/compiletest.rs | 1 | ||||
-rw-r--r-- | tests/test_expr.rs | 48 | ||||
-rw-r--r-- | tests/test_item.rs | 4 | ||||
-rw-r--r-- | tests/ui/invalid-ident.rs | 8 | ||||
-rw-r--r-- | tests/ui/invalid-ident.stderr | 24 | ||||
-rw-r--r-- | tests/ui/unsupported-literal.rs | 16 | ||||
-rw-r--r-- | tests/ui/unsupported-literal.stderr | 24 |
17 files changed, 261 insertions, 51 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index be43e96..1a328e4 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "4ffed377239acf07f5fbe2cfa152b0824790852b" + "sha1": "188ceccacedd20ff9ecc4037d43162f39a41f7bf" }, "path_in_vcs": "" }
\ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a59ee09..ab5c1fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,12 @@ on: pull_request: schedule: [cron: "40 1 * * *"] +permissions: + contents: read + +env: + RUSTFLAGS: -Dwarnings + jobs: test: name: Rust ${{matrix.rust}} @@ -12,35 +18,30 @@ jobs: strategy: fail-fast: false matrix: - rust: [nightly, beta, stable, 1.45.0] + rust: [nightly, beta, stable, 1.56.0] + timeout-minutes: 45 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust}} - run: cargo test - mintest: - name: Rust 1.34.0 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@1.34.0 - - run: cargo test --test test_item - msrv: name: Rust 1.31.0 runs-on: ubuntu-latest + timeout-minutes: 45 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@1.31.0 - run: cargo check minimal: name: Minimal versions runs-on: ubuntu-latest + timeout-minutes: 45 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@nightly - run: cargo -Z minimal-versions generate-lockfile - run: cargo check --locked @@ -49,15 +50,29 @@ jobs: name: Clippy runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@clippy - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic + miri: + name: Miri + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@miri + - run: cargo miri test + env: + MIRIFLAGS: -Zmiri-strict-provenance + outdated: name: Outdated runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - - uses: actions/checkout@v2 - - run: cargo outdated --exit-code 1 + - uses: actions/checkout@v3 + - uses: dtolnay/install@cargo-outdated + - run: cargo outdated --workspace --exit-code 1 @@ -41,7 +41,7 @@ rust_proc_macro { name: "libpaste", crate_name: "paste", cargo_env_compat: true, - cargo_pkg_version: "1.0.6", + cargo_pkg_version: "1.0.10", srcs: ["src/lib.rs"], edition: "2018", } @@ -13,18 +13,24 @@ edition = "2018" rust-version = "1.31" name = "paste" -version = "1.0.6" +version = "1.0.10" authors = ["David Tolnay <dtolnay@gmail.com>"] description = "Macros for all your token pasting needs" readme = "README.md" -categories = ["no-std"] +keywords = ["macros"] +categories = [ + "development-tools", + "no-std", +] license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/paste" + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [lib] proc-macro = true + [dev-dependencies.paste-test-suite] version = "0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 88d4d81..bbd510c 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,14 +1,14 @@ [package] name = "paste" -version = "1.0.6" +version = "1.0.10" authors = ["David Tolnay <dtolnay@gmail.com>"] +categories = ["development-tools", "no-std"] +description = "Macros for all your token pasting needs" edition = "2018" -rust-version = "1.31" +keywords = ["macros"] license = "MIT OR Apache-2.0" -description = "Macros for all your token pasting needs" repository = "https://github.com/dtolnay/paste" -categories = ["no-std"] -readme = "README.md" +rust-version = "1.31" [lib] proc-macro = true diff --git a/LICENSE-MIT b/LICENSE-MIT index 815d6c0..31aa793 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,5 +1,3 @@ -Copyright (c) 2018 - 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 @@ -1,3 +1,7 @@ +# This project was upgraded with external_updater. +# Usage: tools/external_updater/updater.sh update rust/crates/paste +# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md + name: "paste" description: "Macros for all your token pasting needs" third_party { @@ -7,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/paste/paste-1.0.6.crate" + value: "https://static.crates.io/crates/paste/paste-1.0.10.crate" } - version: "1.0.6" + version: "1.0.10" license_type: NOTICE last_upgrade_date { year: 2022 - month: 3 - day: 1 + month: 12 + day: 13 } } @@ -3,7 +3,7 @@ Macros for all your token pasting needs [<img alt="github" src="https://img.shields.io/badge/github-dtolnay/paste-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/paste) [<img alt="crates.io" src="https://img.shields.io/crates/v/paste.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/paste) -[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-paste-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/paste) +[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-paste-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/paste) [<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/paste/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/paste/actions?query=branch%3Amaster) The nightly-only [`concat_idents!`] macro in the Rust standard library is diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..349b5fc --- /dev/null +++ b/build.rs @@ -0,0 +1,33 @@ +use std::env; +use std::process::Command; +use std::str; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + let version = match rustc_version() { + Some(version) => version, + None => return, + }; + + if version.minor < 54 { + // https://github.com/rust-lang/rust/pull/84717 + println!("cargo:rustc-cfg=no_literal_fromstr"); + } +} + +struct RustcVersion { + minor: u32, +} + +fn rustc_version() -> Option<RustcVersion> { + let rustc = env::var_os("RUSTC")?; + let output = Command::new(rustc).arg("--version").output().ok()?; + let version = str::from_utf8(&output.stdout).ok()?; + let mut pieces = version.split('.'); + if pieces.next() != Some("rustc 1") { + return None; + } + let minor = pieces.next()?.parse().ok()?; + Some(RustcVersion { minor }) +} @@ -2,7 +2,7 @@ //! //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github //! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust -//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K +//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs //! //! <br> //! @@ -138,7 +138,9 @@ //! ``` #![allow( + clippy::derive_partial_eq_without_eq, clippy::doc_markdown, + clippy::match_same_arms, clippy::module_name_repetitions, clippy::needless_doctest_main, clippy::too_many_lines @@ -154,6 +156,7 @@ use crate::attr::expand_attr; use crate::error::{Error, Result}; use crate::segment::Segment; use proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree}; +use std::char; use std::iter; use std::panic; @@ -161,8 +164,18 @@ use std::panic; pub fn paste(input: TokenStream) -> TokenStream { let mut contains_paste = false; let flatten_single_interpolation = true; - match expand(input, &mut contains_paste, flatten_single_interpolation) { - Ok(expanded) => expanded, + match expand( + input.clone(), + &mut contains_paste, + flatten_single_interpolation, + ) { + Ok(expanded) => { + if contains_paste { + expanded + } else { + input + } + } Err(err) => err.to_compile_error(), } } @@ -363,14 +376,32 @@ fn parse_bracket_as_segments(input: TokenStream, scope: Span) -> Result<Vec<Segm for segment in &mut segments { if let Segment::String(string) = segment { - if string.value.contains(&['#', '\\', '.', '+'][..]) { + if string.value.starts_with("'\\u{") { + let hex = &string.value[4..string.value.len() - 2]; + if let Ok(unsigned) = u32::from_str_radix(hex, 16) { + if let Some(ch) = char::from_u32(unsigned) { + string.value.clear(); + string.value.push(ch); + continue; + } + } + } + if string.value.contains(&['#', '\\', '.', '+'][..]) + || string.value.starts_with("b'") + || string.value.starts_with("b\"") + || string.value.starts_with("br\"") + { return Err(Error::new(string.span, "unsupported literal")); } - string.value = string - .value - .replace('"', "") - .replace('\'', "") - .replace('-', "_"); + let mut range = 0..string.value.len(); + if string.value.starts_with("r\"") { + range.start += 2; + range.end -= 1; + } else if string.value.starts_with(&['"', '\''][..]) { + range.start += 1; + range.end -= 1; + } + string.value = string.value[range].replace('-', "_"); } } @@ -380,6 +411,26 @@ fn parse_bracket_as_segments(input: TokenStream, scope: Span) -> Result<Vec<Segm fn pasted_to_tokens(mut pasted: String, span: Span) -> Result<TokenStream> { let mut tokens = TokenStream::new(); + #[cfg(not(no_literal_fromstr))] + { + use proc_macro::{LexError, Literal}; + use std::str::FromStr; + + if pasted.starts_with(|ch: char| ch.is_ascii_digit()) { + let literal = match panic::catch_unwind(|| Literal::from_str(&pasted)) { + Ok(Ok(literal)) => TokenTree::Literal(literal), + Ok(Err(LexError { .. })) | Err(_) => { + return Err(Error::new( + span, + &format!("`{:?}` is not a valid literal", pasted), + )); + } + }; + tokens.extend(iter::once(literal)); + return Ok(tokens); + } + } + if pasted.starts_with('\'') { let mut apostrophe = TokenTree::Punct(Punct::new('\'', Spacing::Joint)); apostrophe.set_span(span); diff --git a/tests/compiletest.rs b/tests/compiletest.rs index f9aea23..7974a62 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -1,4 +1,5 @@ #[rustversion::attr(not(nightly), ignore)] +#[cfg_attr(miri, ignore)] #[test] fn ui() { let t = trybuild::TestCases::new(); diff --git a/tests/test_expr.rs b/tests/test_expr.rs index a61bd03..41d84ce 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -26,11 +26,34 @@ fn test_repeat() { } #[test] -fn test_integer() { +fn test_literal_to_identifier() { const CONST0: &str = "const0"; let pasted = paste!([<CONST 0>]); assert_eq!(pasted, CONST0); + + let pasted = paste!([<CONST '0'>]); + assert_eq!(pasted, CONST0); + + let pasted = paste!([<CONST "0">]); + assert_eq!(pasted, CONST0); + + let pasted = paste!([<CONST r"0">]); + assert_eq!(pasted, CONST0); + + let pasted = paste!([<CONST '\u{30}'>]); + assert_eq!(pasted, CONST0); +} + +#[test] +fn test_literal_suffix() { + macro_rules! literal { + ($bit:tt) => { + paste!([<1_u $bit>]) + }; + } + + assert_eq!(literal!(32), 1); } #[test] @@ -235,3 +258,26 @@ mod test_local_setter { assert_eq!(a.val, 42); } } + +// https://github.com/dtolnay/paste/issues/85 +#[test] +fn test_top_level_none_delimiter() { + macro_rules! clone { + ($val:expr) => { + paste! { + $val.clone() + } + }; + } + + #[derive(Clone)] + struct A; + + impl A { + fn consume_self(self) { + let _ = self; + } + } + + clone!(&A).consume_self(); +} diff --git a/tests/test_item.rs b/tests/test_item.rs index 86c98a9..3821510 100644 --- a/tests/test_item.rs +++ b/tests/test_item.rs @@ -59,8 +59,8 @@ mod test_none_delimited_single_lifetime { macro_rules! m { ($life:lifetime) => { paste! { - pub struct S; - impl<$life> S { + pub struct S<$life>(&$life ()); + impl<$life> S<$life> { fn f() {} } } diff --git a/tests/ui/invalid-ident.rs b/tests/ui/invalid-ident.rs index d566e65..6a8cf3c 100644 --- a/tests/ui/invalid-ident.rs +++ b/tests/ui/invalid-ident.rs @@ -4,4 +4,12 @@ paste! { fn [<0 f>]() {} } +paste! { + fn [<f '"'>]() {} +} + +paste! { + fn [<f "'">]() {} +} + fn main() {} diff --git a/tests/ui/invalid-ident.stderr b/tests/ui/invalid-ident.stderr index 8a233cb..28593fb 100644 --- a/tests/ui/invalid-ident.stderr +++ b/tests/ui/invalid-ident.stderr @@ -1,5 +1,21 @@ -error: `"0f"` is not a valid identifier - --> tests/ui/invalid-ident.rs:4:8 +error: expected identifier, found `0f` + --> tests/ui/invalid-ident.rs:3:1 | -4 | fn [<0 f>]() {} - | ^^^^^^^ +3 | / paste! { +4 | | fn [<0 f>]() {} +5 | | } + | |_^ expected identifier + | + = note: this error originates in the macro `paste` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `"f\""` is not a valid identifier + --> tests/ui/invalid-ident.rs:8:8 + | +8 | fn [<f '"'>]() {} + | ^^^^^^^^^ + +error: `"f'"` is not a valid identifier + --> tests/ui/invalid-ident.rs:12:8 + | +12 | fn [<f "'">]() {} + | ^^^^^^^^^ diff --git a/tests/ui/unsupported-literal.rs b/tests/ui/unsupported-literal.rs index 6538971..7a9c490 100644 --- a/tests/ui/unsupported-literal.rs +++ b/tests/ui/unsupported-literal.rs @@ -1,7 +1,21 @@ use paste::paste; paste! { - fn [<1e+100>]() {} + fn [<x 1e+100 z>]() {} +} + +paste! { + // `xyz` is not correct. `xbyz` is certainly not correct. Maybe `x121z` + // would be justifiable but for now don't accept this. + fn [<x b'y' z>]() {} +} + +paste! { + fn [<x b"y" z>]() {} +} + +paste! { + fn [<x br"y" z>]() {} } fn main() {} diff --git a/tests/ui/unsupported-literal.stderr b/tests/ui/unsupported-literal.stderr index 842e2f2..a802b45 100644 --- a/tests/ui/unsupported-literal.stderr +++ b/tests/ui/unsupported-literal.stderr @@ -1,5 +1,23 @@ error: unsupported literal - --> tests/ui/unsupported-literal.rs:4:10 + --> tests/ui/unsupported-literal.rs:4:12 | -4 | fn [<1e+100>]() {} - | ^^^^^^ +4 | fn [<x 1e+100 z>]() {} + | ^^^^^^ + +error: unsupported literal + --> tests/ui/unsupported-literal.rs:10:12 + | +10 | fn [<x b'y' z>]() {} + | ^^^^ + +error: unsupported literal + --> tests/ui/unsupported-literal.rs:14:12 + | +14 | fn [<x b"y" z>]() {} + | ^^^^ + +error: unsupported literal + --> tests/ui/unsupported-literal.rs:18:12 + | +18 | fn [<x br"y" z>]() {} + | ^^^^^ |