Skip to content

Commit 95de86e

Browse files
authored
Update syn to 2.0 (eupn#91)
1 parent 3751785 commit 95de86e

File tree

6 files changed

+76
-133
lines changed

6 files changed

+76
-133
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "macrotest"
33
version = "1.0.9" # remember to update in lib.rs
44
authors = ["eupn <[email protected]>"]
55
edition = "2018"
6+
rust-version = "1.56"
67
license = "MIT OR Apache-2.0"
78
readme = "README.md"
89
repository = "https://github.com/eupn/macrotest"
@@ -11,8 +12,8 @@ description = "Test harness for macro expansion"
1112
[dependencies]
1213
diff = "0.1"
1314
glob = "0.3"
14-
prettyplease = "0.1"
15+
prettyplease = "0.2"
1516
serde = { version = "1.0.105", features = ["derive"] }
1617
serde_json = "1.0"
17-
syn = { version = "1", features = ["full"] }
18+
syn = { version = "2", features = ["full"] }
1819
toml = "0.5"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
[![Travis-CI](https://api.travis-ci.com/eupn/macrotest.svg?branch=master)](https://travis-ci.com/eupn/macrotest)
44
[![Crates.io](https://img.shields.io/crates/v/macrotest)](https://crates.io/crates/macrotest)
5-
![MSRV 1.34.0](https://img.shields.io/badge/MSRV-1.34.0-orange.svg)
5+
![MSRV 1.56](https://img.shields.io/badge/MSRV-1.56-orange.svg)
66
[![docs.rs](https://docs.rs/macrotest/badge.svg)](https://docs.rs/macrotest/)
77
[![Crates.io](https://img.shields.io/crates/d/macrotest)](https://crates.io/crates/macrotest)
88
[![Crates.io](https://img.shields.io/crates/l/macrotest)](https://crates.io/crates/macrotest)
99

1010
Similar to [trybuild], but allows you to test how declarative or procedural macros are expanded.
1111

12-
*Minimal Supported Rust Version: 1.34.0*
12+
*Minimal Supported Rust Version: 1.56*
1313

1414
----
1515

src/expand.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use crate::manifest::{Bin, Build, Config, Manifest, Name, Package, Workspace};
1212
use crate::message::{message_different, message_expansion_error};
1313
use crate::rustflags;
1414
use crate::{error::Error, error::Result};
15-
use syn::{Item, Meta, NestedMeta};
15+
use syn::punctuated::Punctuated;
16+
use syn::{Item, Meta, Token};
1617

1718
/// An extension for files containing `cargo expand` result.
1819
const EXPANDED_RS_SUFFIX: &str = "expanded.rs";
@@ -400,11 +401,17 @@ fn normalize_expansion(input: &[u8]) -> String {
400401
// #![feature(prelude_import)]
401402
//
402403
syntax_tree.attrs.retain(|attr| {
403-
if let Ok(Meta::List(meta)) = attr.parse_meta() {
404-
if meta.path.is_ident("feature") && meta.nested.len() == 1 {
405-
if let NestedMeta::Meta(Meta::Path(inner)) = &meta.nested[0] {
406-
if inner.is_ident("prelude_import") {
407-
return false;
404+
if let Meta::List(meta) = &attr.meta {
405+
if meta.path.is_ident("feature") {
406+
if let Ok(list) =
407+
meta.parse_args_with(Punctuated::<Meta, Token![,]>::parse_terminated)
408+
{
409+
if list.len() == 1 {
410+
if let Meta::Path(inner) = &list.first().unwrap() {
411+
if inner.is_ident("prelude_import") {
412+
return false;
413+
}
414+
}
408415
}
409416
}
410417
}
@@ -423,7 +430,7 @@ fn normalize_expansion(input: &[u8]) -> String {
423430
syntax_tree.items.retain(|item| {
424431
if let Item::Use(item) = item {
425432
if let Some(attr) = item.attrs.first() {
426-
if attr.path.is_ident("prelude_import") && attr.tokens.is_empty() {
433+
if attr.path().is_ident("prelude_import") && attr.meta.require_path_only().is_ok() {
427434
return false;
428435
}
429436
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//!
66
//! Similar to [trybuild], but allows you to write tests on how macros are expanded.
77
//!
8-
//! *Minimal Supported Rust Version: 1.34.0*
8+
//! *Minimal Supported Rust Version: 1.56*
99
//!
1010
//! <br>
1111
//!

test-procmacro-project/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ proc-macro = true
1010
[dependencies]
1111
quote = "1"
1212
proc-macro2 = "1.0"
13-
syn = "1.0"
13+
syn = "2"
1414

1515
[dev-dependencies]
1616
macrotest = { path = "../" }

test-project/Cargo.lock

Lines changed: 55 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)