Skip to content

Commit b85fbec

Browse files
committed
Add a benchmark for exhaustive_patterns
1 parent 623acd9 commit b85fbec

File tree

16 files changed

+2338
-0
lines changed

16 files changed

+2338
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "syn"
3+
version = "0.0.0"
4+
5+
[workspace]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"supports_stable": false,
3+
"touch_file": "src/lib.rs"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
use super::*;
2+
use delimited::Delimited;
3+
4+
ast_struct! {
5+
/// Doc-comments are promoted to attributes that have `is_sugared_doc` = true
6+
pub struct Attribute {
7+
pub style: AttrStyle,
8+
pub pound_token: tokens::Pound,
9+
pub bracket_token: tokens::Bracket,
10+
11+
/// The path of the attribute.
12+
///
13+
/// E.g. `derive` in `#[derive(Copy)]`
14+
/// E.g. `crate::precondition` in `#[crate::precondition x < 5]`
15+
pub path: Path,
16+
17+
/// Any tokens after the path.
18+
///
19+
/// E.g. `( Copy )` in `#[derive(Copy)]`
20+
/// E.g. `x < 5` in `#[crate::precondition x < 5]`
21+
pub tts: Vec<TokenTree>,
22+
23+
pub is_sugared_doc: bool,
24+
}
25+
}
26+
27+
ast_enum! {
28+
/// Distinguishes between Attributes that decorate items and Attributes that
29+
/// are contained as statements within items. These two cases need to be
30+
/// distinguished for pretty-printing.
31+
pub enum AttrStyle {
32+
/// Attribute of the form `#[...]`.
33+
Outer,
34+
35+
/// Attribute of the form `#![...]`.
36+
Inner(tokens::Bang),
37+
}
38+
}
39+
40+
ast_enum_of_structs! {
41+
/// A compile-time attribute item.
42+
///
43+
/// E.g. `#[test]`, `#[derive(..)]` or `#[feature = "foo"]`
44+
pub enum MetaItem {
45+
/// Term meta item.
46+
///
47+
/// E.g. `test` as in `#[test]`
48+
pub Term(Ident),
49+
50+
/// List meta item.
51+
///
52+
/// E.g. `derive(..)` as in `#[derive(..)]`
53+
pub List(MetaItemList {
54+
/// Name of this attribute.
55+
///
56+
/// E.g. `derive` in `#[derive(..)]`
57+
pub ident: Ident,
58+
59+
pub paren_token: tokens::Paren,
60+
61+
/// Arguments to this attribute
62+
///
63+
/// E.g. `..` in `#[derive(..)]`
64+
pub nested: Delimited<NestedMetaItem, tokens::Comma>,
65+
}),
66+
67+
/// Name-value meta item.
68+
///
69+
/// E.g. `feature = "foo"` as in `#[feature = "foo"]`
70+
pub NameValue(MetaNameValue {
71+
/// Name of this attribute.
72+
///
73+
/// E.g. `feature` in `#[feature = "foo"]`
74+
pub ident: Ident,
75+
76+
pub eq_token: tokens::Eq,
77+
78+
/// Arguments to this attribute
79+
///
80+
/// E.g. `"foo"` in `#[feature = "foo"]`
81+
pub lit: Lit,
82+
}),
83+
}
84+
}
85+
86+
ast_enum_of_structs! {
87+
/// Possible values inside of compile-time attribute lists.
88+
///
89+
/// E.g. the '..' in `#[name(..)]`.
90+
pub enum NestedMetaItem {
91+
/// A full `MetaItem`.
92+
///
93+
/// E.g. `Copy` in `#[derive(Copy)]` would be a `MetaItem::Term(Ident::from("Copy"))`.
94+
pub MetaItem(MetaItem),
95+
96+
/// A Rust literal.
97+
///
98+
/// E.g. `"name"` in `#[rename("name")]`.
99+
pub Literal(Lit),
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use super::*;
2+
use delimited::Delimited;
3+
4+
ast_struct! {
5+
/// An enum variant.
6+
pub struct Variant {
7+
/// Name of the variant.
8+
pub ident: Ident,
9+
10+
/// Attributes tagged on the variant.
11+
pub attrs: Vec<Attribute>,
12+
13+
/// Type of variant.
14+
pub data: VariantData,
15+
16+
/// Explicit discriminant, e.g. `Foo = 1`
17+
pub discriminant: Option<Expr>,
18+
19+
pub eq_token: Option<tokens::Eq>,
20+
}
21+
}
22+
23+
ast_enum! {
24+
/// Data stored within an enum variant or struct.
25+
pub enum VariantData {
26+
/// Struct variant, e.g. `Point { x: f64, y: f64 }`.
27+
Struct(Delimited<Field, tokens::Comma>, tokens::Brace),
28+
29+
/// Tuple variant, e.g. `Some(T)`.
30+
Tuple(Delimited<Field, tokens::Comma>, tokens::Paren),
31+
32+
/// Unit variant, e.g. `None`.
33+
Unit,
34+
}
35+
}
36+
37+
ast_struct! {
38+
/// A field of a struct or enum variant.
39+
pub struct Field {
40+
/// Name of the field, if any.
41+
///
42+
/// Fields of tuple structs have no names.
43+
pub ident: Option<Ident>,
44+
45+
/// Visibility of the field.
46+
pub vis: Visibility,
47+
48+
/// Attributes tagged on the field.
49+
pub attrs: Vec<Attribute>,
50+
51+
/// Type of the field.
52+
pub ty: Ty,
53+
54+
pub colon_token: Option<tokens::Colon>,
55+
}
56+
}
57+
58+
ast_enum_of_structs! {
59+
/// Visibility level of an item.
60+
pub enum Visibility {
61+
/// Public, i.e. `pub`.
62+
pub Public(VisPublic {
63+
pub pub_token: tokens::Pub,
64+
}),
65+
66+
/// Crate-visible, i.e. `pub(crate)`.
67+
pub Crate(VisCrate {
68+
pub pub_token: tokens::Pub,
69+
pub paren_token: tokens::Paren,
70+
pub crate_token: tokens::Crate,
71+
}),
72+
73+
/// Restricted, e.g. `pub(self)` or `pub(super)` or `pub(in some::module)`.
74+
pub Restricted(VisRestricted {
75+
pub pub_token: tokens::Pub,
76+
pub paren_token: tokens::Paren,
77+
pub in_token: Option<tokens::In>,
78+
pub path: Box<Path>,
79+
}),
80+
81+
/// Inherited, i.e. private.
82+
pub Inherited(VisInherited {}),
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use super::*;
2+
use delimited::Delimited;
3+
4+
ast_struct! {
5+
/// Struct or enum sent to a `proc_macro_derive` macro.
6+
pub struct DeriveInput {
7+
/// Name of the struct or enum.
8+
pub ident: Ident,
9+
10+
/// Visibility of the struct or enum.
11+
pub vis: Visibility,
12+
13+
/// Attributes tagged on the whole struct or enum.
14+
pub attrs: Vec<Attribute>,
15+
16+
/// Generics required to complete the definition.
17+
pub generics: Generics,
18+
19+
/// Data within the struct or enum.
20+
pub body: Body,
21+
}
22+
}
23+
24+
ast_enum_of_structs! {
25+
/// Body of a derived struct or enum.
26+
pub enum Body {
27+
/// It's an enum.
28+
pub Enum(BodyEnum {
29+
pub enum_token: tokens::Enum,
30+
pub brace_token: tokens::Brace,
31+
pub variants: Delimited<Variant, tokens::Comma>,
32+
}),
33+
34+
/// It's a struct.
35+
pub Struct(BodyStruct {
36+
pub data: VariantData,
37+
pub struct_token: tokens::Struct,
38+
pub semi_token: Option<tokens::Semi>,
39+
}),
40+
}
41+
}

0 commit comments

Comments
 (0)