dep: update syn to v2 (#115)

* dep: update syn to v2

* fix a broken test.

---------

Co-authored-by: Vince Pike <25014503+vthg2themax@users.noreply.github.com>
This commit is contained in:
liushuyu 2023-04-12 08:02:05 -06:00 committed by GitHub
parent 7741afd404
commit 2a8e1a7b7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 191 additions and 132 deletions

148
Cargo.lock generated
View File

@ -8,6 +8,15 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "basic-toml"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c0de75129aa8d0cceaf750b89013f0e08804d6ec61416da787b35ad0d7cddf1"
dependencies = [
"serde",
]
[[package]]
name = "bitflags"
version = "1.3.2"
@ -27,7 +36,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"
dependencies = [
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -38,9 +47,9 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
[[package]]
name = "filetime"
version = "0.2.19"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9"
checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153"
dependencies = [
"cfg-if",
"libc",
@ -71,9 +80,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "1.9.2"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown",
@ -93,9 +102,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]]
name = "itoap"
@ -105,9 +114,9 @@ checksum = "9028f49264629065d057f340a86acb84867925865f73bbf8d47b4d149a7e88b8"
[[package]]
name = "libc"
version = "0.2.139"
version = "0.2.141"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5"
[[package]]
name = "memchr"
@ -117,9 +126,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "once_cell"
version = "1.17.0"
version = "1.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
[[package]]
name = "output_vt100"
@ -144,18 +153,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.50"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2"
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.23"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
dependencies = [
"proc-macro2",
]
@ -171,9 +180,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.12"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
[[package]]
name = "sailfish"
@ -198,8 +207,8 @@ dependencies = [
"proc-macro2",
"quote",
"serde",
"syn",
"toml 0.7.2",
"syn 2.0.13",
"toml",
]
[[package]]
@ -212,29 +221,29 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.152"
version = "1.0.159"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.152"
version = "1.0.159"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.13",
]
[[package]]
name = "serde_json"
version = "1.0.91"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744"
dependencies = [
"itoa",
"ryu",
@ -252,9 +261,20 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.107"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec"
dependencies = [
"proc-macro2",
"quote",
@ -272,18 +292,9 @@ dependencies = [
[[package]]
name = "toml"
version = "0.5.11"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]]
name = "toml"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6"
checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21"
dependencies = [
"serde",
"serde_spanned",
@ -302,9 +313,9 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.19.4"
version = "0.19.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a1eb0622d28f4b9c90adc4ea4b2b46b47663fde9ac5fafcb14a1369d5508825"
checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13"
dependencies = [
"indexmap",
"serde",
@ -315,24 +326,24 @@ dependencies = [
[[package]]
name = "trybuild"
version = "1.0.76"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ed2c57956f91546d4d33614265a85d55c8e1ab91484853a10335894786d7db6"
checksum = "501dbdbb99861e4ab6b60eb6a7493956a9defb644fd034bc4a5ef27c693c8a3a"
dependencies = [
"basic-toml",
"glob",
"once_cell",
"serde",
"serde_derive",
"serde_json",
"termcolor",
"toml 0.5.11",
]
[[package]]
name = "unicode-ident"
version = "1.0.6"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
[[package]]
name = "version_check"
@ -373,9 +384,18 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.42.0"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
@ -388,51 +408,51 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.1"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.1"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_i686_gnu"
version = "0.42.1"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
[[package]]
name = "windows_i686_msvc"
version = "0.42.1"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.1"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.1"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.1"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "winnow"
version = "0.3.4"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c95fb4ff192527911dd18eb138ac30908e7165b8944e528b6af93aa4c842d345"
checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28"
dependencies = [
"memchr",
]

View File

@ -22,15 +22,15 @@ procmacro = []
config = ["serde", "toml"]
[dependencies]
memchr = "2.3.3"
quote = { version = "1.0.6", default-features = false }
memchr = "2.5.0"
quote = { version = "1.0.26", default-features = false }
serde = { version = "1.0", features = ["derive"], optional = true }
toml = { version = "0.7", optional = true }
home = "0.5.3"
filetime = "0.2.14"
toml = { version = "0.7.3", optional = true }
home = "0.5.4"
filetime = "0.2.21"
[dependencies.syn]
version = "1.0.21"
version = "2.0"
default-features = false
features = ["parsing", "full", "visit-mut", "printing"]
@ -40,4 +40,4 @@ default-features = false
features = ["span-locations"]
[dev-dependencies]
pretty_assertions = "1.1.0"
pretty_assertions = "1.3.0"

View File

@ -1,7 +1,11 @@
use proc_macro2::TokenStream;
use quote::quote;
use syn::parse::{Parse, ParseStream, Result as ParseResult};
use syn::visit_mut::VisitMut;
use syn::{Block, Expr, ExprBreak, ExprContinue, ExprMacro, Ident, LitStr, Stmt, Token};
use syn::{
Block, Expr, ExprBreak, ExprContinue, ExprMacro, Ident, LitStr, Macro, Stmt,
StmtMacro, Token,
};
pub struct Optimizer {
rm_whitespace: bool,
@ -44,8 +48,7 @@ impl VisitMut for OptmizerImpl {
// check if statement is for loop
let fl = match stmt {
Stmt::Expr(Expr::ForLoop(ref mut fl))
| Stmt::Semi(Expr::ForLoop(ref mut fl), _) => fl,
Stmt::Expr(Expr::ForLoop(ref mut fl), _) => fl,
_ => {
results.push(stmt);
continue;
@ -116,35 +119,29 @@ impl VisitMut for OptmizerImpl {
i.stmts = results;
}
fn visit_stmt_macro_mut(&mut self, i: &mut StmtMacro) {
if self.rm_whitespace {
if let Some(v) = get_rendertext_value(&i.mac) {
let ts = match remove_whitespace(v) {
Some(value) => value,
None => return,
};
i.mac.tokens = ts;
return;
}
}
syn::visit_mut::visit_stmt_macro_mut(self, i);
}
fn visit_expr_macro_mut(&mut self, i: &mut ExprMacro) {
if self.rm_whitespace {
if let Some(v) = get_rendertext_value(i) {
let mut buffer = String::new();
let mut it = v.lines().peekable();
if let Some(line) = it.next() {
if it.peek().is_some() {
buffer.push_str(line.trim_end());
buffer.push('\n');
} else {
return;
}
}
while let Some(line) = it.next() {
if it.peek().is_some() {
if !line.is_empty() {
buffer.push_str(line.trim());
buffer.push('\n');
} else {
// ignore empty line
}
} else {
// last line
buffer.push_str(line.trim_start());
}
}
i.mac.tokens = quote! { __sf_buf, #buffer };
if let Some(v) = get_rendertext_value(&i.mac) {
let ts = match remove_whitespace(v) {
Some(value) => value,
None => return,
};
i.mac.tokens = ts;
return;
}
}
@ -153,7 +150,35 @@ impl VisitMut for OptmizerImpl {
}
}
fn get_rendertext_value(i: &ExprMacro) -> Option<String> {
fn remove_whitespace(v: String) -> Option<TokenStream> {
let mut buffer = String::new();
let mut it = v.lines().peekable();
if let Some(line) = it.next() {
if it.peek().is_some() {
buffer.push_str(line.trim_end());
buffer.push('\n');
} else {
return None;
}
}
while let Some(line) = it.next() {
if it.peek().is_some() {
if !line.is_empty() {
buffer.push_str(line.trim());
buffer.push('\n');
} else {
// ignore empty line
}
} else {
// last line
buffer.push_str(line.trim_start());
}
}
Some(quote! { __sf_buf, #buffer })
}
fn get_rendertext_value(mac: &Macro) -> Option<String> {
struct RenderTextMacroArgument {
#[allow(dead_code)]
context: Ident,
@ -170,13 +195,13 @@ fn get_rendertext_value(i: &ExprMacro) -> Option<String> {
}
}
let mut it = i.mac.path.segments.iter();
let mut it = mac.path.segments.iter();
if it.next().map_or(false, |s| s.ident == "__sf_rt")
&& it.next().map_or(false, |s| s.ident == "render_text")
&& it.next().is_none()
{
let tokens = i.mac.tokens.clone();
let tokens = mac.tokens.clone();
if let Ok(macro_arg) = syn::parse2::<RenderTextMacroArgument>(tokens) {
return Some(macro_arg.arg.value());
}
@ -186,12 +211,12 @@ fn get_rendertext_value(i: &ExprMacro) -> Option<String> {
}
fn get_rendertext_value_from_stmt(stmt: &Stmt) -> Option<String> {
let mac = match stmt {
Stmt::Semi(Expr::Macro(ref mac), ..) => mac,
let em = match stmt {
Stmt::Expr(Expr::Macro(ref mac), Some(_)) => mac,
_ => return None,
};
get_rendertext_value(mac)
get_rendertext_value(&em.mac)
}
fn block_has_continue_or_break(i: &mut Block) -> bool {

View File

@ -24,10 +24,7 @@ struct DeriveTemplateOptions {
impl DeriveTemplateOptions {
fn parser<'s>(&'s mut self) -> impl Parser + 's {
move |outer: ParseStream| -> ParseResult<()> {
let s;
syn::parenthesized!(s in outer);
move |s: ParseStream| -> ParseResult<()> {
while !s.is_empty() {
let key = s.parse::<Ident>()?;
s.parse::<Token![=]>()?;
@ -161,8 +158,8 @@ fn derive_template_impl(tokens: TokenStream) -> Result<TokenStream, syn::Error>
let mut all_options = DeriveTemplateOptions::default();
for attr in strct.attrs {
if attr.path.is_ident("template") {
syn::parse::Parser::parse2(all_options.parser(), attr.tokens)?;
if attr.path().is_ident("template") {
attr.parse_args_with(all_options.parser())?;
}
}

View File

@ -2,7 +2,7 @@ use quote::quote;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use syn::visit_mut::VisitMut;
use syn::{Block, Expr, ExprBlock, ExprMacro, LitStr};
use syn::{Block, Expr, ExprBlock, LitStr, Macro, Stmt};
use crate::error::*;
@ -82,8 +82,8 @@ struct ResolverImpl<'h> {
}
impl<'h> ResolverImpl<'h> {
fn resolve_include(&mut self, i: &ExprMacro) -> Result<Expr, Error> {
let arg = match syn::parse2::<LitStr>(i.mac.tokens.clone()) {
fn resolve_include(&mut self, mac: &Macro) -> Result<Expr, Error> {
let arg = match syn::parse2::<LitStr>(mac.tokens.clone()) {
Ok(l) => l.value(),
Err(e) => {
let mut e = Error::from(e);
@ -145,6 +145,24 @@ impl<'h> ResolverImpl<'h> {
}
impl<'h> VisitMut for ResolverImpl<'h> {
fn visit_stmt_mut(&mut self, i: &mut Stmt) {
return_if_some!(self.error);
let sm = matches_or_else!(*i, Stmt::Macro(ref mut sm), sm, {
syn::visit_mut::visit_stmt_mut(self, i);
return;
});
if sm.mac.path.is_ident("include") {
match self.resolve_include(&sm.mac) {
Ok(e) => *i = Stmt::Expr(e, None),
Err(e) => {
self.error = Some(e);
return;
}
}
}
}
fn visit_expr_mut(&mut self, i: &mut Expr) {
return_if_some!(self.error);
let em = matches_or_else!(*i, Expr::Macro(ref mut em), em, {
@ -154,7 +172,7 @@ impl<'h> VisitMut for ResolverImpl<'h> {
// resolve `include`
if em.mac.path.is_ident("include") {
match self.resolve_include(em) {
match self.resolve_include(&em.mac) {
Ok(e) => *i = e,
Err(e) => {
self.error = Some(e);

View File

@ -1,7 +1,6 @@
use proc_macro2::Span;
use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
use syn::parse::{Parse, ParseStream as SynParseStream, Result as ParseResult};
use syn::spanned::Spanned;
use syn::{BinOp, Block, Expr};
use crate::error::*;
@ -276,11 +275,11 @@ enum Filter {
Call(syn::ExprCall),
}
impl Spanned for Filter {
fn span(&self) -> Span {
match *self {
Filter::Ident(ref i) => i.span(),
Filter::Call(ref c) => c.span(),
impl ToTokens for Filter {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
Filter::Ident(ident) => ident.to_tokens(tokens),
Filter::Call(call) => call.to_tokens(tokens),
}
}
}

View File

@ -26,7 +26,7 @@ default = ["config"]
config = ["sailfish-compiler/config"]
[dependencies]
proc-macro2 = "1.0.11"
proc-macro2 = "1.0.56"
[dependencies.sailfish-compiler]
path = "../sailfish-compiler"

View File

@ -9,8 +9,8 @@ publish = false
sailfish = { path = "../../sailfish", default-features = false, features = ["json"] }
sailfish-macros = { path = "../../sailfish-macros" }
sailfish-compiler = { path = "../../sailfish-compiler" }
serde_json = "1.0.53"
serde_json = "1.0.95"
[dev-dependencies]
trybuild = "1.0.28"
pretty_assertions = "1.1.0"
trybuild = "1.0.80"
pretty_assertions = "1.3.0"

View File

@ -23,9 +23,9 @@ perf-inline = []
[dependencies]
itoap = "1.0.1"
ryu = "1.0.4"
serde = { version = "1.0.111", optional = true }
serde_json = { version = "1.0.53", optional = true }
ryu = "1.0.13"
serde = { version = "1.0.159", optional = true }
serde_json = { version = "1.0.95", optional = true }
[dependencies.sailfish-macros]
path = "../sailfish-macros"
@ -33,7 +33,7 @@ version = "0.6.0"
optional = true
[build-dependencies]
version_check = "0.9.2"
version_check = "0.9.4"
[package.metadata.docs.rs]
all-features = true