aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Maurer <mmaurer@google.com>2023-05-27 00:57:49 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-05-27 00:57:49 +0000
commit8f3a4d8f2ff1548637167da1089bd7398a276d27 (patch)
tree563f66aad4288194e7c8fdc3bf4b41d2759b8b10
parentab71c22418a2844cf119ca04d86f380c53e549bf (diff)
parentd076a8b19b5f612c30bb7597f1b4b089f9e38929 (diff)
downloadquote-8f3a4d8f2ff1548637167da1089bd7398a276d27.tar.gz
Upgrade quote to 1.0.26 am: ecb5eb34a8 am: 9791b3d2d9 am: 3258971c13 am: d076a8b19b
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/quote/+/2498775 Change-Id: I927e4f9f4837e0e812ba564daad5847513542465 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.github/workflows/ci.yml31
-rw-r--r--Android.bp2
-rw-r--r--Cargo.toml4
-rw-r--r--Cargo.toml.orig4
-rw-r--r--LICENSE-APACHE25
-rw-r--r--METADATA8
-rw-r--r--src/lib.rs12
-rw-r--r--src/runtime.rs60
-rw-r--r--src/spanned.rs21
-rw-r--r--tests/test.rs32
-rw-r--r--tests/ui/does-not-have-iter-interpolated-dup.stderr2
-rw-r--r--tests/ui/does-not-have-iter-interpolated.stderr2
-rw-r--r--tests/ui/does-not-have-iter-separated.stderr2
-rw-r--r--tests/ui/does-not-have-iter.stderr2
-rw-r--r--tests/ui/not-quotable.rs2
-rw-r--r--tests/ui/not-quotable.stderr12
-rw-r--r--tests/ui/not-repeatable.rs2
-rw-r--r--tests/ui/not-repeatable.stderr6
-rw-r--r--tests/ui/wrong-type-span.stderr10
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 <dtolnay@gmail.com>"]
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 <dtolnay@gmail.com>"]
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<T: ToTokens> ToTokens for RepInterp<T> {
}
}
+#[inline]
+pub fn get_span<T>(span: T) -> GetSpan<T> {
+ GetSpan(GetSpanInner(GetSpanBase(span)))
+}
+
+mod get_span {
+ use core::ops::Deref;
+ use proc_macro2::extra::DelimSpan;
+ use proc_macro2::Span;
+
+ pub struct GetSpan<T>(pub(crate) GetSpanInner<T>);
+
+ pub struct GetSpanInner<T>(pub(crate) GetSpanBase<T>);
+
+ pub struct GetSpanBase<T>(pub(crate) T);
+
+ impl GetSpan<Span> {
+ #[inline]
+ pub fn __into_span(self) -> Span {
+ ((self.0).0).0
+ }
+ }
+
+ impl GetSpanInner<DelimSpan> {
+ #[inline]
+ pub fn __into_span(&self) -> Span {
+ (self.0).0.join()
+ }
+ }
+
+ impl<T> GetSpanBase<T> {
+ #[allow(clippy::unused_self)]
+ pub fn __into_span(&self) -> T {
+ unreachable!()
+ }
+ }
+
+ impl<T> Deref for GetSpan<T> {
+ type Target = GetSpanInner<T>;
+
+ #[inline]
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+ }
+
+ impl<T> Deref for GetSpanInner<T> {
+ type Target = GetSpanBase<T>;
+
+ #[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<T: ?Sized + ToTokens> 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<T: ?Sized + ToTokens> 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)