aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/ast
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-17 20:00:13 +0100
committerAleksey Kladov <[email protected]>2018-08-17 20:00:13 +0100
commitd3c90ded2b9a4f75e101fa3abc60cd3aebc439c9 (patch)
tree6d2388eb68605331a0dd090269372bc98dd038cd /crates/libsyntax2/src/ast
parent70097504f78c4c41368a0b864a94df95fb9c27f7 (diff)
Borrowed AST
Diffstat (limited to 'crates/libsyntax2/src/ast')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs436
-rw-r--r--crates/libsyntax2/src/ast/generated.rs.tera31
-rw-r--r--crates/libsyntax2/src/ast/mod.rs61
3 files changed, 267 insertions, 261 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index 4fc405c8a..e8a87eba5 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -1,45 +1,45 @@
1use { 1use {
2 ast, 2 ast,
3 SyntaxNode, OwnedRoot, TreeRoot, AstNode, 3 SyntaxNodeRef, AstNode,
4 SyntaxKind::*, 4 SyntaxKind::*,
5}; 5};
6 6
7// ArrayType 7// ArrayType
8#[derive(Debug, Clone, Copy)] 8#[derive(Debug, Clone, Copy)]
9pub struct ArrayType<R: TreeRoot = OwnedRoot> { 9pub struct ArrayType<'a> {
10 syntax: SyntaxNode<R>, 10 syntax: SyntaxNodeRef<'a>,
11} 11}
12 12
13impl<R: TreeRoot> AstNode<R> for ArrayType<R> { 13impl<'a> AstNode<'a> for ArrayType<'a> {
14 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 14 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
15 match syntax.kind() { 15 match syntax.kind() {
16 ARRAY_TYPE => Some(ArrayType { syntax }), 16 ARRAY_TYPE => Some(ArrayType { syntax }),
17 _ => None, 17 _ => None,
18 } 18 }
19 } 19 }
20 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 20 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
21} 21}
22 22
23impl<R: TreeRoot> ArrayType<R> {} 23impl<'a> ArrayType<'a> {}
24 24
25// Attr 25// Attr
26#[derive(Debug, Clone, Copy)] 26#[derive(Debug, Clone, Copy)]
27pub struct Attr<R: TreeRoot = OwnedRoot> { 27pub struct Attr<'a> {
28 syntax: SyntaxNode<R>, 28 syntax: SyntaxNodeRef<'a>,
29} 29}
30 30
31impl<R: TreeRoot> AstNode<R> for Attr<R> { 31impl<'a> AstNode<'a> for Attr<'a> {
32 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 32 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
33 match syntax.kind() { 33 match syntax.kind() {
34 ATTR => Some(Attr { syntax }), 34 ATTR => Some(Attr { syntax }),
35 _ => None, 35 _ => None,
36 } 36 }
37 } 37 }
38 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 38 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
39} 39}
40 40
41impl<R: TreeRoot> Attr<R> { 41impl<'a> Attr<'a> {
42 pub fn value(&self) -> Option<TokenTree<R>> { 42 pub fn value(self) -> Option<TokenTree<'a>> {
43 self.syntax() 43 self.syntax()
44 .children() 44 .children()
45 .filter_map(TokenTree::cast) 45 .filter_map(TokenTree::cast)
@@ -49,80 +49,80 @@ impl<R: TreeRoot> Attr<R> {
49 49
50// ConstDef 50// ConstDef
51#[derive(Debug, Clone, Copy)] 51#[derive(Debug, Clone, Copy)]
52pub struct ConstDef<R: TreeRoot = OwnedRoot> { 52pub struct ConstDef<'a> {
53 syntax: SyntaxNode<R>, 53 syntax: SyntaxNodeRef<'a>,
54} 54}
55 55
56impl<R: TreeRoot> AstNode<R> for ConstDef<R> { 56impl<'a> AstNode<'a> for ConstDef<'a> {
57 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 57 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
58 match syntax.kind() { 58 match syntax.kind() {
59 CONST_DEF => Some(ConstDef { syntax }), 59 CONST_DEF => Some(ConstDef { syntax }),
60 _ => None, 60 _ => None,
61 } 61 }
62 } 62 }
63 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 63 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
64} 64}
65 65
66impl<R: TreeRoot> ast::NameOwner<R> for ConstDef<R> {} 66impl<'a> ast::NameOwner<'a> for ConstDef<'a> {}
67impl<R: TreeRoot> ast::AttrsOwner<R> for ConstDef<R> {} 67impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {}
68impl<R: TreeRoot> ConstDef<R> {} 68impl<'a> ConstDef<'a> {}
69 69
70// DynTraitType 70// DynTraitType
71#[derive(Debug, Clone, Copy)] 71#[derive(Debug, Clone, Copy)]
72pub struct DynTraitType<R: TreeRoot = OwnedRoot> { 72pub struct DynTraitType<'a> {
73 syntax: SyntaxNode<R>, 73 syntax: SyntaxNodeRef<'a>,
74} 74}
75 75
76impl<R: TreeRoot> AstNode<R> for DynTraitType<R> { 76impl<'a> AstNode<'a> for DynTraitType<'a> {
77 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 77 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
78 match syntax.kind() { 78 match syntax.kind() {
79 DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), 79 DYN_TRAIT_TYPE => Some(DynTraitType { syntax }),
80 _ => None, 80 _ => None,
81 } 81 }
82 } 82 }
83 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 83 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
84} 84}
85 85
86impl<R: TreeRoot> DynTraitType<R> {} 86impl<'a> DynTraitType<'a> {}
87 87
88// EnumDef 88// EnumDef
89#[derive(Debug, Clone, Copy)] 89#[derive(Debug, Clone, Copy)]
90pub struct EnumDef<R: TreeRoot = OwnedRoot> { 90pub struct EnumDef<'a> {
91 syntax: SyntaxNode<R>, 91 syntax: SyntaxNodeRef<'a>,
92} 92}
93 93
94impl<R: TreeRoot> AstNode<R> for EnumDef<R> { 94impl<'a> AstNode<'a> for EnumDef<'a> {
95 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 95 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
96 match syntax.kind() { 96 match syntax.kind() {
97 ENUM_DEF => Some(EnumDef { syntax }), 97 ENUM_DEF => Some(EnumDef { syntax }),
98 _ => None, 98 _ => None,
99 } 99 }
100 } 100 }
101 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 101 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
102} 102}
103 103
104impl<R: TreeRoot> ast::NameOwner<R> for EnumDef<R> {} 104impl<'a> ast::NameOwner<'a> for EnumDef<'a> {}
105impl<R: TreeRoot> ast::AttrsOwner<R> for EnumDef<R> {} 105impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {}
106impl<R: TreeRoot> EnumDef<R> {} 106impl<'a> EnumDef<'a> {}
107 107
108// File 108// File
109#[derive(Debug, Clone, Copy)] 109#[derive(Debug, Clone, Copy)]
110pub struct File<R: TreeRoot = OwnedRoot> { 110pub struct File<'a> {
111 syntax: SyntaxNode<R>, 111 syntax: SyntaxNodeRef<'a>,
112} 112}
113 113
114impl<R: TreeRoot> AstNode<R> for File<R> { 114impl<'a> AstNode<'a> for File<'a> {
115 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 115 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
116 match syntax.kind() { 116 match syntax.kind() {
117 FILE => Some(File { syntax }), 117 FILE => Some(File { syntax }),
118 _ => None, 118 _ => None,
119 } 119 }
120 } 120 }
121 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 121 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
122} 122}
123 123
124impl<R: TreeRoot> File<R> { 124impl<'a> File<'a> {
125 pub fn functions<'a>(&'a self) -> impl Iterator<Item = FnDef<R>> + 'a { 125 pub fn functions(self) -> impl Iterator<Item = FnDef<'a>> + 'a {
126 self.syntax() 126 self.syntax()
127 .children() 127 .children()
128 .filter_map(FnDef::cast) 128 .filter_map(FnDef::cast)
@@ -131,206 +131,206 @@ impl<R: TreeRoot> File<R> {
131 131
132// FnDef 132// FnDef
133#[derive(Debug, Clone, Copy)] 133#[derive(Debug, Clone, Copy)]
134pub struct FnDef<R: TreeRoot = OwnedRoot> { 134pub struct FnDef<'a> {
135 syntax: SyntaxNode<R>, 135 syntax: SyntaxNodeRef<'a>,
136} 136}
137 137
138impl<R: TreeRoot> AstNode<R> for FnDef<R> { 138impl<'a> AstNode<'a> for FnDef<'a> {
139 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 139 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
140 match syntax.kind() { 140 match syntax.kind() {
141 FN_DEF => Some(FnDef { syntax }), 141 FN_DEF => Some(FnDef { syntax }),
142 _ => None, 142 _ => None,
143 } 143 }
144 } 144 }
145 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 145 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
146} 146}
147 147
148impl<R: TreeRoot> ast::NameOwner<R> for FnDef<R> {} 148impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
149impl<R: TreeRoot> ast::AttrsOwner<R> for FnDef<R> {} 149impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
150impl<R: TreeRoot> FnDef<R> {} 150impl<'a> FnDef<'a> {}
151 151
152// FnPointerType 152// FnPointerType
153#[derive(Debug, Clone, Copy)] 153#[derive(Debug, Clone, Copy)]
154pub struct FnPointerType<R: TreeRoot = OwnedRoot> { 154pub struct FnPointerType<'a> {
155 syntax: SyntaxNode<R>, 155 syntax: SyntaxNodeRef<'a>,
156} 156}
157 157
158impl<R: TreeRoot> AstNode<R> for FnPointerType<R> { 158impl<'a> AstNode<'a> for FnPointerType<'a> {
159 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 159 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
160 match syntax.kind() { 160 match syntax.kind() {
161 FN_POINTER_TYPE => Some(FnPointerType { syntax }), 161 FN_POINTER_TYPE => Some(FnPointerType { syntax }),
162 _ => None, 162 _ => None,
163 } 163 }
164 } 164 }
165 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 165 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
166} 166}
167 167
168impl<R: TreeRoot> FnPointerType<R> {} 168impl<'a> FnPointerType<'a> {}
169 169
170// ForType 170// ForType
171#[derive(Debug, Clone, Copy)] 171#[derive(Debug, Clone, Copy)]
172pub struct ForType<R: TreeRoot = OwnedRoot> { 172pub struct ForType<'a> {
173 syntax: SyntaxNode<R>, 173 syntax: SyntaxNodeRef<'a>,
174} 174}
175 175
176impl<R: TreeRoot> AstNode<R> for ForType<R> { 176impl<'a> AstNode<'a> for ForType<'a> {
177 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 177 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
178 match syntax.kind() { 178 match syntax.kind() {
179 FOR_TYPE => Some(ForType { syntax }), 179 FOR_TYPE => Some(ForType { syntax }),
180 _ => None, 180 _ => None,
181 } 181 }
182 } 182 }
183 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 183 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
184} 184}
185 185
186impl<R: TreeRoot> ForType<R> {} 186impl<'a> ForType<'a> {}
187 187
188// ImplItem 188// ImplItem
189#[derive(Debug, Clone, Copy)] 189#[derive(Debug, Clone, Copy)]
190pub struct ImplItem<R: TreeRoot = OwnedRoot> { 190pub struct ImplItem<'a> {
191 syntax: SyntaxNode<R>, 191 syntax: SyntaxNodeRef<'a>,
192} 192}
193 193
194impl<R: TreeRoot> AstNode<R> for ImplItem<R> { 194impl<'a> AstNode<'a> for ImplItem<'a> {
195 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 195 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
196 match syntax.kind() { 196 match syntax.kind() {
197 IMPL_ITEM => Some(ImplItem { syntax }), 197 IMPL_ITEM => Some(ImplItem { syntax }),
198 _ => None, 198 _ => None,
199 } 199 }
200 } 200 }
201 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 201 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
202} 202}
203 203
204impl<R: TreeRoot> ImplItem<R> {} 204impl<'a> ImplItem<'a> {}
205 205
206// ImplTraitType 206// ImplTraitType
207#[derive(Debug, Clone, Copy)] 207#[derive(Debug, Clone, Copy)]
208pub struct ImplTraitType<R: TreeRoot = OwnedRoot> { 208pub struct ImplTraitType<'a> {
209 syntax: SyntaxNode<R>, 209 syntax: SyntaxNodeRef<'a>,
210} 210}
211 211
212impl<R: TreeRoot> AstNode<R> for ImplTraitType<R> { 212impl<'a> AstNode<'a> for ImplTraitType<'a> {
213 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 213 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
214 match syntax.kind() { 214 match syntax.kind() {
215 IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }), 215 IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }),
216 _ => None, 216 _ => None,
217 } 217 }
218 } 218 }
219 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 219 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
220} 220}
221 221
222impl<R: TreeRoot> ImplTraitType<R> {} 222impl<'a> ImplTraitType<'a> {}
223 223
224// Module 224// Module
225#[derive(Debug, Clone, Copy)] 225#[derive(Debug, Clone, Copy)]
226pub struct Module<R: TreeRoot = OwnedRoot> { 226pub struct Module<'a> {
227 syntax: SyntaxNode<R>, 227 syntax: SyntaxNodeRef<'a>,
228} 228}
229 229
230impl<R: TreeRoot> AstNode<R> for Module<R> { 230impl<'a> AstNode<'a> for Module<'a> {
231 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 231 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
232 match syntax.kind() { 232 match syntax.kind() {
233 MODULE => Some(Module { syntax }), 233 MODULE => Some(Module { syntax }),
234 _ => None, 234 _ => None,
235 } 235 }
236 } 236 }
237 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 237 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
238} 238}
239 239
240impl<R: TreeRoot> ast::NameOwner<R> for Module<R> {} 240impl<'a> ast::NameOwner<'a> for Module<'a> {}
241impl<R: TreeRoot> ast::AttrsOwner<R> for Module<R> {} 241impl<'a> ast::AttrsOwner<'a> for Module<'a> {}
242impl<R: TreeRoot> Module<R> {} 242impl<'a> Module<'a> {}
243 243
244// Name 244// Name
245#[derive(Debug, Clone, Copy)] 245#[derive(Debug, Clone, Copy)]
246pub struct Name<R: TreeRoot = OwnedRoot> { 246pub struct Name<'a> {
247 syntax: SyntaxNode<R>, 247 syntax: SyntaxNodeRef<'a>,
248} 248}
249 249
250impl<R: TreeRoot> AstNode<R> for Name<R> { 250impl<'a> AstNode<'a> for Name<'a> {
251 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 251 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
252 match syntax.kind() { 252 match syntax.kind() {
253 NAME => Some(Name { syntax }), 253 NAME => Some(Name { syntax }),
254 _ => None, 254 _ => None,
255 } 255 }
256 } 256 }
257 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 257 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
258} 258}
259 259
260impl<R: TreeRoot> Name<R> {} 260impl<'a> Name<'a> {}
261 261
262// NameRef 262// NameRef
263#[derive(Debug, Clone, Copy)] 263#[derive(Debug, Clone, Copy)]
264pub struct NameRef<R: TreeRoot = OwnedRoot> { 264pub struct NameRef<'a> {
265 syntax: SyntaxNode<R>, 265 syntax: SyntaxNodeRef<'a>,
266} 266}
267 267
268impl<R: TreeRoot> AstNode<R> for NameRef<R> { 268impl<'a> AstNode<'a> for NameRef<'a> {
269 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 269 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
270 match syntax.kind() { 270 match syntax.kind() {
271 NAME_REF => Some(NameRef { syntax }), 271 NAME_REF => Some(NameRef { syntax }),
272 _ => None, 272 _ => None,
273 } 273 }
274 } 274 }
275 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 275 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
276} 276}
277 277
278impl<R: TreeRoot> NameRef<R> {} 278impl<'a> NameRef<'a> {}
279 279
280// NamedField 280// NamedField
281#[derive(Debug, Clone, Copy)] 281#[derive(Debug, Clone, Copy)]
282pub struct NamedField<R: TreeRoot = OwnedRoot> { 282pub struct NamedField<'a> {
283 syntax: SyntaxNode<R>, 283 syntax: SyntaxNodeRef<'a>,
284} 284}
285 285
286impl<R: TreeRoot> AstNode<R> for NamedField<R> { 286impl<'a> AstNode<'a> for NamedField<'a> {
287 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 287 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
288 match syntax.kind() { 288 match syntax.kind() {
289 NAMED_FIELD => Some(NamedField { syntax }), 289 NAMED_FIELD => Some(NamedField { syntax }),
290 _ => None, 290 _ => None,
291 } 291 }
292 } 292 }
293 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 293 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
294} 294}
295 295
296impl<R: TreeRoot> ast::NameOwner<R> for NamedField<R> {} 296impl<'a> ast::NameOwner<'a> for NamedField<'a> {}
297impl<R: TreeRoot> ast::AttrsOwner<R> for NamedField<R> {} 297impl<'a> ast::AttrsOwner<'a> for NamedField<'a> {}
298impl<R: TreeRoot> NamedField<R> {} 298impl<'a> NamedField<'a> {}
299 299
300// NeverType 300// NeverType
301#[derive(Debug, Clone, Copy)] 301#[derive(Debug, Clone, Copy)]
302pub struct NeverType<R: TreeRoot = OwnedRoot> { 302pub struct NeverType<'a> {
303 syntax: SyntaxNode<R>, 303 syntax: SyntaxNodeRef<'a>,
304} 304}
305 305
306impl<R: TreeRoot> AstNode<R> for NeverType<R> { 306impl<'a> AstNode<'a> for NeverType<'a> {
307 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 307 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
308 match syntax.kind() { 308 match syntax.kind() {
309 NEVER_TYPE => Some(NeverType { syntax }), 309 NEVER_TYPE => Some(NeverType { syntax }),
310 _ => None, 310 _ => None,
311 } 311 }
312 } 312 }
313 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 313 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
314} 314}
315 315
316impl<R: TreeRoot> NeverType<R> {} 316impl<'a> NeverType<'a> {}
317 317
318// NominalDef 318// NominalDef
319#[derive(Debug, Clone, Copy)] 319#[derive(Debug, Clone, Copy)]
320pub enum NominalDef<R: TreeRoot = OwnedRoot> { 320pub enum NominalDef<'a> {
321 StructDef(StructDef<R>), 321 StructDef(StructDef<'a>),
322 EnumDef(EnumDef<R>), 322 EnumDef(EnumDef<'a>),
323} 323}
324 324
325impl<R: TreeRoot> AstNode<R> for NominalDef<R> { 325impl<'a> AstNode<'a> for NominalDef<'a> {
326 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 326 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
327 match syntax.kind() { 327 match syntax.kind() {
328 STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })), 328 STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })),
329 ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })), 329 ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })),
330 _ => None, 330 _ => None,
331 } 331 }
332 } 332 }
333 fn syntax(&self) -> &SyntaxNode<R> { 333 fn syntax(self) -> SyntaxNodeRef<'a> {
334 match self { 334 match self {
335 NominalDef::StructDef(inner) => inner.syntax(), 335 NominalDef::StructDef(inner) => inner.syntax(),
336 NominalDef::EnumDef(inner) => inner.syntax(), 336 NominalDef::EnumDef(inner) => inner.syntax(),
@@ -338,157 +338,157 @@ impl<R: TreeRoot> AstNode<R> for NominalDef<R> {
338 } 338 }
339} 339}
340 340
341impl<R: TreeRoot> ast::AttrsOwner<R> for NominalDef<R> {} 341impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {}
342impl<R: TreeRoot> NominalDef<R> {} 342impl<'a> NominalDef<'a> {}
343 343
344// ParenType 344// ParenType
345#[derive(Debug, Clone, Copy)] 345#[derive(Debug, Clone, Copy)]
346pub struct ParenType<R: TreeRoot = OwnedRoot> { 346pub struct ParenType<'a> {
347 syntax: SyntaxNode<R>, 347 syntax: SyntaxNodeRef<'a>,
348} 348}
349 349
350impl<R: TreeRoot> AstNode<R> for ParenType<R> { 350impl<'a> AstNode<'a> for ParenType<'a> {
351 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 351 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
352 match syntax.kind() { 352 match syntax.kind() {
353 PAREN_TYPE => Some(ParenType { syntax }), 353 PAREN_TYPE => Some(ParenType { syntax }),
354 _ => None, 354 _ => None,
355 } 355 }
356 } 356 }
357 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 357 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
358} 358}
359 359
360impl<R: TreeRoot> ParenType<R> {} 360impl<'a> ParenType<'a> {}
361 361
362// PathType 362// PathType
363#[derive(Debug, Clone, Copy)] 363#[derive(Debug, Clone, Copy)]
364pub struct PathType<R: TreeRoot = OwnedRoot> { 364pub struct PathType<'a> {
365 syntax: SyntaxNode<R>, 365 syntax: SyntaxNodeRef<'a>,
366} 366}
367 367
368impl<R: TreeRoot> AstNode<R> for PathType<R> { 368impl<'a> AstNode<'a> for PathType<'a> {
369 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 369 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
370 match syntax.kind() { 370 match syntax.kind() {
371 PATH_TYPE => Some(PathType { syntax }), 371 PATH_TYPE => Some(PathType { syntax }),
372 _ => None, 372 _ => None,
373 } 373 }
374 } 374 }
375 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 375 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
376} 376}
377 377
378impl<R: TreeRoot> PathType<R> {} 378impl<'a> PathType<'a> {}
379 379
380// PlaceholderType 380// PlaceholderType
381#[derive(Debug, Clone, Copy)] 381#[derive(Debug, Clone, Copy)]
382pub struct PlaceholderType<R: TreeRoot = OwnedRoot> { 382pub struct PlaceholderType<'a> {
383 syntax: SyntaxNode<R>, 383 syntax: SyntaxNodeRef<'a>,
384} 384}
385 385
386impl<R: TreeRoot> AstNode<R> for PlaceholderType<R> { 386impl<'a> AstNode<'a> for PlaceholderType<'a> {
387 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 387 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
388 match syntax.kind() { 388 match syntax.kind() {
389 PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }), 389 PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }),
390 _ => None, 390 _ => None,
391 } 391 }
392 } 392 }
393 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 393 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
394} 394}
395 395
396impl<R: TreeRoot> PlaceholderType<R> {} 396impl<'a> PlaceholderType<'a> {}
397 397
398// PointerType 398// PointerType
399#[derive(Debug, Clone, Copy)] 399#[derive(Debug, Clone, Copy)]
400pub struct PointerType<R: TreeRoot = OwnedRoot> { 400pub struct PointerType<'a> {
401 syntax: SyntaxNode<R>, 401 syntax: SyntaxNodeRef<'a>,
402} 402}
403 403
404impl<R: TreeRoot> AstNode<R> for PointerType<R> { 404impl<'a> AstNode<'a> for PointerType<'a> {
405 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 405 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
406 match syntax.kind() { 406 match syntax.kind() {
407 POINTER_TYPE => Some(PointerType { syntax }), 407 POINTER_TYPE => Some(PointerType { syntax }),
408 _ => None, 408 _ => None,
409 } 409 }
410 } 410 }
411 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 411 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
412} 412}
413 413
414impl<R: TreeRoot> PointerType<R> {} 414impl<'a> PointerType<'a> {}
415 415
416// ReferenceType 416// ReferenceType
417#[derive(Debug, Clone, Copy)] 417#[derive(Debug, Clone, Copy)]
418pub struct ReferenceType<R: TreeRoot = OwnedRoot> { 418pub struct ReferenceType<'a> {
419 syntax: SyntaxNode<R>, 419 syntax: SyntaxNodeRef<'a>,
420} 420}
421 421
422impl<R: TreeRoot> AstNode<R> for ReferenceType<R> { 422impl<'a> AstNode<'a> for ReferenceType<'a> {
423 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 423 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
424 match syntax.kind() { 424 match syntax.kind() {
425 REFERENCE_TYPE => Some(ReferenceType { syntax }), 425 REFERENCE_TYPE => Some(ReferenceType { syntax }),
426 _ => None, 426 _ => None,
427 } 427 }
428 } 428 }
429 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 429 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
430} 430}
431 431
432impl<R: TreeRoot> ReferenceType<R> {} 432impl<'a> ReferenceType<'a> {}
433 433
434// SliceType 434// SliceType
435#[derive(Debug, Clone, Copy)] 435#[derive(Debug, Clone, Copy)]
436pub struct SliceType<R: TreeRoot = OwnedRoot> { 436pub struct SliceType<'a> {
437 syntax: SyntaxNode<R>, 437 syntax: SyntaxNodeRef<'a>,
438} 438}
439 439
440impl<R: TreeRoot> AstNode<R> for SliceType<R> { 440impl<'a> AstNode<'a> for SliceType<'a> {
441 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 441 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
442 match syntax.kind() { 442 match syntax.kind() {
443 SLICE_TYPE => Some(SliceType { syntax }), 443 SLICE_TYPE => Some(SliceType { syntax }),
444 _ => None, 444 _ => None,
445 } 445 }
446 } 446 }
447 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 447 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
448} 448}
449 449
450impl<R: TreeRoot> SliceType<R> {} 450impl<'a> SliceType<'a> {}
451 451
452// StaticDef 452// StaticDef
453#[derive(Debug, Clone, Copy)] 453#[derive(Debug, Clone, Copy)]
454pub struct StaticDef<R: TreeRoot = OwnedRoot> { 454pub struct StaticDef<'a> {
455 syntax: SyntaxNode<R>, 455 syntax: SyntaxNodeRef<'a>,
456} 456}
457 457
458impl<R: TreeRoot> AstNode<R> for StaticDef<R> { 458impl<'a> AstNode<'a> for StaticDef<'a> {
459 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 459 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
460 match syntax.kind() { 460 match syntax.kind() {
461 STATIC_DEF => Some(StaticDef { syntax }), 461 STATIC_DEF => Some(StaticDef { syntax }),
462 _ => None, 462 _ => None,
463 } 463 }
464 } 464 }
465 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 465 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
466} 466}
467 467
468impl<R: TreeRoot> ast::NameOwner<R> for StaticDef<R> {} 468impl<'a> ast::NameOwner<'a> for StaticDef<'a> {}
469impl<R: TreeRoot> ast::AttrsOwner<R> for StaticDef<R> {} 469impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {}
470impl<R: TreeRoot> StaticDef<R> {} 470impl<'a> StaticDef<'a> {}
471 471
472// StructDef 472// StructDef
473#[derive(Debug, Clone, Copy)] 473#[derive(Debug, Clone, Copy)]
474pub struct StructDef<R: TreeRoot = OwnedRoot> { 474pub struct StructDef<'a> {
475 syntax: SyntaxNode<R>, 475 syntax: SyntaxNodeRef<'a>,
476} 476}
477 477
478impl<R: TreeRoot> AstNode<R> for StructDef<R> { 478impl<'a> AstNode<'a> for StructDef<'a> {
479 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 479 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
480 match syntax.kind() { 480 match syntax.kind() {
481 STRUCT_DEF => Some(StructDef { syntax }), 481 STRUCT_DEF => Some(StructDef { syntax }),
482 _ => None, 482 _ => None,
483 } 483 }
484 } 484 }
485 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 485 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
486} 486}
487 487
488impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {} 488impl<'a> ast::NameOwner<'a> for StructDef<'a> {}
489impl<R: TreeRoot> ast::AttrsOwner<R> for StructDef<R> {} 489impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {}
490impl<R: TreeRoot> StructDef<R> { 490impl<'a> StructDef<'a> {
491 pub fn fields<'a>(&'a self) -> impl Iterator<Item = NamedField<R>> + 'a { 491 pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a {
492 self.syntax() 492 self.syntax()
493 .children() 493 .children()
494 .filter_map(NamedField::cast) 494 .filter_map(NamedField::cast)
@@ -497,100 +497,100 @@ impl<R: TreeRoot> StructDef<R> {
497 497
498// TokenTree 498// TokenTree
499#[derive(Debug, Clone, Copy)] 499#[derive(Debug, Clone, Copy)]
500pub struct TokenTree<R: TreeRoot = OwnedRoot> { 500pub struct TokenTree<'a> {
501 syntax: SyntaxNode<R>, 501 syntax: SyntaxNodeRef<'a>,
502} 502}
503 503
504impl<R: TreeRoot> AstNode<R> for TokenTree<R> { 504impl<'a> AstNode<'a> for TokenTree<'a> {
505 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 505 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
506 match syntax.kind() { 506 match syntax.kind() {
507 TOKEN_TREE => Some(TokenTree { syntax }), 507 TOKEN_TREE => Some(TokenTree { syntax }),
508 _ => None, 508 _ => None,
509 } 509 }
510 } 510 }
511 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 511 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
512} 512}
513 513
514impl<R: TreeRoot> TokenTree<R> {} 514impl<'a> TokenTree<'a> {}
515 515
516// TraitDef 516// TraitDef
517#[derive(Debug, Clone, Copy)] 517#[derive(Debug, Clone, Copy)]
518pub struct TraitDef<R: TreeRoot = OwnedRoot> { 518pub struct TraitDef<'a> {
519 syntax: SyntaxNode<R>, 519 syntax: SyntaxNodeRef<'a>,
520} 520}
521 521
522impl<R: TreeRoot> AstNode<R> for TraitDef<R> { 522impl<'a> AstNode<'a> for TraitDef<'a> {
523 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 523 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
524 match syntax.kind() { 524 match syntax.kind() {
525 TRAIT_DEF => Some(TraitDef { syntax }), 525 TRAIT_DEF => Some(TraitDef { syntax }),
526 _ => None, 526 _ => None,
527 } 527 }
528 } 528 }
529 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 529 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
530} 530}
531 531
532impl<R: TreeRoot> ast::NameOwner<R> for TraitDef<R> {} 532impl<'a> ast::NameOwner<'a> for TraitDef<'a> {}
533impl<R: TreeRoot> ast::AttrsOwner<R> for TraitDef<R> {} 533impl<'a> ast::AttrsOwner<'a> for TraitDef<'a> {}
534impl<R: TreeRoot> TraitDef<R> {} 534impl<'a> TraitDef<'a> {}
535 535
536// TupleType 536// TupleType
537#[derive(Debug, Clone, Copy)] 537#[derive(Debug, Clone, Copy)]
538pub struct TupleType<R: TreeRoot = OwnedRoot> { 538pub struct TupleType<'a> {
539 syntax: SyntaxNode<R>, 539 syntax: SyntaxNodeRef<'a>,
540} 540}
541 541
542impl<R: TreeRoot> AstNode<R> for TupleType<R> { 542impl<'a> AstNode<'a> for TupleType<'a> {
543 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 543 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
544 match syntax.kind() { 544 match syntax.kind() {
545 TUPLE_TYPE => Some(TupleType { syntax }), 545 TUPLE_TYPE => Some(TupleType { syntax }),
546 _ => None, 546 _ => None,
547 } 547 }
548 } 548 }
549 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 549 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
550} 550}
551 551
552impl<R: TreeRoot> TupleType<R> {} 552impl<'a> TupleType<'a> {}
553 553
554// TypeDef 554// TypeDef
555#[derive(Debug, Clone, Copy)] 555#[derive(Debug, Clone, Copy)]
556pub struct TypeDef<R: TreeRoot = OwnedRoot> { 556pub struct TypeDef<'a> {
557 syntax: SyntaxNode<R>, 557 syntax: SyntaxNodeRef<'a>,
558} 558}
559 559
560impl<R: TreeRoot> AstNode<R> for TypeDef<R> { 560impl<'a> AstNode<'a> for TypeDef<'a> {
561 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 561 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
562 match syntax.kind() { 562 match syntax.kind() {
563 TYPE_DEF => Some(TypeDef { syntax }), 563 TYPE_DEF => Some(TypeDef { syntax }),
564 _ => None, 564 _ => None,
565 } 565 }
566 } 566 }
567 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 567 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
568} 568}
569 569
570impl<R: TreeRoot> ast::NameOwner<R> for TypeDef<R> {} 570impl<'a> ast::NameOwner<'a> for TypeDef<'a> {}
571impl<R: TreeRoot> ast::AttrsOwner<R> for TypeDef<R> {} 571impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {}
572impl<R: TreeRoot> TypeDef<R> {} 572impl<'a> TypeDef<'a> {}
573 573
574// TypeRef 574// TypeRef
575#[derive(Debug, Clone, Copy)] 575#[derive(Debug, Clone, Copy)]
576pub enum TypeRef<R: TreeRoot = OwnedRoot> { 576pub enum TypeRef<'a> {
577 ParenType(ParenType<R>), 577 ParenType(ParenType<'a>),
578 TupleType(TupleType<R>), 578 TupleType(TupleType<'a>),
579 NeverType(NeverType<R>), 579 NeverType(NeverType<'a>),
580 PathType(PathType<R>), 580 PathType(PathType<'a>),
581 PointerType(PointerType<R>), 581 PointerType(PointerType<'a>),
582 ArrayType(ArrayType<R>), 582 ArrayType(ArrayType<'a>),
583 SliceType(SliceType<R>), 583 SliceType(SliceType<'a>),
584 ReferenceType(ReferenceType<R>), 584 ReferenceType(ReferenceType<'a>),
585 PlaceholderType(PlaceholderType<R>), 585 PlaceholderType(PlaceholderType<'a>),
586 FnPointerType(FnPointerType<R>), 586 FnPointerType(FnPointerType<'a>),
587 ForType(ForType<R>), 587 ForType(ForType<'a>),
588 ImplTraitType(ImplTraitType<R>), 588 ImplTraitType(ImplTraitType<'a>),
589 DynTraitType(DynTraitType<R>), 589 DynTraitType(DynTraitType<'a>),
590} 590}
591 591
592impl<R: TreeRoot> AstNode<R> for TypeRef<R> { 592impl<'a> AstNode<'a> for TypeRef<'a> {
593 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 593 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
594 match syntax.kind() { 594 match syntax.kind() {
595 PAREN_TYPE => Some(TypeRef::ParenType(ParenType { syntax })), 595 PAREN_TYPE => Some(TypeRef::ParenType(ParenType { syntax })),
596 TUPLE_TYPE => Some(TypeRef::TupleType(TupleType { syntax })), 596 TUPLE_TYPE => Some(TypeRef::TupleType(TupleType { syntax })),
@@ -608,7 +608,7 @@ impl<R: TreeRoot> AstNode<R> for TypeRef<R> {
608 _ => None, 608 _ => None,
609 } 609 }
610 } 610 }
611 fn syntax(&self) -> &SyntaxNode<R> { 611 fn syntax(self) -> SyntaxNodeRef<'a> {
612 match self { 612 match self {
613 TypeRef::ParenType(inner) => inner.syntax(), 613 TypeRef::ParenType(inner) => inner.syntax(),
614 TypeRef::TupleType(inner) => inner.syntax(), 614 TypeRef::TupleType(inner) => inner.syntax(),
@@ -627,5 +627,5 @@ impl<R: TreeRoot> AstNode<R> for TypeRef<R> {
627 } 627 }
628} 628}
629 629
630impl<R: TreeRoot> TypeRef<R> {} 630impl<'a> TypeRef<'a> {}
631 631
diff --git a/crates/libsyntax2/src/ast/generated.rs.tera b/crates/libsyntax2/src/ast/generated.rs.tera
index f83da0326..0572cceaa 100644
--- a/crates/libsyntax2/src/ast/generated.rs.tera
+++ b/crates/libsyntax2/src/ast/generated.rs.tera
@@ -1,21 +1,20 @@
1use std::sync::Arc;
2use { 1use {
3 ast, 2 ast,
4 SyntaxNode, SyntaxRoot, TreeRoot, AstNode, 3 SyntaxNodeRef, AstNode,
5 SyntaxKind::*, 4 SyntaxKind::*,
6}; 5};
7{% for node, methods in ast %} 6{% for node, methods in ast %}
8// {{ node }} 7// {{ node }}
9{%- if methods.enum %} 8{%- if methods.enum %}
10#[derive(Debug, Clone, Copy)] 9#[derive(Debug, Clone, Copy)]
11pub enum {{ node }}<R: TreeRoot = Arc<SyntaxRoot>> { 10pub enum {{ node }}<'a> {
12{%- for kind in methods.enum %} 11{%- for kind in methods.enum %}
13 {{ kind }}({{ kind }}<R>), 12 {{ kind }}({{ kind }}<'a>),
14{%- endfor %} 13{%- endfor %}
15} 14}
16 15
17impl<R: TreeRoot> AstNode<R> for {{ node }}<R> { 16impl<'a> AstNode<'a> for {{ node }}<'a> {
18 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 17 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
19 match syntax.kind() { 18 match syntax.kind() {
20{%- for kind in methods.enum %} 19{%- for kind in methods.enum %}
21 {{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })), 20 {{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })),
@@ -23,7 +22,7 @@ impl<R: TreeRoot> AstNode<R> for {{ node }}<R> {
23 _ => None, 22 _ => None,
24 } 23 }
25 } 24 }
26 fn syntax(&self) -> &SyntaxNode<R> { 25 fn syntax(self) -> SyntaxNodeRef<'a> {
27 match self { 26 match self {
28{%- for kind in methods.enum %} 27{%- for kind in methods.enum %}
29 {{ node }}::{{ kind }}(inner) => inner.syntax(), 28 {{ node }}::{{ kind }}(inner) => inner.syntax(),
@@ -33,32 +32,32 @@ impl<R: TreeRoot> AstNode<R> for {{ node }}<R> {
33} 32}
34{% else %} 33{% else %}
35#[derive(Debug, Clone, Copy)] 34#[derive(Debug, Clone, Copy)]
36pub struct {{ node }}<R: TreeRoot = Arc<SyntaxRoot>> { 35pub struct {{ node }}<'a> {
37 syntax: SyntaxNode<R>, 36 syntax: SyntaxNodeRef<'a>,
38} 37}
39 38
40impl<R: TreeRoot> AstNode<R> for {{ node }}<R> { 39impl<'a> AstNode<'a> for {{ node }}<'a> {
41 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 40 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
42 match syntax.kind() { 41 match syntax.kind() {
43 {{ node | SCREAM }} => Some({{ node }} { syntax }), 42 {{ node | SCREAM }} => Some({{ node }} { syntax }),
44 _ => None, 43 _ => None,
45 } 44 }
46 } 45 }
47 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 46 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
48} 47}
49{% endif %} 48{% endif %}
50{% if methods.traits -%} 49{% if methods.traits -%}
51{%- for t in methods.traits -%} 50{%- for t in methods.traits -%}
52impl<R: TreeRoot> ast::{{ t }}<R> for {{ node }}<R> {} 51impl<'a> ast::{{ t }}<'a> for {{ node }}<'a> {}
53{% endfor -%} 52{% endfor -%}
54{%- endif -%} 53{%- endif -%}
55 54
56impl<R: TreeRoot> {{ node }}<R> { 55impl<'a> {{ node }}<'a> {
57{%- if methods.collections -%} 56{%- if methods.collections -%}
58{%- for m in methods.collections -%} 57{%- for m in methods.collections -%}
59{%- set method_name = m.0 -%} 58{%- set method_name = m.0 -%}
60{%- set ChildName = m.1 %} 59{%- set ChildName = m.1 %}
61 pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator<Item = {{ ChildName }}<R>> + 'a { 60 pub fn {{ method_name }}(self) -> impl Iterator<Item = {{ ChildName }}<'a>> + 'a {
62 self.syntax() 61 self.syntax()
63 .children() 62 .children()
64 .filter_map({{ ChildName }}::cast) 63 .filter_map({{ ChildName }}::cast)
@@ -70,7 +69,7 @@ impl<R: TreeRoot> {{ node }}<R> {
70{%- for m in methods.options -%} 69{%- for m in methods.options -%}
71{%- set method_name = m.0 -%} 70{%- set method_name = m.0 -%}
72{%- set ChildName = m.1 %} 71{%- set ChildName = m.1 %}
73 pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}<R>> { 72 pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> {
74 self.syntax() 73 self.syntax()
75 .children() 74 .children()
76 .filter_map({{ ChildName }}::cast) 75 .filter_map({{ ChildName }}::cast)
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs
index b52230e9c..46509b5ec 100644
--- a/crates/libsyntax2/src/ast/mod.rs
+++ b/crates/libsyntax2/src/ast/mod.rs
@@ -4,22 +4,19 @@ use itertools::Itertools;
4use smol_str::SmolStr; 4use smol_str::SmolStr;
5 5
6use { 6use {
7 SyntaxNode, SyntaxNodeRef, OwnedRoot, TreeRoot, SyntaxError, 7 SyntaxNode, SyntaxNodeRef, TreeRoot, SyntaxError,
8 SyntaxKind::*, 8 SyntaxKind::*,
9}; 9};
10pub use self::generated::*; 10pub use self::generated::*;
11 11
12pub trait AstNode<R: TreeRoot> { 12pub trait AstNode<'a>: Clone + Copy {
13 fn cast(syntax: SyntaxNode<R>) -> Option<Self> 13 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self>
14 where Self: Sized; 14 where Self: Sized;
15 fn syntax(&self) -> &SyntaxNode<R>; 15 fn syntax(self) -> SyntaxNodeRef<'a>;
16 fn syntax_ref<'a>(&'a self) -> SyntaxNodeRef<'a> where R: 'a {
17 self.syntax().as_ref()
18 }
19} 16}
20 17
21pub trait NameOwner<R: TreeRoot>: AstNode<R> { 18pub trait NameOwner<'a>: AstNode<'a> {
22 fn name(&self) -> Option<Name<R>> { 19 fn name(self) -> Option<Name<'a>> {
23 self.syntax() 20 self.syntax()
24 .children() 21 .children()
25 .filter_map(Name::cast) 22 .filter_map(Name::cast)
@@ -27,27 +24,37 @@ pub trait NameOwner<R: TreeRoot>: AstNode<R> {
27 } 24 }
28} 25}
29 26
30pub trait AttrsOwner<R: TreeRoot>: AstNode<R> { 27pub trait AttrsOwner<'a>: AstNode<'a> {
31 fn attrs<'a>(&'a self) -> Box<Iterator<Item=Attr<R>> + 'a> where R: 'a { 28 fn attrs(&self) -> Box<Iterator<Item=Attr<'a>> + 'a> {
32 let it = self.syntax().children() 29 let it = self.syntax().children()
33 .filter_map(Attr::cast); 30 .filter_map(Attr::cast);
34 Box::new(it) 31 Box::new(it)
35 } 32 }
36} 33}
37 34
38impl File<OwnedRoot> { 35#[derive(Clone, Debug)]
39 pub fn parse(text: &str) -> Self { 36pub struct ParsedFile {
40 File::cast(::parse(text)).unwrap() 37 root: SyntaxNode
41 }
42} 38}
43 39
44impl<R: TreeRoot> File<R> { 40impl ParsedFile {
41 pub fn parse(text: &str) -> Self {
42 let root = ::parse(text);
43 ParsedFile { root }
44 }
45 pub fn ast(&self) -> File {
46 File::cast(self.syntax()).unwrap()
47 }
48 pub fn syntax(&self) -> SyntaxNodeRef {
49 self.root.as_ref()
50 }
45 pub fn errors(&self) -> Vec<SyntaxError> { 51 pub fn errors(&self) -> Vec<SyntaxError> {
46 self.syntax().root.syntax_root().errors.clone() 52 self.syntax().root.syntax_root().errors.clone()
47 } 53 }
54
48} 55}
49 56
50impl<R: TreeRoot> FnDef<R> { 57impl<'a> FnDef<'a> {
51 pub fn has_atom_attr(&self, atom: &str) -> bool { 58 pub fn has_atom_attr(&self, atom: &str) -> bool {
52 self.attrs() 59 self.attrs()
53 .filter_map(|x| x.as_atom()) 60 .filter_map(|x| x.as_atom())
@@ -55,7 +62,7 @@ impl<R: TreeRoot> FnDef<R> {
55 } 62 }
56} 63}
57 64
58impl<R: TreeRoot> Attr<R> { 65impl<'a> Attr<'a> {
59 pub fn as_atom(&self) -> Option<SmolStr> { 66 pub fn as_atom(&self) -> Option<SmolStr> {
60 let tt = self.value()?; 67 let tt = self.value()?;
61 let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; 68 let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?;
@@ -66,7 +73,7 @@ impl<R: TreeRoot> Attr<R> {
66 } 73 }
67 } 74 }
68 75
69 pub fn as_call(&self) -> Option<(SmolStr, TokenTree<R>)> { 76 pub fn as_call(&self) -> Option<(SmolStr, TokenTree<'a>)> {
70 let tt = self.value()?; 77 let tt = self.value()?;
71 let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; 78 let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?;
72 let args = TokenTree::cast(args)?; 79 let args = TokenTree::cast(args)?;
@@ -78,7 +85,7 @@ impl<R: TreeRoot> Attr<R> {
78 } 85 }
79} 86}
80 87
81impl<R: TreeRoot> Name<R> { 88impl<'a> Name<'a> {
82 pub fn text(&self) -> SmolStr { 89 pub fn text(&self) -> SmolStr {
83 let ident = self.syntax().first_child() 90 let ident = self.syntax().first_child()
84 .unwrap(); 91 .unwrap();
@@ -86,7 +93,7 @@ impl<R: TreeRoot> Name<R> {
86 } 93 }
87} 94}
88 95
89impl<R: TreeRoot> NameRef<R> { 96impl<'a> NameRef<'a> {
90 pub fn text(&self) -> SmolStr { 97 pub fn text(&self) -> SmolStr {
91 let ident = self.syntax().first_child() 98 let ident = self.syntax().first_child()
92 .unwrap(); 99 .unwrap();
@@ -94,22 +101,22 @@ impl<R: TreeRoot> NameRef<R> {
94 } 101 }
95} 102}
96 103
97impl <R: TreeRoot> ImplItem<R> { 104impl<'a> ImplItem<'a> {
98 pub fn target_type(&self) -> Option<TypeRef<R>> { 105 pub fn target_type(&self) -> Option<TypeRef<'a>> {
99 match self.target() { 106 match self.target() {
100 (Some(t), None) | (_, Some(t)) => Some(t), 107 (Some(t), None) | (_, Some(t)) => Some(t),
101 _ => None, 108 _ => None,
102 } 109 }
103 } 110 }
104 111
105 pub fn target_trait(&self) -> Option<TypeRef<R>> { 112 pub fn target_trait(&self) -> Option<TypeRef<'a>> {
106 match self.target() { 113 match self.target() {
107 (Some(t), Some(_)) => Some(t), 114 (Some(t), Some(_)) => Some(t),
108 _ => None, 115 _ => None,
109 } 116 }
110 } 117 }
111 118
112 fn target(&self) -> (Option<TypeRef<R>>, Option<TypeRef<R>>) { 119 fn target(&self) -> (Option<TypeRef<'a>>, Option<TypeRef<'a>>) {
113 let mut types = self.syntax().children().filter_map(TypeRef::cast); 120 let mut types = self.syntax().children().filter_map(TypeRef::cast);
114 let first = types.next(); 121 let first = types.next();
115 let second = types.next(); 122 let second = types.next();
@@ -117,9 +124,9 @@ impl <R: TreeRoot> ImplItem<R> {
117 } 124 }
118} 125}
119 126
120impl <R: TreeRoot> Module<R> { 127impl<'a> Module<'a> {
121 pub fn has_semi(&self) -> bool { 128 pub fn has_semi(&self) -> bool {
122 match self.syntax_ref().last_child() { 129 match self.syntax().last_child() {
123 None => false, 130 None => false,
124 Some(node) => node.kind() == SEMI, 131 Some(node) => node.kind() == SEMI,
125 } 132 }