mirror of
https://github.com/openharmony/third_party_rust_quote.git
synced 2026-07-01 20:44:02 -04:00
merge master into master
升级到1.0.37 Created-by: dragonswordy Commit-by: ljy9810 Merged-by: openharmony_ci Description: ### 一、内容说明(相关的Issue) https://gitcode.com/openharmony/third_party_rust_memoffset/issues/1 ### 二、建议测试周期和提测地址 建议测试完成时间:xxxx.xx.xx 投产上线时间:xxxx.xx.xx 提测地址:CI环境/压测环境 测试账号: ### 三、变更内容 * 3.1 关联PR列表 * 3.2 数据库和部署说明 1. 常规更新 2. 重启unicorn 3. 重启sidekiq 4. 迁移任务:是否有迁移任务,没有写 "无" 5. rake脚本:`bundle exec xxx RAILS_ENV = production`;没有写 "无" * 3.4 其他技术优化内容(做了什么,变更了什么) - 重构了 xxxx 代码 - xxxx 算法优化 * 3.5 废弃通知(什么字段、方法弃用?) * 3.6 后向不兼容变更(是否有无法向后兼容的变更?) ### 四、研发自测点(自测哪些?冒烟用例全部自测?) 自测测试结论: ### 五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方) 检查点: | 需求名称 | 是否影响xx公共模块 | 是否需要xx功能 | 需求升级是否依赖其他子产品 | |------|------------|----------|---------------| | xxx | 否 | 需要 | 不需要 | | | | | | 接口测试: 性能测试: 并发测试: 其他: See merge request: openharmony/third_party_rust_quote!11
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "b01743f24cb5b19f96a3eac6bce0e7aee10f6199"
|
||||
},
|
||||
"path_in_vcs": ""
|
||||
}
|
||||
@@ -99,5 +99,6 @@ jobs:
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: dtolnay/install@cargo-outdated
|
||||
- run: cargo outdated --workspace --exit-code 1
|
||||
|
||||
@@ -20,7 +20,7 @@ ohos_cargo_crate("lib") {
|
||||
|
||||
sources = [ "src/lib.rs" ]
|
||||
edition = "2018"
|
||||
cargo_pkg_version = "1.0.35"
|
||||
cargo_pkg_version = "1.0.37"
|
||||
cargo_pkg_authors = "David Tolnay <dtolnay@gmail.com>"
|
||||
cargo_pkg_name = "quote"
|
||||
cargo_pkg_description = "Quasi-quoting macro quote!(...)"
|
||||
|
||||
+22
-36
@@ -1,50 +1,36 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
rust-version = "1.56"
|
||||
name = "quote"
|
||||
version = "1.0.35"
|
||||
version = "1.0.37"
|
||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||
autobenches = false
|
||||
categories = ["development-tools::procedural-macro-helpers"]
|
||||
description = "Quasi-quoting macro quote!(...)"
|
||||
documentation = "https://docs.rs/quote/"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"macros",
|
||||
"syn",
|
||||
]
|
||||
categories = ["development-tools::procedural-macro-helpers"]
|
||||
edition = "2018"
|
||||
keywords = ["macros", "syn"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/dtolnay/quote"
|
||||
rust-version = "1.56"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--generate-link-to-definition"]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dependencies]
|
||||
proc-macro2 = { version = "1.0.80", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
rustversion = "1.0"
|
||||
trybuild = { version = "1.0.66", features = ["diff"] }
|
||||
|
||||
[features]
|
||||
default = ["proc-macro"]
|
||||
# Disabling the proc-macro feature removes the dynamic library dependency on
|
||||
# libproc_macro in the rustc compiler.
|
||||
proc-macro = ["proc-macro2/proc-macro"]
|
||||
|
||||
[lib]
|
||||
doc-scrape-examples = false
|
||||
|
||||
[dependencies.proc-macro2]
|
||||
version = "1.0.74"
|
||||
default-features = false
|
||||
[workspace]
|
||||
members = ["benches"]
|
||||
|
||||
[dev-dependencies.rustversion]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.trybuild]
|
||||
version = "1.0.66"
|
||||
features = ["diff"]
|
||||
|
||||
[features]
|
||||
default = ["proc-macro"]
|
||||
proc-macro = ["proc-macro2/proc-macro"]
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
rustdoc-args = ["--generate-link-to-definition"]
|
||||
|
||||
Generated
-36
@@ -1,36 +0,0 @@
|
||||
[package]
|
||||
name = "quote"
|
||||
version = "1.0.35" # 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"]
|
||||
description = "Quasi-quoting macro quote!(...)"
|
||||
documentation = "https://docs.rs/quote/"
|
||||
edition = "2018"
|
||||
keywords = ["macros", "syn"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/dtolnay/quote"
|
||||
rust-version = "1.56"
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = { version = "1.0.74", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
rustversion = "1.0"
|
||||
trybuild = { version = "1.0.66", features = ["diff"] }
|
||||
|
||||
[features]
|
||||
default = ["proc-macro"]
|
||||
# Disabling the proc-macro feature removes the dynamic library dependency on
|
||||
# libproc_macro in the rustc compiler.
|
||||
proc-macro = ["proc-macro2/proc-macro"]
|
||||
|
||||
[lib]
|
||||
doc-scrape-examples = false
|
||||
|
||||
[workspace]
|
||||
members = ["benches"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
rustdoc-args = ["--generate-link-to-definition"]
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
[
|
||||
{
|
||||
"Name": "dtolnay/quote",
|
||||
"Name": "Rust Quasi-Quoting",
|
||||
"License": "Apache License V2.0, MIT",
|
||||
"License File": "LICENSE-APACHE, LICENSE-MIT",
|
||||
"Version Number": "1.0.35",
|
||||
"Version Number": "1.0.37",
|
||||
"Owner": "fangting12@huawei.com",
|
||||
"Upstream URL": "https://github.com/dtolnay/quote",
|
||||
"Description": "A Rust library that provides support for generating Rust code."
|
||||
|
||||
@@ -84,8 +84,7 @@ let tokens = quote! {
|
||||
Repetition is done using `#(...)*` or `#(...),*` similar to `macro_rules!`. This
|
||||
iterates through the elements of any variable interpolated within the repetition
|
||||
and inserts a copy of the repetition body for each one. The variables in an
|
||||
interpolation may be anything that implements `IntoIterator`, including `Vec` or
|
||||
a pre-existing iterator.
|
||||
interpolation may be a `Vec`, slice, `BTreeSet`, or any `Iterator`.
|
||||
|
||||
- `#(#var)*` — no separators
|
||||
- `#(#var),*` — the character before the asterisk is used as a separator
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "quote-benchmark"
|
||||
version = "0.0.0"
|
||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT OR Apache-2.0"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
path = "lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "quote-benchmark"
|
||||
path = "main.rs"
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1.0"
|
||||
quote = { path = ".." }
|
||||
termcolor = "1.1"
|
||||
@@ -0,0 +1,18 @@
|
||||
Example output:
|
||||
|
||||
<pre>
|
||||
$ <b>cargo run && cargo run --release</b>
|
||||
|
||||
<i>Compiling quote v1.0.35</i>
|
||||
<i>Compiling quote-benchmark v0.0.0</i>
|
||||
<kbd><kbd><b>macro in debug mode: 440 micros</b></kbd></kbd>
|
||||
<i>Finished dev [unoptimized + debuginfo] target(s) in 4.39s</i>
|
||||
<i>Running `target/debug/quote-benchmark`</i>
|
||||
<kbd><kbd><b>non-macro in debug mode: 537 micros</b></kbd></kbd>
|
||||
<i>Compiling quote v1.0.35</i>
|
||||
<i>Compiling quote-benchmark v0.0.0</i>
|
||||
<kbd><kbd><b>macro in release mode: 423 micros</b></kbd></kbd>
|
||||
<i>Finished release [optimized] target(s) in 4.00s</i>
|
||||
<i>Running `target/release/quote-benchmark`</i>
|
||||
<kbd><kbd><b>non-macro in release mode: 134 micros</b></kbd></kbd>
|
||||
</pre>
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
#![allow(
|
||||
clippy::cast_lossless,
|
||||
clippy::let_underscore_untyped,
|
||||
clippy::uninlined_format_args
|
||||
)]
|
||||
|
||||
use quote::quote;
|
||||
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! benchmark {
|
||||
(|$ident:ident| $quote:expr) => {
|
||||
mod timer;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Ident;
|
||||
|
||||
#[proc_macro]
|
||||
pub fn run_quote_benchmark(input: TokenStream) -> TokenStream {
|
||||
let input = proc_macro2::TokenStream::from(input);
|
||||
let span = input.into_iter().next().unwrap().span();
|
||||
let $ident = Ident::new("Response", span);
|
||||
timer::time("macro", || proc_macro::TokenStream::from($quote));
|
||||
TokenStream::new()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use benchmark;
|
||||
|
||||
crate::benchmark! {
|
||||
|ident| quote! {
|
||||
impl<'de> _serde::Deserialize<'de> for #ident {
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__field1,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::export::Formatter,
|
||||
) -> _serde::export::fmt::Result {
|
||||
_serde::export::Formatter::write_str(__formatter, "field identifier")
|
||||
}
|
||||
fn visit_u64<__E>(self, __value: u64) -> _serde::export::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::export::Ok(__Field::__field0),
|
||||
1u64 => _serde::export::Ok(__Field::__field1),
|
||||
_ => _serde::export::Err(_serde::de::Error::invalid_value(
|
||||
_serde::de::Unexpected::Unsigned(__value),
|
||||
&"field index 0 <= i < 2",
|
||||
)),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(self, __value: &str) -> _serde::export::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"id" => _serde::export::Ok(__Field::__field0),
|
||||
"s" => _serde::export::Ok(__Field::__field1),
|
||||
_ => _serde::export::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::export::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"id" => _serde::export::Ok(__Field::__field0),
|
||||
b"s" => _serde::export::Ok(__Field::__field1),
|
||||
_ => _serde::export::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de> {
|
||||
marker: _serde::export::PhantomData<#ident>,
|
||||
lifetime: _serde::export::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de> _serde::de::Visitor<'de> for __Visitor<'de> {
|
||||
type Value = #ident;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::export::Formatter,
|
||||
) -> _serde::export::fmt::Result {
|
||||
_serde::export::Formatter::write_str(__formatter, "struct")
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::export::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 =
|
||||
match try!(_serde::de::SeqAccess::next_element::<u64>(&mut __seq)) {
|
||||
_serde::export::Some(__value) => __value,
|
||||
_serde::export::None => {
|
||||
return _serde::export::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"struct with 2 elements",
|
||||
));
|
||||
}
|
||||
};
|
||||
let __field1 =
|
||||
match try!(_serde::de::SeqAccess::next_element::<String>(&mut __seq)) {
|
||||
_serde::export::Some(__value) => __value,
|
||||
_serde::export::None => {
|
||||
return _serde::export::Err(_serde::de::Error::invalid_length(
|
||||
1usize,
|
||||
&"struct with 2 elements",
|
||||
));
|
||||
}
|
||||
};
|
||||
_serde::export::Ok(#ident {
|
||||
id: __field0,
|
||||
s: __field1,
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::export::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: _serde::export::Option<u64> = _serde::export::None;
|
||||
let mut __field1: _serde::export::Option<String> = _serde::export::None;
|
||||
while let _serde::export::Some(__key) =
|
||||
try!(_serde::de::MapAccess::next_key::<__Field>(&mut __map))
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if _serde::export::Option::is_some(&__field0) {
|
||||
return _serde::export::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("id"),
|
||||
);
|
||||
}
|
||||
__field0 = _serde::export::Some(
|
||||
try!(_serde::de::MapAccess::next_value::<u64>(&mut __map)),
|
||||
);
|
||||
}
|
||||
__Field::__field1 => {
|
||||
if _serde::export::Option::is_some(&__field1) {
|
||||
return _serde::export::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("s"),
|
||||
);
|
||||
}
|
||||
__field1 = _serde::export::Some(
|
||||
try!(_serde::de::MapAccess::next_value::<String>(&mut __map)),
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
let _ = try!(_serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(&mut __map));
|
||||
}
|
||||
}
|
||||
}
|
||||
let __field0 = match __field0 {
|
||||
_serde::export::Some(__field0) => __field0,
|
||||
_serde::export::None => try!(_serde::private::de::missing_field("id")),
|
||||
};
|
||||
let __field1 = match __field1 {
|
||||
_serde::export::Some(__field1) => __field1,
|
||||
_serde::export::None => try!(_serde::private::de::missing_field("s")),
|
||||
};
|
||||
_serde::export::Ok(#ident {
|
||||
id: __field0,
|
||||
s: __field1,
|
||||
})
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["id", "s"];
|
||||
_serde::Deserializer::deserialize_struct(
|
||||
__deserializer,
|
||||
stringify!(#ident),
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
marker: _serde::export::PhantomData::<#ident>,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#![allow(unknown_lints, special_module_name)]
|
||||
#![allow(
|
||||
clippy::cast_lossless,
|
||||
clippy::let_underscore_untyped,
|
||||
clippy::uninlined_format_args
|
||||
)]
|
||||
|
||||
quote_benchmark::run_quote_benchmark!(_);
|
||||
|
||||
mod benchmark {
|
||||
macro_rules! benchmark {
|
||||
(|$ident:ident| $quote:expr) => {
|
||||
use proc_macro2::{Ident, Span};
|
||||
|
||||
pub fn quote() -> proc_macro2::TokenStream {
|
||||
let $ident = Ident::new("Response", Span::call_site());
|
||||
$quote
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use benchmark;
|
||||
}
|
||||
|
||||
use benchmark::benchmark;
|
||||
|
||||
mod lib;
|
||||
mod timer;
|
||||
|
||||
fn main() {
|
||||
timer::time("non-macro", lib::quote);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
use std::io::Write;
|
||||
use std::time::Instant;
|
||||
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
||||
|
||||
const ITERATIONS: u32 = 1000;
|
||||
|
||||
pub fn time<T>(name: &'static str, function: impl Fn() -> T) {
|
||||
let begin = Instant::now();
|
||||
for _ in 0..ITERATIONS {
|
||||
let _ = function();
|
||||
}
|
||||
let micros = (begin.elapsed() / ITERATIONS).as_micros();
|
||||
let mode = ["release", "debug"][cfg!(debug_assertions) as usize];
|
||||
let mut writer = StandardStream::stderr(ColorChoice::Auto);
|
||||
let _ = writer.set_color(ColorSpec::new().set_fg(Some(Color::Magenta)));
|
||||
let _ = writeln!(&mut writer, "{} in {} mode: {} micros", name, mode, micros);
|
||||
}
|
||||
+547
-527
File diff suppressed because it is too large
Load Diff
+96
-30
@@ -3,6 +3,7 @@ use alloc::borrow::Cow;
|
||||
use alloc::rc::Rc;
|
||||
use core::iter;
|
||||
use proc_macro2::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree};
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
/// Types that can be interpolated inside a `quote!` invocation.
|
||||
///
|
||||
@@ -106,7 +107,7 @@ impl<T: ?Sized + ToTokens> ToTokens for Rc<T> {
|
||||
|
||||
impl<T: ToTokens> ToTokens for Option<T> {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
if let Some(ref t) = *self {
|
||||
if let Some(t) = self {
|
||||
t.to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
@@ -124,35 +125,88 @@ impl ToTokens for String {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! primitive {
|
||||
($($t:ident => $name:ident)*) => {
|
||||
$(
|
||||
impl ToTokens for $t {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::$name(*self));
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
impl ToTokens for i8 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::i8_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
primitive! {
|
||||
i8 => i8_suffixed
|
||||
i16 => i16_suffixed
|
||||
i32 => i32_suffixed
|
||||
i64 => i64_suffixed
|
||||
i128 => i128_suffixed
|
||||
isize => isize_suffixed
|
||||
impl ToTokens for i16 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::i16_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
u8 => u8_suffixed
|
||||
u16 => u16_suffixed
|
||||
u32 => u32_suffixed
|
||||
u64 => u64_suffixed
|
||||
u128 => u128_suffixed
|
||||
usize => usize_suffixed
|
||||
impl ToTokens for i32 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::i32_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
f32 => f32_suffixed
|
||||
f64 => f64_suffixed
|
||||
impl ToTokens for i64 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::i64_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for i128 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::i128_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for isize {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::isize_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for u8 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::u8_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for u16 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::u16_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for u32 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::u32_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for u64 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::u64_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for u128 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::u128_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for usize {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::usize_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for f32 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::f32_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for f64 {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::f64_suffixed(*self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for char {
|
||||
@@ -168,6 +222,18 @@ impl ToTokens for bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for CStr {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::c_string(self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for CString {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(Literal::c_string(self));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for Group {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(self.clone());
|
||||
@@ -193,14 +259,14 @@ impl ToTokens for Literal {
|
||||
}
|
||||
|
||||
impl ToTokens for TokenTree {
|
||||
fn to_tokens(&self, dst: &mut TokenStream) {
|
||||
dst.append(self.clone());
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.append(self.clone());
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for TokenStream {
|
||||
fn to_tokens(&self, dst: &mut TokenStream) {
|
||||
dst.extend(iter::once(self.clone()));
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.extend(iter::once(self.clone()));
|
||||
}
|
||||
|
||||
fn into_token_stream(self) -> TokenStream {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#[rustversion::attr(not(nightly), ignore)]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
#[rustversion::attr(not(nightly), ignore = "requires nightly")]
|
||||
#[cfg_attr(miri, ignore = "incompatible with miri")]
|
||||
#[test]
|
||||
fn ui() {
|
||||
let t = trybuild::TestCases::new();
|
||||
|
||||
+19
-3
@@ -8,11 +8,11 @@
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream};
|
||||
use quote::{format_ident, quote, quote_spanned, TokenStreamExt};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::BTreeSet;
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
struct X;
|
||||
|
||||
@@ -233,6 +233,22 @@ fn test_string() {
|
||||
assert_eq!(expected, tokens.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_c_str() {
|
||||
let s = CStr::from_bytes_with_nul(b"\x01 a 'b \" c\0").unwrap();
|
||||
let tokens = quote!(#s);
|
||||
let expected = "c\"\\u{1} a 'b \\\" c\"";
|
||||
assert_eq!(expected, tokens.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_c_string() {
|
||||
let s = CString::new(&b"\x01 a 'b \" c"[..]).unwrap();
|
||||
let tokens = quote!(#s);
|
||||
let expected = "c\"\\u{1} a 'b \\\" c\"";
|
||||
assert_eq!(expected, tokens.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_interpolated_literal() {
|
||||
macro_rules! m {
|
||||
|
||||
Reference in New Issue
Block a user