David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 1 | use super::*; |
| 2 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 3 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 4 | pub struct Item { |
| 5 | pub ident: Ident, |
| 6 | pub vis: Visibility, |
| 7 | pub attrs: Vec<Attribute>, |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 8 | pub node: ItemKind, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 9 | } |
| 10 | |
| 11 | #[derive(Debug, Clone, Eq, PartialEq)] |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 12 | pub enum ItemKind { |
| 13 | /// An`extern crate` item, with optional original crate name. |
| 14 | /// |
| 15 | /// E.g. `extern crate foo` or `extern crate foo_bar as foo` |
| 16 | ExternCrate(Option<Ident>), |
| 17 | /// A use declaration (`use` or `pub use`) item. |
| 18 | /// |
| 19 | /// E.g. `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;` |
| 20 | Use(Box<ViewPath>), |
| 21 | /// A static item (`static` or `pub static`). |
| 22 | /// |
| 23 | /// E.g. `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";` |
| 24 | Static(Box<Ty>, Mutability, Box<Expr>), |
| 25 | /// A constant item (`const` or `pub const`). |
| 26 | /// |
| 27 | /// E.g. `const FOO: i32 = 42;` |
| 28 | Const(Box<Ty>, Box<Expr>), |
| 29 | /// A function declaration (`fn` or `pub fn`). |
| 30 | /// |
| 31 | /// E.g. `fn foo(bar: usize) -> usize { .. }` |
| 32 | Fn(Box<FnDecl>, Unsafety, Constness, Abi, Generics, Box<Block>), |
| 33 | /// A module declaration (`mod` or `pub mod`). |
| 34 | /// |
| 35 | /// E.g. `mod foo;` or `mod foo { .. }` |
| 36 | Mod(Vec<Item>), |
| 37 | /// An external module (`extern` or `pub extern`). |
| 38 | /// |
| 39 | /// E.g. `extern {}` or `extern "C" {}` |
| 40 | ForeignMod(ForeignMod), |
| 41 | /// A type alias (`type` or `pub type`). |
| 42 | /// |
| 43 | /// E.g. `type Foo = Bar<u8>;` |
| 44 | Ty(Box<Ty>, Generics), |
| 45 | /// An enum definition (`enum` or `pub enum`). |
| 46 | /// |
| 47 | /// E.g. `enum Foo<A, B> { C<A>, D<B> }` |
| 48 | Enum(Vec<Variant>, Generics), |
| 49 | /// A struct definition (`struct` or `pub struct`). |
| 50 | /// |
| 51 | /// E.g. `struct Foo<A> { x: A }` |
| 52 | Struct(VariantData, Generics), |
| 53 | /// A union definition (`union` or `pub union`). |
| 54 | /// |
| 55 | /// E.g. `union Foo<A, B> { x: A, y: B }` |
| 56 | Union(VariantData, Generics), |
| 57 | /// A Trait declaration (`trait` or `pub trait`). |
| 58 | /// |
| 59 | /// E.g. `trait Foo { .. }` or `trait Foo<T> { .. }` |
| 60 | Trait(Unsafety, Generics, Vec<TyParamBound>, Vec<TraitItem>), |
| 61 | // Default trait implementation. |
| 62 | /// |
| 63 | /// E.g. `impl Trait for .. {}` or `impl<T> Trait<T> for .. {}` |
| 64 | DefaultImpl(Unsafety, Path), |
| 65 | /// An implementation. |
| 66 | /// |
| 67 | /// E.g. `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }` |
| 68 | Impl(Unsafety, |
| 69 | ImplPolarity, |
| 70 | Generics, |
| 71 | Option<Path>, // (optional) trait this impl implements |
| 72 | Box<Ty>, // self |
| 73 | Vec<ImplItem>), |
| 74 | /// A macro invocation (which includes macro definition). |
| 75 | /// |
| 76 | /// E.g. `macro_rules! foo { .. }` or `foo!(..)` |
| 77 | Mac(Mac), |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | #[derive(Debug, Clone, Eq, PartialEq)] |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 81 | pub enum ViewPath { |
| 82 | /// `foo::bar::baz as quux` |
| 83 | /// |
| 84 | /// or just |
| 85 | /// |
| 86 | /// `foo::bar::baz` (with `as baz` implicitly on the right) |
| 87 | ViewPathSimple(Ident, Path), |
| 88 | |
| 89 | /// `foo::bar::*` |
| 90 | ViewPathGlob(Path), |
| 91 | |
| 92 | /// `foo::bar::{a,b,c}` |
| 93 | ViewPathList(Path, Vec<PathListItem>) |
| 94 | } |
| 95 | |
| 96 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 97 | pub struct PathListItem { |
| 98 | pub name: Ident, |
| 99 | /// renamed in list, e.g. `use foo::{bar as baz};` |
| 100 | pub rename: Option<Ident>, |
| 101 | } |
| 102 | |
| 103 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 104 | pub enum Unsafety { |
| 105 | Unsafe, |
| 106 | Normal, |
| 107 | } |
| 108 | |
| 109 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 110 | pub enum Constness { |
| 111 | Const, |
| 112 | NotConst, |
| 113 | } |
| 114 | |
| 115 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 116 | pub enum Defaultness { |
| 117 | Default, |
| 118 | Final, |
| 119 | } |
| 120 | |
| 121 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 122 | pub struct Abi(pub String); |
| 123 | |
| 124 | /// Foreign module declaration. |
| 125 | /// |
| 126 | /// E.g. `extern { .. }` or `extern C { .. }` |
| 127 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 128 | pub struct ForeignMod { |
| 129 | pub abi: Abi, |
| 130 | pub items: Vec<ForeignItem>, |
| 131 | } |
| 132 | |
| 133 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 134 | pub struct ForeignItem { |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 135 | pub ident: Ident, |
| 136 | pub attrs: Vec<Attribute>, |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 137 | pub node: ForeignItemKind, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 138 | pub vis: Visibility, |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 139 | } |
| 140 | |
| 141 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 142 | pub enum ForeignItemKind { |
| 143 | /// A foreign function |
| 144 | Fn(Box<FnDecl>, Generics), |
| 145 | /// A foreign static item (`static ext: u8`), with optional mutability |
| 146 | /// (the boolean is true when mutable) |
| 147 | Static(Box<Ty>, bool), |
| 148 | } |
| 149 | |
| 150 | /// Represents an item declaration within a trait declaration, |
| 151 | /// possibly including a default implementation. A trait item is |
| 152 | /// either required (meaning it doesn't have an implementation, just a |
| 153 | /// signature) or provided (meaning it has a default implementation). |
| 154 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 155 | pub struct TraitItem { |
| 156 | pub ident: Ident, |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 157 | pub attrs: Vec<Attribute>, |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 158 | pub node: TraitItemKind, |
| 159 | } |
| 160 | |
| 161 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 162 | pub enum TraitItemKind { |
| 163 | Const(Ty, Option<Expr>), |
| 164 | Method(MethodSig, Option<Block>), |
| 165 | Type(Vec<TyParamBound>, Option<Ty>), |
| 166 | Macro(Mac), |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 167 | } |
| 168 | |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 169 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 170 | pub enum ImplPolarity { |
| 171 | /// `impl Trait for Type` |
| 172 | Positive, |
| 173 | /// `impl !Trait for Type` |
| 174 | Negative, |
David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 175 | } |
| 176 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 177 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 178 | pub struct ImplItem { |
| 179 | pub ident: Ident, |
| 180 | pub vis: Visibility, |
| 181 | pub defaultness: Defaultness, |
| 182 | pub attrs: Vec<Attribute>, |
| 183 | pub node: ImplItemKind, |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 184 | } |
| 185 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 186 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 187 | pub enum ImplItemKind { |
| 188 | Const(Ty, Expr), |
| 189 | Method(MethodSig, Block), |
| 190 | Type(Ty), |
| 191 | Macro(Mac), |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 192 | } |
David Tolnay | d502581 | 2016-09-04 14:21:46 -0700 | [diff] [blame] | 193 | |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame^] | 194 | /// Represents a method's signature in a trait declaration, |
| 195 | /// or in an implementation. |
| 196 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 197 | pub struct MethodSig { |
| 198 | pub unsafety: Unsafety, |
| 199 | pub constness: Constness, |
| 200 | pub abi: Abi, |
| 201 | pub decl: FnDecl, |
| 202 | pub generics: Generics, |
David Tolnay | d502581 | 2016-09-04 14:21:46 -0700 | [diff] [blame] | 203 | } |