Skip to content

Commit 1c232a7

Browse files
committed
Update trace-var example to new proc-macro2
1 parent 98577c3 commit 1c232a7

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

examples/trace-var/trace-var/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ proc-macro = true
99

1010
[dependencies]
1111
syn = { path = "../../../", features = ["full", "fold"] }
12-
quote = "0.5"
13-
proc-macro2 = { version = "0.3", features = ["nightly"] }
12+
quote = "0.6"
13+
proc-macro2 = { version = "0.4", features = ["nightly"] }

examples/trace-var/trace-var/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct Args {
3131

3232
impl Synom for Args {
3333
named!(parse -> Self, map!(
34-
parens!(Punctuated::<Ident, Token![,]>::parse_terminated_nonempty),
35-
|(_parens, vars)| Args {
34+
call!(Punctuated::<Ident, Token![,]>::parse_terminated_nonempty),
35+
|vars| Args {
3636
vars: vars.into_iter().collect(),
3737
}
3838
));
@@ -62,8 +62,11 @@ impl Args {
6262
/// Determines whether the given `Pat` is an identifier equal to one of the
6363
/// variables we intend to print. Patterns are used as the left-hand side of
6464
/// a `let` binding.
65-
fn should_print_pat(&self, p: &Pat) -> bool {
66-
match *p {
65+
fn should_print_pat(&self, p: &Punctuated<Pat, Token![|]>) -> bool {
66+
if p.len() != 1 {
67+
return false;
68+
}
69+
match p[0] {
6770
Pat::Ident(ref p) => self.vars.contains(&p.ident),
6871
_ => false,
6972
}
@@ -94,11 +97,12 @@ impl Args {
9497
/// // After
9598
/// let VAR = { let VAR = INIT; println!("VAR = {:?}", VAR); VAR };
9699
fn let_and_print(&mut self, local: Local) -> Stmt {
97-
let Local { pat, ty, init, .. } = local;
100+
let Local { pats, ty, init, .. } = local;
101+
let pat = &pats[0];
98102
let ty = ty.map(|(colon_token, ty)| quote!(#colon_token #ty));
99103
let init = self.fold_expr(*init.unwrap().1);
100104
let ident = match *pat {
101-
Pat::Ident(ref p) => p.ident,
105+
Pat::Ident(ref p) => &p.ident,
102106
_ => unreachable!(),
103107
};
104108
parse_quote! {
@@ -147,7 +151,7 @@ impl Fold for Args {
147151
fn fold_stmt(&mut self, s: Stmt) -> Stmt {
148152
match s {
149153
Stmt::Local(s) => {
150-
if s.init.is_some() && self.should_print_pat(&s.pat) {
154+
if s.init.is_some() && self.should_print_pat(&s.pats) {
151155
self.let_and_print(s)
152156
} else {
153157
Stmt::Local(fold::fold_local(self, s))

0 commit comments

Comments
 (0)