Skip to content

Commit

Permalink
Update code to use syn 2.0 parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhang committed Mar 19, 2023
1 parent 1f62dc3 commit 954aa6d
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ name = "fibonacci"
harness = false

[dev-dependencies]
trybuild = "1.0.56"
trybuild = "1.0.79"
criterion = { version = "0.4.0", features = ["html_reports"] }
fnv = "1.0"
fnv = "1.0.7"

[dependencies]
syn = { version = "1.0", features = ["full"] }
syn = { version = "2.0", features = ["full"] }
quote = "1.0"
proc-macro2 = "1.0"
proc-macro-error = "1.0"
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ fn is_datalog_var(expr: &Expr) -> Option<Ident> {
/// are bound by that pattern.
fn pat_datalog_vars(pat: &Pat, datalog_vars: &mut HashSet<String>) {
match pat {
Pat::Box(pb) => pat_datalog_vars(&pb.pat, datalog_vars),
Pat::Const(_) => (),
Pat::Ident(pi) => {
datalog_vars.insert(pi.ident.to_string());
if let Some((_, ref p)) = pi.subpat {
Expand All @@ -1202,6 +1202,7 @@ fn pat_datalog_vars(pat: &Pat, datalog_vars: &mut HashSet<String>) {
Pat::Lit(_) => (),
Pat::Macro(pm) => abort!(pm.span(), "Macros not allowed in let bindings."),
Pat::Or(_) => (),
Pat::Paren(pp) => pat_datalog_vars(&pp.pat, datalog_vars),
Pat::Path(_) => (),
Pat::Range(_) => (),
Pat::Reference(pr) => pat_datalog_vars(&pr.pat, datalog_vars),
Expand All @@ -1222,7 +1223,7 @@ fn pat_datalog_vars(pat: &Pat, datalog_vars: &mut HashSet<String>) {
}
}
Pat::TupleStruct(pts) => {
for e in &pts.pat.elems {
for e in &pts.elems {
pat_datalog_vars(e, datalog_vars);
}
}
Expand Down
29 changes: 16 additions & 13 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Parse for Relation {
name: input.parse()?,
generics: input.parse()?,
paren_token: parenthesized!(content in input),
fields: content.parse_terminated(Field::parse_unnamed)?,
fields: content.parse_terminated(Field::parse_unnamed, Token![,])?,
semi_token: input.parse()?,
})
}
Expand Down Expand Up @@ -173,17 +173,20 @@ impl Parse for Fact {
negate: input.parse()?,
relation: input.parse()?,
paren_token: parenthesized!(content in input),
fields: content.parse_terminated(|input| {
if input.peek(Token![_]) {
Ok(FactField::Ignored(input.parse()?))
} else if input.peek(Token![ref]) {
let ref_tok: Token![ref] = input.parse()?;
let ident: Ident = input.parse()?;
Ok(FactField::Ref(ref_tok, ident))
} else {
Ok(FactField::Expr(input.parse()?))
}
})?,
fields: content.parse_terminated(
|input| {
if input.peek(Token![_]) {
Ok(FactField::Ignored(input.parse()?))
} else if input.peek(Token![ref]) {
let ref_tok: Token![ref] = input.parse()?;
let ident: Ident = input.parse()?;
Ok(FactField::Ref(ref_tok, ident))
} else {
Ok(FactField::Expr(input.parse()?))
}
},
Token![,],
)?,
})
}
}
Expand All @@ -201,7 +204,7 @@ impl Parse for For {
#[allow(clippy::mixed_read_write_in_expression)]
Ok(Self {
for_token: input.parse()?,
pat: input.parse()?,
pat: Pat::parse_single(input)?,
in_token: input.parse()?,
expr: input.parse()?,
})
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/bad_goal_input.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Relations marked as @input cannot be derived from a rule.
--> $DIR/bad_goal_input.rs:11:9
--> tests/ui/bad_goal_input.rs:11:9
|
11 | In(0, 0);
| ^^
16 changes: 12 additions & 4 deletions tests/ui/bad_visibility_of_relation.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0603]: tuple struct constructor `Test` is private
--> $DIR/bad_visibility_of_relation.rs:21:22
--> tests/ui/bad_visibility_of_relation.rs:21:22
|
9 | struct Test(u32);
| --- a constructor is private if any of the fields is private
Expand All @@ -8,13 +8,17 @@ error[E0603]: tuple struct constructor `Test` is private
| ^^^^ private tuple struct constructor
|
note: the tuple struct constructor `Test` is defined here
--> $DIR/bad_visibility_of_relation.rs:9:9
--> tests/ui/bad_visibility_of_relation.rs:9:9
|
9 | struct Test(u32);
| ^^^^^^^^^^^^^^^^^
help: consider making the field publicly accessible
|
9 | struct Test(pub u32);
| +++

error[E0603]: tuple struct constructor `MoreTest` is private
--> $DIR/bad_visibility_of_relation.rs:22:22
--> tests/ui/bad_visibility_of_relation.rs:22:22
|
12 | pub struct MoreTest(bool);
| ---- a constructor is private if any of the fields is private
Expand All @@ -23,7 +27,11 @@ error[E0603]: tuple struct constructor `MoreTest` is private
| ^^^^^^^^ private tuple struct constructor
|
note: the tuple struct constructor `MoreTest` is defined here
--> $DIR/bad_visibility_of_relation.rs:12:9
--> tests/ui/bad_visibility_of_relation.rs:12:9
|
12 | pub struct MoreTest(bool);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider making the field publicly accessible
|
12 | pub struct MoreTest(pub bool);
| +++
4 changes: 2 additions & 2 deletions tests/ui/capital_letter_var.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0425]: cannot find value `Not_a_variable` in this scope
--> $DIR/capital_letter_var.rs:8:30
--> tests/ui/capital_letter_var.rs:8:30
|
8 | Ok(Not_a_variable) <- Ok(Not_a_variable);
| ^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `Not_a_variable` in this scope
--> $DIR/capital_letter_var.rs:8:8
--> tests/ui/capital_letter_var.rs:8:8
|
8 | Ok(Not_a_variable) <- Ok(Not_a_variable);
| ^^^^^^^^^^^^^^ not found in this scope
2 changes: 1 addition & 1 deletion tests/ui/invalid_arity.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Relation 'Fib' was declared with arity 2, but constructed with arity 3 here.
--> $DIR/invalid_arity.rs:10:9
--> tests/ui/invalid_arity.rs:10:9
|
10 | Fib(0, 0, 2);
| ^^^
2 changes: 1 addition & 1 deletion tests/ui/non_input_lifetime.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Lifetime on output relation without any input relations having a lifetime
--> $DIR/non_input_lifetime.rs:14:22
--> tests/ui/non_input_lifetime.rs:14:22
|
14 | struct Output<'a>(&'a u32);
| ^^^^
2 changes: 1 addition & 1 deletion tests/ui/recursive_negation.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Negation of relation 'Ok' creates a dependency cycle and cannot be stratified.
--> $DIR/recursive_negation.rs:8:14
--> tests/ui/recursive_negation.rs:8:14
|
8 | Ok() <- !Ok();
| ^^
8 changes: 4 additions & 4 deletions tests/ui/unbound_variable.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
error[E0425]: cannot find value `n` in this scope
--> $DIR/unbound_variable.rs:13:30
--> tests/ui/unbound_variable.rs:13:30
|
13 | Fib(n, x + y) <- Fib(n - 1, x), Fib(n - 2, y), (n <= 25);
| ^ not found in this scope

error[E0425]: cannot find value `n` in this scope
--> $DIR/unbound_variable.rs:13:45
--> tests/ui/unbound_variable.rs:13:45
|
13 | Fib(n, x + y) <- Fib(n - 1, x), Fib(n - 2, y), (n <= 25);
| ^ help: a local variable with a similar name exists: `x`

error[E0425]: cannot find value `n` in this scope
--> $DIR/unbound_variable.rs:13:57
--> tests/ui/unbound_variable.rs:13:57
|
13 | Fib(n, x + y) <- Fib(n - 1, x), Fib(n - 2, y), (n <= 25);
| ^ help: a local variable with a similar name exists: `x`

error[E0425]: cannot find value `n` in this scope
--> $DIR/unbound_variable.rs:13:13
--> tests/ui/unbound_variable.rs:13:13
|
13 | Fib(n, x + y) <- Fib(n - 1, x), Fib(n - 2, y), (n <= 25);
| ^ help: a local variable with a similar name exists: `x`
2 changes: 1 addition & 1 deletion tests/ui/underscore_in_goal.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Cannot have _ in goal atom of rule.
--> $DIR/underscore_in_goal.rs:7:8
--> tests/ui/underscore_in_goal.rs:7:8
|
7 | Ok(_) <- Ok(_);
| ^

0 comments on commit 954aa6d

Please sign in to comment.