Rewrite the AST to be a bit more user-friendly
This commit is a relatively large rewrite of the AST that `syn` exposes. The
main change is to expose enums-of-structs rather than
enums-with-huge-tuple-variants. The best example of this is `ItemKind::Fn` which
changed from:
enum ItemKind {
Fn(Box<FnDecl>, Unsafety, Constness, Option<Abi>, Generics, Box<Block>),
...
}
to
enum ItemKind {
Fn(ItemFn),
...
}
struct ItemFn {
decl: Box<FnDecl>,
unsafety: Unsafety,
constness: Constness,
abi: Option<Abi>,
generics: Generics,
block: Box<Block>,
}
This change serves a few purposes:
* It's now much easier to add fields to each variant of the ast, ast struct
fields tend to be "by default ignored" in most contexts.
* It's much easier to document what each field is, as each field can have
dedicated documentation.
* There's now canonicalized names for each field (the name of the field) which
can help match `match` statements more consistent across a codebase.
A downside of this representation is that it can be a little more verbose to
work with in `match` statements and during constructions. Overall though I'd
feel at least that the readability improved significantly despite the extra
words required to do various operations.
Closes #136
diff --git a/tests/test_generics.rs b/tests/test_generics.rs
index 800daa7..08886bb 100644
--- a/tests/test_generics.rs
+++ b/tests/test_generics.rs
@@ -27,13 +27,15 @@
}],
ident: Ident::new("T"),
bounds: vec![TyParamBound::Region(Lifetime::new("'a"))],
- default: Some(Ty::Tup(Vec::new())),
+ default: Some(TyTup { tys: Vec::new() }.into()),
}],
where_clause: WhereClause {
predicates: vec![WherePredicate::BoundPredicate(WhereBoundPredicate {
bound_lifetimes: Vec::new(),
- bounded_ty:
- Ty::Path(None, "T".into()),
+ bounded_ty: TyPath {
+ qself: None,
+ path: "T".into(),
+ }.into(),
bounds: vec![
TyParamBound::Trait(
PolyTraitRef {