aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharisee <chiw@google.com>2023-10-16 19:52:37 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-10-16 19:52:37 +0000
commit985a8ee7548d2707e3f522e039cfe7265b11f77c (patch)
tree2f156db06732ed2e2c740cb649f1de94702ef311
parentc10466a0c1a129459bd4e2147daf8df34194ac32 (diff)
parentefc77a30fa667f3a6cf217cf522784851d21a2fd (diff)
downloadquote-985a8ee7548d2707e3f522e039cfe7265b11f77c.tar.gz
Update quote crate 1.0.33 am: 5a4e5901d4 am: efc77a30fa
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/quote/+/2787703 Change-Id: If7c3f39588a3f2664089ad2164c5d313447f07f8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--Cargo.toml7
-rw-r--r--README.md23
-rw-r--r--src/ident_fragment.rs8
-rw-r--r--src/lib.rs20
-rw-r--r--src/runtime.rs44
-rw-r--r--src/spanned.rs12
-rw-r--r--src/to_tokens.rs4
-rw-r--r--tests/ui/does-not-have-iter-interpolated-dup.stderr1
-rw-r--r--tests/ui/does-not-have-iter-interpolated.stderr1
-rw-r--r--tests/ui/not-quotable.stderr18
10 files changed, 93 insertions, 45 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 734042f..4dbf7ab 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,9 +11,9 @@
[package]
edition = "2018"
-rust-version = "1.31"
+rust-version = "1.56"
name = "quote"
-version = "1.0.26"
+version = "1.0.33"
authors = ["David Tolnay <dtolnay@gmail.com>"]
autobenches = false
description = "Quasi-quoting macro quote!(...)"
@@ -28,13 +28,14 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/quote"
[package.metadata.docs.rs]
+rustdoc-args = ["--generate-link-to-definition"]
targets = ["x86_64-unknown-linux-gnu"]
[lib]
doc-scrape-examples = false
[dependencies.proc-macro2]
-version = "1.0.52"
+version = "1.0.66"
default-features = false
[dev-dependencies.rustversion]
diff --git a/README.md b/README.md
index 74e99ce..bfc91a9 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ macros.
quote = "1.0"
```
-*Version requirement: Quote supports rustc 1.31 and up.*<br>
+*Version requirement: Quote supports rustc 1.56 and up.*<br>
[*Release notes*](https://github.com/dtolnay/quote/releases)
<br>
@@ -233,15 +233,26 @@ macro.
## Non-macro code generators
When using `quote` in a build.rs or main.rs and writing the output out to a
-file, consider having the code generator pass the tokens through [rustfmt]
-before writing (either by shelling out to the `rustfmt` binary or by pulling in
-the `rustfmt` library as a dependency). This way if an error occurs in the
-generated code it is convenient for a human to read and debug.
+file, consider having the code generator pass the tokens through [prettyplease]
+before writing. This way if an error occurs in the generated code it is
+convenient for a human to read and debug.
Be aware that no kind of hygiene or span information is retained when tokens are
written to a file; the conversion from tokens to source code is lossy.
-[rustfmt]: https://github.com/rust-lang/rustfmt
+Example usage in build.rs:
+
+```rust
+let output = quote! { ... };
+let syntax_tree = syn::parse2(output).unwrap();
+let formatted = prettyplease::unparse(&syntax_tree);
+
+let out_dir = env::var_os("OUT_DIR").unwrap();
+let dest_path = Path::new(&out_dir).join("out.rs");
+fs::write(dest_path, formatted).unwrap();
+```
+
+[prettyplease]: https://github.com/dtolnay/prettyplease
<br>
diff --git a/src/ident_fragment.rs b/src/ident_fragment.rs
index cf74024..6c2a9a8 100644
--- a/src/ident_fragment.rs
+++ b/src/ident_fragment.rs
@@ -1,6 +1,6 @@
+use alloc::borrow::Cow;
use core::fmt;
use proc_macro2::{Ident, Span};
-use std::borrow::Cow;
/// Specialized formatting trait used by `format_ident!`.
///
@@ -8,6 +8,8 @@ use std::borrow::Cow;
/// stripped, if present.
///
/// See [`format_ident!`] for more information.
+///
+/// [`format_ident!`]: crate::format_ident
pub trait IdentFragment {
/// Format this value as an identifier fragment.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result;
@@ -47,8 +49,8 @@ impl IdentFragment for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let id = self.to_string();
- if id.starts_with("r#") {
- fmt::Display::fmt(&id[2..], f)
+ if let Some(id) = id.strip_prefix("r#") {
+ fmt::Display::fmt(id, f)
} else {
fmt::Display::fmt(&id[..], f)
}
diff --git a/src/lib.rs b/src/lib.rs
index ab8c1b1..47167d3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -79,9 +79,20 @@
//! }
//! };
//! ```
+//!
+//! <br>
+//!
+//! # Non-macro code generators
+//!
+//! When using `quote` in a build.rs or main.rs and writing the output out to a
+//! file, consider having the code generator pass the tokens through
+//! [prettyplease] before writing. This way if an error occurs in the generated
+//! code it is convenient for a human to read and debug.
+//!
+//! [prettyplease]: https://github.com/dtolnay/prettyplease
// Quote types in rustdoc of other crates get linked to here.
-#![doc(html_root_url = "https://docs.rs/quote/1.0.26")]
+#![doc(html_root_url = "https://docs.rs/quote/1.0.33")]
#![allow(
clippy::doc_markdown,
clippy::missing_errors_doc,
@@ -91,10 +102,9 @@
clippy::wrong_self_convention,
)]
-#[cfg(all(
- not(all(target_arch = "wasm32", target_os = "unknown")),
- feature = "proc-macro"
-))]
+extern crate alloc;
+
+#[cfg(feature = "proc-macro")]
extern crate proc_macro;
mod ext;
diff --git a/src/runtime.rs b/src/runtime.rs
index 4e3d4fd..eff044a 100644
--- a/src/runtime.rs
+++ b/src/runtime.rs
@@ -5,11 +5,21 @@ use core::iter;
use core::ops::BitOr;
use proc_macro2::{Group, Ident, Punct, Spacing, TokenTree};
+#[doc(hidden)]
+pub use alloc::format;
+#[doc(hidden)]
pub use core::option::Option;
-pub use proc_macro2::{Delimiter, Span, TokenStream};
-pub use std::format;
+#[doc(hidden)]
+pub type Delimiter = proc_macro2::Delimiter;
+#[doc(hidden)]
+pub type Span = proc_macro2::Span;
+#[doc(hidden)]
+pub type TokenStream = proc_macro2::TokenStream;
+
+#[doc(hidden)]
pub struct HasIterator; // True
+#[doc(hidden)]
pub struct ThereIsNoIteratorInRepetition; // False
impl BitOr<ThereIsNoIteratorInRepetition> for ThereIsNoIteratorInRepetition {
@@ -46,14 +56,16 @@ impl BitOr<HasIterator> for HasIterator {
/// These traits expose a `quote_into_iter` method which should allow calling
/// whichever impl happens to be applicable. Calling that method repeatedly on
/// the returned value should be idempotent.
+#[doc(hidden)]
pub mod ext {
use super::RepInterp;
use super::{HasIterator as HasIter, ThereIsNoIteratorInRepetition as DoesNotHaveIter};
use crate::ToTokens;
+ use alloc::collections::btree_set::{self, BTreeSet};
use core::slice;
- use std::collections::btree_set::{self, BTreeSet};
/// Extension trait providing the `quote_into_iter` method on iterators.
+ #[doc(hidden)]
pub trait RepIteratorExt: Iterator + Sized {
fn quote_into_iter(self) -> (Self, HasIter) {
(self, HasIter)
@@ -65,6 +77,7 @@ pub mod ext {
/// Extension trait providing the `quote_into_iter` method for
/// non-iterable types. These types interpolate the same value in each
/// iteration of the repetition.
+ #[doc(hidden)]
pub trait RepToTokensExt {
/// Pretend to be an iterator for the purposes of `quote_into_iter`.
/// This allows repeated calls to `quote_into_iter` to continue
@@ -82,6 +95,7 @@ pub mod ext {
/// Extension trait providing the `quote_into_iter` method for types that
/// can be referenced as an iterator.
+ #[doc(hidden)]
pub trait RepAsIteratorExt<'q> {
type Iter: Iterator;
@@ -140,6 +154,7 @@ pub mod ext {
// Helper type used within interpolations to allow for repeated binding names.
// Implements the relevant traits, and exports a dummy `next()` method.
#[derive(Copy, Clone)]
+#[doc(hidden)]
pub struct RepInterp<T>(pub T);
impl<T> RepInterp<T> {
@@ -166,6 +181,7 @@ impl<T: ToTokens> ToTokens for RepInterp<T> {
}
}
+#[doc(hidden)]
#[inline]
pub fn get_span<T>(span: T) -> GetSpan<T> {
GetSpan(GetSpanInner(GetSpanBase(span)))
@@ -222,10 +238,12 @@ mod get_span {
}
}
+#[doc(hidden)]
pub fn push_group(tokens: &mut TokenStream, delimiter: Delimiter, inner: TokenStream) {
tokens.append(Group::new(delimiter, inner));
}
+#[doc(hidden)]
pub fn push_group_spanned(
tokens: &mut TokenStream,
span: Span,
@@ -237,11 +255,13 @@ pub fn push_group_spanned(
tokens.append(g);
}
+#[doc(hidden)]
pub fn parse(tokens: &mut TokenStream, s: &str) {
let s: TokenStream = s.parse().expect("invalid token stream");
tokens.extend(iter::once(s));
}
+#[doc(hidden)]
pub fn parse_spanned(tokens: &mut TokenStream, span: Span, s: &str) {
let s: TokenStream = s.parse().expect("invalid token stream");
tokens.extend(s.into_iter().map(|t| respan_token_tree(t, span)));
@@ -264,15 +284,18 @@ fn respan_token_tree(mut token: TokenTree, span: Span) -> TokenTree {
token
}
+#[doc(hidden)]
pub fn push_ident(tokens: &mut TokenStream, s: &str) {
let span = Span::call_site();
push_ident_spanned(tokens, span, s);
}
+#[doc(hidden)]
pub fn push_ident_spanned(tokens: &mut TokenStream, span: Span, s: &str) {
tokens.append(ident_maybe_raw(s, span));
}
+#[doc(hidden)]
pub fn push_lifetime(tokens: &mut TokenStream, lifetime: &str) {
struct Lifetime<'a> {
name: &'a str,
@@ -303,6 +326,7 @@ pub fn push_lifetime(tokens: &mut TokenStream, lifetime: &str) {
});
}
+#[doc(hidden)]
pub fn push_lifetime_spanned(tokens: &mut TokenStream, span: Span, lifetime: &str) {
struct Lifetime<'a> {
name: &'a str,
@@ -339,9 +363,11 @@ pub fn push_lifetime_spanned(tokens: &mut TokenStream, span: Span, lifetime: &st
macro_rules! push_punct {
($name:ident $spanned:ident $char1:tt) => {
+ #[doc(hidden)]
pub fn $name(tokens: &mut TokenStream) {
tokens.append(Punct::new($char1, Spacing::Alone));
}
+ #[doc(hidden)]
pub fn $spanned(tokens: &mut TokenStream, span: Span) {
let mut punct = Punct::new($char1, Spacing::Alone);
punct.set_span(span);
@@ -349,10 +375,12 @@ macro_rules! push_punct {
}
};
($name:ident $spanned:ident $char1:tt $char2:tt) => {
+ #[doc(hidden)]
pub fn $name(tokens: &mut TokenStream) {
tokens.append(Punct::new($char1, Spacing::Joint));
tokens.append(Punct::new($char2, Spacing::Alone));
}
+ #[doc(hidden)]
pub fn $spanned(tokens: &mut TokenStream, span: Span) {
let mut punct = Punct::new($char1, Spacing::Joint);
punct.set_span(span);
@@ -363,11 +391,13 @@ macro_rules! push_punct {
}
};
($name:ident $spanned:ident $char1:tt $char2:tt $char3:tt) => {
+ #[doc(hidden)]
pub fn $name(tokens: &mut TokenStream) {
tokens.append(Punct::new($char1, Spacing::Joint));
tokens.append(Punct::new($char2, Spacing::Joint));
tokens.append(Punct::new($char3, Spacing::Alone));
}
+ #[doc(hidden)]
pub fn $spanned(tokens: &mut TokenStream, span: Span) {
let mut punct = Punct::new($char1, Spacing::Joint);
punct.set_span(span);
@@ -427,24 +457,27 @@ push_punct!(push_star push_star_spanned '*');
push_punct!(push_sub push_sub_spanned '-');
push_punct!(push_sub_eq push_sub_eq_spanned '-' '=');
+#[doc(hidden)]
pub fn push_underscore(tokens: &mut TokenStream) {
push_underscore_spanned(tokens, Span::call_site());
}
+#[doc(hidden)]
pub fn push_underscore_spanned(tokens: &mut TokenStream, span: Span) {
tokens.append(Ident::new("_", span));
}
// Helper method for constructing identifiers from the `format_ident!` macro,
// handling `r#` prefixes.
+#[doc(hidden)]
pub fn mk_ident(id: &str, span: Option<Span>) -> Ident {
let span = span.unwrap_or_else(Span::call_site);
ident_maybe_raw(id, span)
}
fn ident_maybe_raw(id: &str, span: Span) -> Ident {
- if id.starts_with("r#") {
- Ident::new_raw(&id[2..], span)
+ if let Some(id) = id.strip_prefix("r#") {
+ Ident::new_raw(id, span)
} else {
Ident::new(id, span)
}
@@ -457,6 +490,7 @@ fn ident_maybe_raw(id: &str, span: Span) -> Ident {
// `Octal`, `LowerHex`, `UpperHex`, and `Binary` to allow for their use within
// `format_ident!`.
#[derive(Copy, Clone)]
+#[doc(hidden)]
pub struct IdentFragmentAdapter<T: IdentFragment>(pub T);
impl<T: IdentFragment> IdentFragmentAdapter<T> {
diff --git a/src/spanned.rs b/src/spanned.rs
index efc2e8b..6eba644 100644
--- a/src/spanned.rs
+++ b/src/spanned.rs
@@ -26,20 +26,8 @@ impl<T: ?Sized + ToTokens> Spanned for T {
}
fn join_spans(tokens: TokenStream) -> Span {
- #[cfg(not(needs_invalid_span_workaround))]
let mut iter = tokens.into_iter().map(|tt| tt.span());
- #[cfg(needs_invalid_span_workaround)]
- let mut iter = tokens.into_iter().filter_map(|tt| {
- let span = tt.span();
- let debug = format!("{:?}", span);
- if debug.ends_with("bytes(0..0)") {
- None
- } else {
- Some(span)
- }
- });
-
let first = match iter.next() {
Some(span) => span,
None => return Span::call_site(),
diff --git a/src/to_tokens.rs b/src/to_tokens.rs
index 5748721..23b6ec2 100644
--- a/src/to_tokens.rs
+++ b/src/to_tokens.rs
@@ -1,8 +1,8 @@
use super::TokenStreamExt;
+use alloc::borrow::Cow;
+use alloc::rc::Rc;
use core::iter;
use proc_macro2::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree};
-use std::borrow::Cow;
-use std::rc::Rc;
/// Types that can be interpolated inside a `quote!` invocation.
///
diff --git a/tests/ui/does-not-have-iter-interpolated-dup.stderr b/tests/ui/does-not-have-iter-interpolated-dup.stderr
index 57d8bf0..99c20a5 100644
--- a/tests/ui/does-not-have-iter-interpolated-dup.stderr
+++ b/tests/ui/does-not-have-iter-interpolated-dup.stderr
@@ -6,5 +6,6 @@ error[E0308]: mismatched types
| |
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
| expected due to this
+ | here the type of `has_iter` is inferred to be `ThereIsNoIteratorInRepetition`
|
= 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 8ec2d40..ef90813 100644
--- a/tests/ui/does-not-have-iter-interpolated.stderr
+++ b/tests/ui/does-not-have-iter-interpolated.stderr
@@ -6,5 +6,6 @@ error[E0308]: mismatched types
| |
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
| expected due to this
+ | here the type of `has_iter` is inferred to be `ThereIsNoIteratorInRepetition`
|
= 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.stderr b/tests/ui/not-quotable.stderr
index 79d4654..35cb6f2 100644
--- a/tests/ui/not-quotable.stderr
+++ b/tests/ui/not-quotable.stderr
@@ -8,13 +8,13 @@ error[E0277]: the trait bound `Ipv4Addr: ToTokens` is not satisfied
| required by a bound introduced by this call
|
= help: the following other types implement trait `ToTokens`:
- &'a T
- &'a mut T
- Box<T>
- Cow<'a, T>
- Option<T>
- Rc<T>
- RepInterp<T>
- String
- and 23 others
+ bool
+ char
+ isize
+ i8
+ i16
+ i32
+ i64
+ i128
+ and $N others
= note: this error originates in the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info)