From ecb5eb34a8f7ad545f3b4a738f47b0b6cd980c4a Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Mon, 20 Mar 2023 22:56:48 +0000 Subject: Upgrade quote to 1.0.26 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/quote For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Bug: 276463929 Change-Id: I4370455adadff775595476f90d2db86a6f8a0e7d --- .cargo_vcs_info.json | 2 +- .github/workflows/ci.yml | 31 ++++++----- Android.bp | 2 +- Cargo.toml | 4 +- Cargo.toml.orig | 4 +- LICENSE-APACHE | 25 --------- METADATA | 8 +-- src/lib.rs | 12 ++--- src/runtime.rs | 60 +++++++++++++++++++++- src/spanned.rs | 21 +++++++- tests/test.rs | 32 +++++++++++- .../ui/does-not-have-iter-interpolated-dup.stderr | 2 +- tests/ui/does-not-have-iter-interpolated.stderr | 2 +- tests/ui/does-not-have-iter-separated.stderr | 2 +- tests/ui/does-not-have-iter.stderr | 2 +- tests/ui/not-quotable.rs | 2 +- tests/ui/not-quotable.stderr | 12 ++--- tests/ui/not-repeatable.rs | 2 +- tests/ui/not-repeatable.stderr | 6 +-- tests/ui/wrong-type-span.stderr | 10 ++-- 20 files changed, 165 insertions(+), 76 deletions(-) diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 88ac651..d3000ae 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "550af67f9e0be89897902031f153fb3d40360017" + "sha1": "ca98b6594a0bee362a431481ba9ba64e502cc757" }, "path_in_vcs": "" } \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e67515..ed9b799 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ name: CI on: push: pull_request: + workflow_dispatch: schedule: [cron: "40 1 * * *"] permissions: @@ -12,13 +13,18 @@ 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: [stable, beta, 1.56.0] + rust: [nightly, stable, beta, 1.56.0] timeout-minutes: 45 steps: - uses: actions/checkout@v3 @@ -26,23 +32,20 @@ jobs: with: toolchain: ${{matrix.rust}} components: rust-src + - name: Enable type layout randomization + run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV + if: matrix.rust == 'nightly' - run: cargo test - - nightly: - name: Rust nightly - runs-on: ubuntu-latest - timeout-minutes: 45 - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@nightly - with: - components: rust-src - - run: cargo test + - run: cargo run --manifest-path benches/Cargo.toml - run: cargo update -Z minimal-versions + if: matrix.rust == 'nightly' - run: cargo build + if: matrix.rust == 'nightly' msrv: name: Rust 1.31.0 + needs: pre_ci + if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest timeout-minutes: 45 steps: @@ -62,10 +65,12 @@ jobs: - uses: dtolnay/rust-toolchain@nightly with: components: clippy, rust-src - - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic + - run: cargo clippy --tests --workspace -- -Dclippy::all -Dclippy::pedantic miri: name: Miri + needs: pre_ci + if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest timeout-minutes: 45 steps: diff --git a/Android.bp b/Android.bp index 4709e22..7d223c0 100644 --- a/Android.bp +++ b/Android.bp @@ -41,7 +41,7 @@ rust_library_host { name: "libquote", crate_name: "quote", cargo_env_compat: true, - cargo_pkg_version: "1.0.23", + cargo_pkg_version: "1.0.26", srcs: ["src/lib.rs"], edition: "2018", features: [ diff --git a/Cargo.toml b/Cargo.toml index 4d6b326..734042f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" rust-version = "1.31" name = "quote" -version = "1.0.23" +version = "1.0.26" authors = ["David Tolnay "] autobenches = false description = "Quasi-quoting macro quote!(...)" @@ -34,7 +34,7 @@ targets = ["x86_64-unknown-linux-gnu"] doc-scrape-examples = false [dependencies.proc-macro2] -version = "1.0.40" +version = "1.0.52" default-features = false [dev-dependencies.rustversion] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index f99b48f..d8b4fe1 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "quote" -version = "1.0.23" # don't forget to update html_root_url, version in readme for breaking changes +version = "1.0.26" # don't forget to update html_root_url, version in readme for breaking changes authors = ["David Tolnay "] autobenches = false categories = ["development-tools::procedural-macro-helpers"] @@ -13,7 +13,7 @@ repository = "https://github.com/dtolnay/quote" rust-version = "1.31" [dependencies] -proc-macro2 = { version = "1.0.40", default-features = false } +proc-macro2 = { version = "1.0.52", default-features = false } [dev-dependencies] rustversion = "1.0" 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/METADATA b/METADATA index 3297eb7..38220d6 100644 --- a/METADATA +++ b/METADATA @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/quote/quote-1.0.23.crate" + value: "https://static.crates.io/crates/quote/quote-1.0.26.crate" } - version: "1.0.23" + version: "1.0.26" license_type: NOTICE last_upgrade_date { year: 2023 - month: 2 - day: 6 + month: 3 + day: 20 } } diff --git a/src/lib.rs b/src/lib.rs index adc14c5..ab8c1b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,7 +81,7 @@ //! ``` // Quote types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/quote/1.0.23")] +#![doc(html_root_url = "https://docs.rs/quote/1.0.26")] #![allow( clippy::doc_markdown, clippy::missing_errors_doc, @@ -619,14 +619,14 @@ macro_rules! quote_spanned { #[macro_export] macro_rules! quote_spanned { ($span:expr=>) => {{ - let _: $crate::__private::Span = $span; + let _: $crate::__private::Span = $crate::__private::get_span($span).__into_span(); $crate::__private::TokenStream::new() }}; // Special case rule for a single tt, for performance. ($span:expr=> $tt:tt) => {{ let mut _s = $crate::__private::TokenStream::new(); - let _span: $crate::__private::Span = $span; + let _span: $crate::__private::Span = $crate::__private::get_span($span).__into_span(); $crate::quote_token_spanned!{$tt _s _span} _s }}; @@ -634,13 +634,13 @@ macro_rules! quote_spanned { // Special case rules for two tts, for performance. ($span:expr=> # $var:ident) => {{ let mut _s = $crate::__private::TokenStream::new(); - let _: $crate::__private::Span = $span; + let _: $crate::__private::Span = $crate::__private::get_span($span).__into_span(); $crate::ToTokens::to_tokens(&$var, &mut _s); _s }}; ($span:expr=> $tt1:tt $tt2:tt) => {{ let mut _s = $crate::__private::TokenStream::new(); - let _span: $crate::__private::Span = $span; + let _span: $crate::__private::Span = $crate::__private::get_span($span).__into_span(); $crate::quote_token_spanned!{$tt1 _s _span} $crate::quote_token_spanned!{$tt2 _s _span} _s @@ -649,7 +649,7 @@ macro_rules! quote_spanned { // Rule for any other number of tokens. ($span:expr=> $($tt:tt)*) => {{ let mut _s = $crate::__private::TokenStream::new(); - let _span: $crate::__private::Span = $span; + let _span: $crate::__private::Span = $crate::__private::get_span($span).__into_span(); $crate::quote_each_token_spanned!{_s _span $($tt)*} _s }}; diff --git a/src/runtime.rs b/src/runtime.rs index f3cdded..4e3d4fd 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -1,10 +1,12 @@ +use self::get_span::{GetSpan, GetSpanBase, GetSpanInner}; use crate::{IdentFragment, ToTokens, TokenStreamExt}; use core::fmt; use core::iter; use core::ops::BitOr; +use proc_macro2::{Group, Ident, Punct, Spacing, TokenTree}; pub use core::option::Option; -pub use proc_macro2::*; +pub use proc_macro2::{Delimiter, Span, TokenStream}; pub use std::format; pub struct HasIterator; // True @@ -164,6 +166,62 @@ impl ToTokens for RepInterp { } } +#[inline] +pub fn get_span(span: T) -> GetSpan { + GetSpan(GetSpanInner(GetSpanBase(span))) +} + +mod get_span { + use core::ops::Deref; + use proc_macro2::extra::DelimSpan; + use proc_macro2::Span; + + pub struct GetSpan(pub(crate) GetSpanInner); + + pub struct GetSpanInner(pub(crate) GetSpanBase); + + pub struct GetSpanBase(pub(crate) T); + + impl GetSpan { + #[inline] + pub fn __into_span(self) -> Span { + ((self.0).0).0 + } + } + + impl GetSpanInner { + #[inline] + pub fn __into_span(&self) -> Span { + (self.0).0.join() + } + } + + impl GetSpanBase { + #[allow(clippy::unused_self)] + pub fn __into_span(&self) -> T { + unreachable!() + } + } + + impl Deref for GetSpan { + type Target = GetSpanInner; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.0 + } + } + + impl Deref for GetSpanInner { + type Target = GetSpanBase; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.0 + } + } +} + pub fn push_group(tokens: &mut TokenStream, delimiter: Delimiter, inner: TokenStream) { tokens.append(Group::new(delimiter, inner)); } diff --git a/src/spanned.rs b/src/spanned.rs index f64c8f5..efc2e8b 100644 --- a/src/spanned.rs +++ b/src/spanned.rs @@ -1,7 +1,9 @@ use crate::ToTokens; +use proc_macro2::extra::DelimSpan; use proc_macro2::{Span, TokenStream}; -pub trait Spanned { +// Not public API other than via the syn crate. Use syn::spanned::Spanned. +pub trait Spanned: private::Sealed { fn __span(&self) -> Span; } @@ -11,6 +13,12 @@ impl Spanned for Span { } } +impl Spanned for DelimSpan { + fn __span(&self) -> Span { + self.join() + } +} + impl Spanned for T { fn __span(&self) -> Span { join_spans(self.into_token_stream()) @@ -41,3 +49,14 @@ fn join_spans(tokens: TokenStream) -> Span { .and_then(|last| first.join(last)) .unwrap_or(first) } + +mod private { + use crate::ToTokens; + use proc_macro2::extra::DelimSpan; + use proc_macro2::Span; + + pub trait Sealed {} + impl Sealed for Span {} + impl Sealed for DelimSpan {} + impl Sealed for T {} +} diff --git a/tests/test.rs b/tests/test.rs index 52ec7bc..eab4f55 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,14 +1,17 @@ #![allow( clippy::disallowed_names, + clippy::let_underscore_untyped, clippy::shadow_unrelated, clippy::unseparated_literal_suffix, clippy::used_underscore_binding )] +extern crate proc_macro; + use std::borrow::Cow; use std::collections::BTreeSet; -use proc_macro2::{Ident, Span, TokenStream}; +use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream}; use quote::{format_ident, quote, quote_spanned, TokenStreamExt}; struct X; @@ -517,3 +520,30 @@ fn test_quote_raw_id() { let id = quote!(r#raw_id); assert_eq!(id.to_string(), "r#raw_id"); } + +#[test] +fn test_type_inference_for_span() { + trait CallSite { + fn get() -> Self; + } + + impl CallSite for Span { + fn get() -> Self { + Span::call_site() + } + } + + let span = Span::call_site(); + let _ = quote_spanned!(span=> ...); + + let delim_span = Group::new(Delimiter::Parenthesis, TokenStream::new()).delim_span(); + let _ = quote_spanned!(delim_span=> ...); + + let inferred = CallSite::get(); + let _ = quote_spanned!(inferred=> ...); + + if false { + let proc_macro_span = proc_macro::Span::call_site(); + let _ = quote_spanned!(proc_macro_span.into()=> ...); + } +} diff --git a/tests/ui/does-not-have-iter-interpolated-dup.stderr b/tests/ui/does-not-have-iter-interpolated-dup.stderr index 8087879..57d8bf0 100644 --- a/tests/ui/does-not-have-iter-interpolated-dup.stderr +++ b/tests/ui/does-not-have-iter-interpolated-dup.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types 8 | quote!(#(#nonrep #nonrep)*); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | expected struct `HasIterator`, found struct `ThereIsNoIteratorInRepetition` + | expected `HasIterator`, found `ThereIsNoIteratorInRepetition` | expected due to this | = note: this error originates in the macro `$crate::quote_token_with_context` which comes from the expansion of the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/does-not-have-iter-interpolated.stderr b/tests/ui/does-not-have-iter-interpolated.stderr index 2dcf206..8ec2d40 100644 --- a/tests/ui/does-not-have-iter-interpolated.stderr +++ b/tests/ui/does-not-have-iter-interpolated.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types 8 | quote!(#(#nonrep)*); | ^^^^^^^^^^^^^^^^^^^ | | - | expected struct `HasIterator`, found struct `ThereIsNoIteratorInRepetition` + | expected `HasIterator`, found `ThereIsNoIteratorInRepetition` | expected due to this | = note: this error originates in the macro `$crate::quote_token_with_context` which comes from the expansion of the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/does-not-have-iter-separated.stderr b/tests/ui/does-not-have-iter-separated.stderr index 87a19fe..7c6e30f 100644 --- a/tests/ui/does-not-have-iter-separated.stderr +++ b/tests/ui/does-not-have-iter-separated.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types 4 | quote!(#(a b),*); | ^^^^^^^^^^^^^^^^ | | - | expected struct `HasIterator`, found struct `ThereIsNoIteratorInRepetition` + | expected `HasIterator`, found `ThereIsNoIteratorInRepetition` | expected due to this | = note: this error originates in the macro `$crate::quote_token_with_context` which comes from the expansion of the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/does-not-have-iter.stderr b/tests/ui/does-not-have-iter.stderr index 32aa62d..0b13e5c 100644 --- a/tests/ui/does-not-have-iter.stderr +++ b/tests/ui/does-not-have-iter.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types 4 | quote!(#(a b)*); | ^^^^^^^^^^^^^^^ | | - | expected struct `HasIterator`, found struct `ThereIsNoIteratorInRepetition` + | expected `HasIterator`, found `ThereIsNoIteratorInRepetition` | expected due to this | = note: this error originates in the macro `$crate::quote_token_with_context` which comes from the expansion of the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/not-quotable.rs b/tests/ui/not-quotable.rs index 220542d..f991c18 100644 --- a/tests/ui/not-quotable.rs +++ b/tests/ui/not-quotable.rs @@ -3,5 +3,5 @@ use std::net::Ipv4Addr; fn main() { let ip = Ipv4Addr::LOCALHOST; - _ = quote! { #ip }; + let _ = quote! { #ip }; } diff --git a/tests/ui/not-quotable.stderr b/tests/ui/not-quotable.stderr index c323d99..79d4654 100644 --- a/tests/ui/not-quotable.stderr +++ b/tests/ui/not-quotable.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `Ipv4Addr: ToTokens` is not satisfied - --> tests/ui/not-quotable.rs:6:9 + --> tests/ui/not-quotable.rs:6:13 | -6 | _ = quote! { #ip }; - | ^^^^^^^^^^^^^^ - | | - | the trait `ToTokens` is not implemented for `Ipv4Addr` - | required by a bound introduced by this call +6 | let _ = quote! { #ip }; + | ^^^^^^^^^^^^^^ + | | + | the trait `ToTokens` is not implemented for `Ipv4Addr` + | required by a bound introduced by this call | = help: the following other types implement trait `ToTokens`: &'a T diff --git a/tests/ui/not-repeatable.rs b/tests/ui/not-repeatable.rs index c1debf5..a8f0fe7 100644 --- a/tests/ui/not-repeatable.rs +++ b/tests/ui/not-repeatable.rs @@ -4,5 +4,5 @@ struct Ipv4Addr; fn main() { let ip = Ipv4Addr; - _ = quote! { #(#ip)* }; + let _ = quote! { #(#ip)* }; } diff --git a/tests/ui/not-repeatable.stderr b/tests/ui/not-repeatable.stderr index 264a89f..2ed1da0 100644 --- a/tests/ui/not-repeatable.stderr +++ b/tests/ui/not-repeatable.stderr @@ -1,5 +1,5 @@ error[E0599]: the method `quote_into_iter` exists for struct `Ipv4Addr`, but its trait bounds were not satisfied - --> tests/ui/not-repeatable.rs:7:9 + --> tests/ui/not-repeatable.rs:7:13 | 3 | struct Ipv4Addr; | --------------- @@ -10,8 +10,8 @@ error[E0599]: the method `quote_into_iter` exists for struct `Ipv4Addr`, but its | doesn't satisfy `Ipv4Addr: ext::RepIteratorExt` | doesn't satisfy `Ipv4Addr: ext::RepToTokensExt` ... -7 | _ = quote! { #(#ip)* }; - | ^^^^^^^^^^^^^^^^^^ method cannot be called on `Ipv4Addr` due to unsatisfied trait bounds +7 | let _ = quote! { #(#ip)* }; + | ^^^^^^^^^^^^^^^^^^ method cannot be called on `Ipv4Addr` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `Ipv4Addr: Iterator` diff --git a/tests/ui/wrong-type-span.stderr b/tests/ui/wrong-type-span.stderr index c774a4c..12ad307 100644 --- a/tests/ui/wrong-type-span.stderr +++ b/tests/ui/wrong-type-span.stderr @@ -1,8 +1,10 @@ error[E0308]: mismatched types - --> tests/ui/wrong-type-span.rs:6:20 + --> tests/ui/wrong-type-span.rs:6:5 | 6 | quote_spanned!(span=> #x); - | ---------------^^^^------ - | | | - | | expected struct `Span`, found `&str` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected `Span`, found `&str` | expected due to this + | + = note: this error originates in the macro `quote_spanned` (in Nightly builds, run with -Z macro-backtrace for more info) -- cgit v1.2.3