aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2020-05-22 00:20:05 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-05-22 00:20:05 +0000
commit0266b748f1e418f1dcdf58036f1bb48ae3e9a2f1 (patch)
tree54f723da1999bf63cb6da22d725d4b2874960936
parent373484eedd502992d38cef30268c1eaa8a2cd8bf (diff)
parentb277046cfc22b8e2d4200fddfc17e1a8827ec204 (diff)
downloadquote-0266b748f1e418f1dcdf58036f1bb48ae3e9a2f1.tar.gz
Upgrade rust/crates/quote to 1.0.6 am: 73bab92726 am: 0fd496fa28 am: b277046cfc
Change-Id: I8fcbd3bf6000b947a13e49d29f5084e37b652822
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA4
-rw-r--r--README.md32
-rw-r--r--src/ident_fragment.rs14
-rw-r--r--src/lib.rs2
-rw-r--r--tests/test.rs2
8 files changed, 50 insertions, 10 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index cb4ee7b..067bf7b 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
{
"git": {
- "sha1": "b4f1671357770f8422a0b4d5e299267d0c48fd97"
+ "sha1": "d67d687aebbc7d6f1692951a15ffff5cb2c33673"
}
}
diff --git a/Cargo.toml b/Cargo.toml
index c9e1d15..6a004f9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "quote"
-version = "1.0.5"
+version = "1.0.6"
authors = ["David Tolnay <dtolnay@gmail.com>"]
include = ["Cargo.toml", "src/**/*.rs", "tests/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
description = "Quasi-quoting macro quote!(...)"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 1153bbb..793de24 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "quote"
-version = "1.0.5" # don't forget to update html_root_url, version in readme for breaking changes
+version = "1.0.6" # don't forget to update html_root_url, version in readme for breaking changes
authors = ["David Tolnay <dtolnay@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "Quasi-quoting macro quote!(...)"
diff --git a/METADATA b/METADATA
index 401eaa8..6cef131 100644
--- a/METADATA
+++ b/METADATA
@@ -9,11 +9,11 @@ third_party {
type: GIT
value: "https://github.com/dtolnay/quote"
}
- version: "1.0.5"
+ version: "1.0.6"
license_type: NOTICE
last_upgrade_date {
year: 2020
month: 5
- day: 13
+ day: 18
}
}
diff --git a/README.md b/README.md
index dce12f7..57b2a62 100644
--- a/README.md
+++ b/README.md
@@ -29,15 +29,16 @@ This crate is motivated by the procedural macro use case, but is a
general-purpose Rust quasi-quoting library and is not specific to procedural
macros.
-*Version requirement: Quote supports rustc 1.31 and up.*
-
-[*Release notes*](https://github.com/dtolnay/quote/releases)
-
```toml
[dependencies]
quote = "1.0"
```
+*Version requirement: Quote supports rustc 1.31 and up.*<br>
+[*Release notes*](https://github.com/dtolnay/quote/releases)
+
+<br>
+
## Syntax
The quote crate provides a [`quote!`] macro within which you can write Rust code
@@ -76,6 +77,8 @@ let tokens = quote! {
};
```
+<br>
+
## Repetition
Repetition is done using `#(...)*` or `#(...),*` similar to `macro_rules!`. This
@@ -93,6 +96,8 @@ Note that there is a difference between `#(#var ,)*` and `#(#var),*`—the latte
does not produce a trailing comma. This matches the behavior of delimiters in
`macro_rules!`.
+<br>
+
## Returning tokens to the compiler
The `quote!` macro evaluates to an expression of type
@@ -112,6 +117,8 @@ There is a [`From`]-conversion in both directions so returning the output of
[`From`]: https://doc.rust-lang.org/std/convert/trait.From.html
+<br>
+
## Examples
### Combining quoted fragments
@@ -206,6 +213,8 @@ quote! {
}
```
+<br>
+
## Hygiene
Any interpolated tokens preserve the `Span` information provided by their
@@ -221,6 +230,21 @@ macro.
<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 [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.
+
+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
+
+<br>
+
#### License
<sup>
diff --git a/src/ident_fragment.rs b/src/ident_fragment.rs
index c8198cc..e7472fe 100644
--- a/src/ident_fragment.rs
+++ b/src/ident_fragment.rs
@@ -1,4 +1,5 @@
use proc_macro2::{Ident, Span};
+use std::borrow::Cow;
use std::fmt;
/// Specialized formatting trait used by `format_ident!`.
@@ -54,6 +55,19 @@ impl IdentFragment for Ident {
}
}
+impl<T> IdentFragment for Cow<'_, T>
+where
+ T: IdentFragment + ToOwned + ?Sized,
+{
+ fn span(&self) -> Option<Span> {
+ T::span(self)
+ }
+
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ T::fmt(self, f)
+ }
+}
+
// Limited set of types which this is implemented for, as we want to avoid types
// which will often include non-identifier characters in their `Display` impl.
macro_rules! ident_fragment_display {
diff --git a/src/lib.rs b/src/lib.rs
index 7339134..dd7ef3c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -83,7 +83,7 @@
#![forbid(unsafe_code)]
// Quote types in rustdoc of other crates get linked to here.
-#![doc(html_root_url = "https://docs.rs/quote/1.0.5")]
+#![doc(html_root_url = "https://docs.rs/quote/1.0.6")]
#[cfg(all(
not(all(target_arch = "wasm32", target_os = "unknown")),
diff --git a/tests/test.rs b/tests/test.rs
index be2b66b..df857fd 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -341,12 +341,14 @@ fn test_format_ident() {
let id2 = format_ident!("Hello{x}", x = 5usize);
let id3 = format_ident!("Hello{}_{x}", id0, x = 10usize);
let id4 = format_ident!("Aa", span = Span::call_site());
+ let id5 = format_ident!("Hello{}", Cow::Borrowed("World"));
assert_eq!(id0, "Aa");
assert_eq!(id1, "HelloAa");
assert_eq!(id2, "Hello5");
assert_eq!(id3, "HelloAa_10");
assert_eq!(id4, "Aa");
+ assert_eq!(id5, "HelloWorld");
}
#[test]