aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-29 10:48:32 +0100
committerAleksey Kladov <[email protected]>2020-07-29 11:04:22 +0100
commit627eddbc7e5eb13fc17c1c655ee1c3864c6dd4fe (patch)
tree2c0b87a578496194db0e423e8488f9f6d5a57d76 /xtask
parent04d2b7b256657f8e6816f8ed67aa5608bfe9e261 (diff)
Owned AST IR
Diffstat (limited to 'xtask')
-rw-r--r--xtask/src/ast_src.rs3830
-rw-r--r--xtask/src/codegen/gen_syntax.rs29
2 files changed, 1934 insertions, 1925 deletions
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs
index 392648d71..425814d73 100644
--- a/xtask/src/ast_src.rs
+++ b/xtask/src/ast_src.rs
@@ -223,35 +223,35 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
223 ], 223 ],
224}; 224};
225 225
226pub(crate) struct AstSrc<'a> { 226pub(crate) struct AstSrc {
227 pub(crate) tokens: &'a [&'a str], 227 pub(crate) tokens: Vec<String>,
228 pub(crate) nodes: &'a [AstNodeSrc<'a>], 228 pub(crate) nodes: Vec<AstNodeSrc>,
229 pub(crate) enums: &'a [AstEnumSrc<'a>], 229 pub(crate) enums: Vec<AstEnumSrc>,
230} 230}
231 231
232pub(crate) struct AstNodeSrc<'a> { 232pub(crate) struct AstNodeSrc {
233 pub(crate) doc: &'a [&'a str], 233 pub(crate) doc: Vec<String>,
234 pub(crate) name: &'a str, 234 pub(crate) name: String,
235 pub(crate) traits: &'a [&'a str], 235 pub(crate) traits: Vec<String>,
236 pub(crate) fields: &'a [Field<'a>], 236 pub(crate) fields: Vec<Field>,
237} 237}
238 238
239pub(crate) enum Field<'a> { 239pub(crate) enum Field {
240 Token(&'a str), 240 Token(String),
241 Node { name: &'a str, src: FieldSrc<'a> }, 241 Node { name: String, src: FieldSrc },
242} 242}
243 243
244pub(crate) enum FieldSrc<'a> { 244pub(crate) enum FieldSrc {
245 Shorthand, 245 Shorthand,
246 Optional(&'a str), 246 Optional(String),
247 Many(&'a str), 247 Many(String),
248} 248}
249 249
250pub(crate) struct AstEnumSrc<'a> { 250pub(crate) struct AstEnumSrc {
251 pub(crate) doc: &'a [&'a str], 251 pub(crate) doc: Vec<String>,
252 pub(crate) name: &'a str, 252 pub(crate) name: String,
253 pub(crate) traits: &'a [&'a str], 253 pub(crate) traits: Vec<String>,
254 pub(crate) variants: &'a [&'a str], 254 pub(crate) variants: Vec<String>,
255} 255}
256 256
257macro_rules! ast_nodes { 257macro_rules! ast_nodes {
@@ -261,12 +261,12 @@ macro_rules! ast_nodes {
261 $($field_name:ident $(![$token:tt])? $(: $ty:tt)?),*$(,)? 261 $($field_name:ident $(![$token:tt])? $(: $ty:tt)?),*$(,)?
262 } 262 }
263 )*) => { 263 )*) => {
264 [$( 264 vec![$(
265 AstNodeSrc { 265 AstNodeSrc {
266 doc: &[$($doc),*], 266 doc: vec![$($doc.to_string()),*],
267 name: stringify!($name), 267 name: stringify!($name).to_string(),
268 traits: &[$($(stringify!($trait)),*)?], 268 traits: vec![$($(stringify!($trait).to_string()),*)?],
269 fields: &[ 269 fields: vec![
270 $(field!($(T![$token])? $field_name $($ty)?)),* 270 $(field!($(T![$token])? $field_name $($ty)?)),*
271 ], 271 ],
272 272
@@ -277,16 +277,22 @@ macro_rules! ast_nodes {
277 277
278macro_rules! field { 278macro_rules! field {
279 (T![$token:tt] T) => { 279 (T![$token:tt] T) => {
280 Field::Token(stringify!($token)) 280 Field::Token(stringify!($token).to_string())
281 }; 281 };
282 ($field_name:ident) => { 282 ($field_name:ident) => {
283 Field::Node { name: stringify!($field_name), src: FieldSrc::Shorthand } 283 Field::Node { name: stringify!($field_name).to_string(), src: FieldSrc::Shorthand }
284 }; 284 };
285 ($field_name:ident [$ty:ident]) => { 285 ($field_name:ident [$ty:ident]) => {
286 Field::Node { name: stringify!($field_name), src: FieldSrc::Many(stringify!($ty)) } 286 Field::Node {
287 name: stringify!($field_name).to_string(),
288 src: FieldSrc::Many(stringify!($ty).to_string()),
289 }
287 }; 290 };
288 ($field_name:ident $ty:ident) => { 291 ($field_name:ident $ty:ident) => {
289 Field::Node { name: stringify!($field_name), src: FieldSrc::Optional(stringify!($ty)) } 292 Field::Node {
293 name: stringify!($field_name).to_string(),
294 src: FieldSrc::Optional(stringify!($ty).to_string()),
295 }
290 }; 296 };
291} 297}
292 298
@@ -297,1947 +303,1949 @@ macro_rules! ast_enums {
297 $($variant:ident),*$(,)? 303 $($variant:ident),*$(,)?
298 } 304 }
299 )*) => { 305 )*) => {
300 [$( 306 vec![$(
301 AstEnumSrc { 307 AstEnumSrc {
302 doc: &[$($doc),*], 308 doc: vec![$($doc.to_string()),*],
303 name: stringify!($name), 309 name: stringify!($name).to_string(),
304 traits: &[$($(stringify!($trait)),*)?], 310 traits: vec![$($(stringify!($trait).to_string()),*)?],
305 variants: &[$(stringify!($variant)),*], 311 variants: vec![$(stringify!($variant).to_string()),*],
306 } 312 }
307 ),*] 313 ),*]
308 }; 314 };
309} 315}
310 316
311pub(crate) const AST_SRC: AstSrc = AstSrc { 317pub(crate) fn rust_ast() -> AstSrc {
312 tokens: &["Whitespace", "Comment", "String", "RawString"], 318 AstSrc {
313 nodes: &ast_nodes! { 319 tokens: vec!["Whitespace".into(), "Comment".into(), "String".into(), "RawString".into()],
314 /// The entire Rust source file. Includes all top-level inner attributes and module items. 320 nodes: ast_nodes! {
315 /// 321 /// The entire Rust source file. Includes all top-level inner attributes and module items.
316 /// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html) 322 ///
317 struct SourceFile: ModuleItemOwner, AttrsOwner, DocCommentsOwner { 323 /// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html)
318 modules: [Module], 324 struct SourceFile: ModuleItemOwner, AttrsOwner, DocCommentsOwner {
319 } 325 modules: [Module],
326 }
320 327
321 /// Function definition either with body or not. 328 /// Function definition either with body or not.
322 /// Includes all of its attributes and doc comments. 329 /// Includes all of its attributes and doc comments.
323 /// 330 ///
324 /// ``` 331 /// ```
325 /// ❰ 332 /// ❰
326 /// /// Docs 333 /// /// Docs
327 /// #[attr] 334 /// #[attr]
328 /// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32 335 /// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32
329 /// where 336 /// where
330 /// T: Debug 337 /// T: Debug
331 /// { 338 /// {
332 /// 42 339 /// 42
333 /// } 340 /// }
334 /// ❱ 341 /// ❱
335 /// 342 ///
336 /// extern "C" { 343 /// extern "C" {
337 /// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱ 344 /// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱
338 /// } 345 /// }
339 /// ``` 346 /// ```
340 /// 347 ///
341 /// - [Reference](https://doc.rust-lang.org/reference/items/functions.html) 348 /// - [Reference](https://doc.rust-lang.org/reference/items/functions.html)
342 /// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions) 349 /// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions)
343 struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner { 350 struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner {
344 Abi, 351 Abi,
345 T![const], 352 T![const],
346 T![default], 353 T![default],
347 T![async], 354 T![async],
348 T![unsafe], 355 T![unsafe],
349 T![fn], 356 T![fn],
350 ParamList, 357 ParamList,
351 RetType, 358 RetType,
352 body: BlockExpr, 359 body: BlockExpr,
353 T![;] 360 T![;]
354 } 361 }
355 362
356 /// Return type annotation. 363 /// Return type annotation.
357 /// 364 ///
358 /// ``` 365 /// ```
359 /// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) } 366 /// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) }
360 /// ``` 367 /// ```
361 /// 368 ///
362 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) 369 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
363 struct RetType { T![->], TypeRef } 370 struct RetType { T![->], TypeRef }
364 371
365 /// Struct definition. 372 /// Struct definition.
366 /// Includes all of its attributes and doc comments. 373 /// Includes all of its attributes and doc comments.
367 /// 374 ///
368 /// ``` 375 /// ```
369 /// ❰ 376 /// ❰
370 /// /// Docs 377 /// /// Docs
371 /// #[attr] 378 /// #[attr]
372 /// struct Foo<T> where T: Debug { 379 /// struct Foo<T> where T: Debug {
373 /// /// Docs 380 /// /// Docs
374 /// #[attr] 381 /// #[attr]
375 /// pub a: u32, 382 /// pub a: u32,
376 /// b: T, 383 /// b: T,
377 /// } 384 /// }
378 /// ❱ 385 /// ❱
379 /// 386 ///
380 /// ❰ struct Foo; ❱ 387 /// ❰ struct Foo; ❱
381 /// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱ 388 /// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱
382 /// ``` 389 /// ```
383 /// 390 ///
384 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) 391 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
385 struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { 392 struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
386 T![struct], 393 T![struct],
387 FieldDefList, 394 FieldDefList,
388 T![;] 395 T![;]
389 } 396 }
390 397
391 /// Union definition. 398 /// Union definition.
392 /// Includes all of its attributes and doc comments. 399 /// Includes all of its attributes and doc comments.
393 /// 400 ///
394 /// ``` 401 /// ```
395 /// ❰ 402 /// ❰
396 /// /// Docs 403 /// /// Docs
397 /// #[attr] 404 /// #[attr]
398 /// pub union Foo<T> where T: Debug { 405 /// pub union Foo<T> where T: Debug {
399 /// /// Docs 406 /// /// Docs
400 /// #[attr] 407 /// #[attr]
401 /// a: T, 408 /// a: T,
402 /// b: u32, 409 /// b: u32,
403 /// } 410 /// }
404 /// ❱ 411 /// ❱
405 /// ``` 412 /// ```
406 /// 413 ///
407 /// [Reference](https://doc.rust-lang.org/reference/items/unions.html) 414 /// [Reference](https://doc.rust-lang.org/reference/items/unions.html)
408 struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { 415 struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
409 T![union], 416 T![union],
410 RecordFieldDefList, 417 RecordFieldDefList,
411 } 418 }
412 419
413 /// Record field definition list including enclosing curly braces. 420 /// Record field definition list including enclosing curly braces.
414 /// 421 ///
415 /// ``` 422 /// ```
416 /// struct Foo // same for union 423 /// struct Foo // same for union
417 /// ❰ 424 /// ❰
418 /// { 425 /// {
419 /// a: u32, 426 /// a: u32,
420 /// b: bool, 427 /// b: bool,
421 /// } 428 /// }
422 /// ❱ 429 /// ❱
423 /// ``` 430 /// ```
424 /// 431 ///
425 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) 432 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
426 struct RecordFieldDefList { T!['{'], fields: [RecordFieldDef], T!['}'] } 433 struct RecordFieldDefList { T!['{'], fields: [RecordFieldDef], T!['}'] }
427 434
428 /// Record field definition including its attributes and doc comments. 435 /// Record field definition including its attributes and doc comments.
429 /// 436 ///
430 /// ` `` 437 /// ` ``
431 /// same for union 438 /// same for union
432 /// struct Foo { 439 /// struct Foo {
433 /// ❰ 440 /// ❰
434 /// /// Docs 441 /// /// Docs
435 /// #[attr] 442 /// #[attr]
436 /// pub a: u32 443 /// pub a: u32
437 /// ❱ 444 /// ❱
438 /// 445 ///
439 /// ❰ b: bool ❱ 446 /// ❰ b: bool ❱
440 /// } 447 /// }
441 /// ``` 448 /// ```
442 /// 449 ///
443 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) 450 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
444 struct RecordFieldDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { } 451 struct RecordFieldDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { }
445 452
446 /// Tuple field definition list including enclosing parens. 453 /// Tuple field definition list including enclosing parens.
447 /// 454 ///
448 /// ``` 455 /// ```
449 /// struct Foo ❰ (u32, String, Vec<u32>) ❱; 456 /// struct Foo ❰ (u32, String, Vec<u32>) ❱;
450 /// ``` 457 /// ```
451 /// 458 ///
452 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) 459 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
453 struct TupleFieldDefList { T!['('], fields: [TupleFieldDef], T![')'] } 460 struct TupleFieldDefList { T!['('], fields: [TupleFieldDef], T![')'] }
454 461
455 /// Tuple field definition including its attributes. 462 /// Tuple field definition including its attributes.
456 /// 463 ///
457 /// ``` 464 /// ```
458 /// struct Foo(❰ #[attr] u32 ❱); 465 /// struct Foo(❰ #[attr] u32 ❱);
459 /// ``` 466 /// ```
460 /// 467 ///
461 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) 468 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
462 struct TupleFieldDef: VisibilityOwner, AttrsOwner { 469 struct TupleFieldDef: VisibilityOwner, AttrsOwner {
463 TypeRef, 470 TypeRef,
464 } 471 }
465 472
466 /// Enum definition. 473 /// Enum definition.
467 /// Includes all of its attributes and doc comments. 474 /// Includes all of its attributes and doc comments.
468 /// 475 ///
469 /// ``` 476 /// ```
470 /// ❰ 477 /// ❰
471 /// /// Docs 478 /// /// Docs
472 /// #[attr] 479 /// #[attr]
473 /// pub enum Foo<T> where T: Debug { 480 /// pub enum Foo<T> where T: Debug {
474 /// /// Docs 481 /// /// Docs
475 /// #[attr] 482 /// #[attr]
476 /// Bar, 483 /// Bar,
477 /// Baz(#[attr] u32), 484 /// Baz(#[attr] u32),
478 /// Bruh { 485 /// Bruh {
479 /// a: u32, 486 /// a: u32,
480 /// /// Docs 487 /// /// Docs
481 /// #[attr] 488 /// #[attr]
482 /// b: T, 489 /// b: T,
483 /// } 490 /// }
484 /// } 491 /// }
485 /// ❱ 492 /// ❱
486 /// ``` 493 /// ```
487 /// 494 ///
488 /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) 495 /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
489 struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { 496 struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
490 T![enum], 497 T![enum],
491 variant_list: EnumVariantList, 498 variant_list: EnumVariantList,
492 } 499 }
493 500
494 /// Enum variant definition list including enclosing curly braces. 501 /// Enum variant definition list including enclosing curly braces.
495 /// 502 ///
496 /// ``` 503 /// ```
497 /// enum Foo 504 /// enum Foo
498 /// ❰ 505 /// ❰
499 /// { 506 /// {
500 /// Bar, 507 /// Bar,
501 /// Baz(u32), 508 /// Baz(u32),
502 /// Bruh { 509 /// Bruh {
503 /// a: u32 510 /// a: u32
504 /// } 511 /// }
505 /// } 512 /// }
506 /// ❱ 513 /// ❱
507 /// ``` 514 /// ```
508 /// 515 ///
509 /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) 516 /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
510 struct EnumVariantList { 517 struct EnumVariantList {
511 T!['{'], 518 T!['{'],
512 variants: [EnumVariant], 519 variants: [EnumVariant],
513 T!['}'] 520 T!['}']
514 } 521 }
515 522
516 /// Enum variant definition including its attributes and discriminant value definition. 523 /// Enum variant definition including its attributes and discriminant value definition.
517 /// 524 ///
518 /// ``` 525 /// ```
519 /// enum Foo { 526 /// enum Foo {
520 /// ❰ 527 /// ❰
521 /// /// Docs 528 /// /// Docs
522 /// #[attr] 529 /// #[attr]
523 /// Bar 530 /// Bar
524 /// ❱ 531 /// ❱
525 /// 532 ///
526 /// // same for tuple and record variants 533 /// // same for tuple and record variants
527 /// } 534 /// }
528 /// ``` 535 /// ```
529 /// 536 ///
530 /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) 537 /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
531 struct EnumVariant: VisibilityOwner, NameOwner, DocCommentsOwner, AttrsOwner { 538 struct EnumVariant: VisibilityOwner, NameOwner, DocCommentsOwner, AttrsOwner {
532 FieldDefList, 539 FieldDefList,
533 T![=], 540 T![=],
534 Expr 541 Expr
535 } 542 }
536 543
537 /// Trait definition. 544 /// Trait definition.
538 /// Includes all of its attributes and doc comments. 545 /// Includes all of its attributes and doc comments.
539 /// 546 ///
540 /// ``` 547 /// ```
541 /// ❰ 548 /// ❰
542 /// /// Docs 549 /// /// Docs
543 /// #[attr] 550 /// #[attr]
544 /// pub unsafe trait Foo<T>: Debug where T: Debug { 551 /// pub unsafe trait Foo<T>: Debug where T: Debug {
545 /// // ... 552 /// // ...
546 /// } 553 /// }
547 /// ❱ 554 /// ❱
548 /// ``` 555 /// ```
549 /// 556 ///
550 /// [Reference](https://doc.rust-lang.org/reference/items/traits.html) 557 /// [Reference](https://doc.rust-lang.org/reference/items/traits.html)
551 struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner { 558 struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner {
552 T![unsafe], 559 T![unsafe],
553 T![auto], 560 T![auto],
554 T![trait], 561 T![trait],
555 ItemList, 562 ItemList,
556 } 563 }
557 564
558 /// Module definition either with body or not. 565 /// Module definition either with body or not.
559 /// Includes all of its inner and outer attributes, module items, doc comments. 566 /// Includes all of its inner and outer attributes, module items, doc comments.
560 /// 567 ///
561 /// ``` 568 /// ```
562 /// ❰ 569 /// ❰
563 /// /// Docs 570 /// /// Docs
564 /// #[attr] 571 /// #[attr]
565 /// pub mod foo; 572 /// pub mod foo;
566 /// ❱ 573 /// ❱
567 /// 574 ///
568 /// ❰ 575 /// ❰
569 /// /// Docs 576 /// /// Docs
570 /// #[attr] 577 /// #[attr]
571 /// pub mod bar { 578 /// pub mod bar {
572 /// //! Inner docs 579 /// //! Inner docs
573 /// #![inner_attr] 580 /// #![inner_attr]
574 /// } 581 /// }
575 /// ❱ 582 /// ❱
576 /// ``` 583 /// ```
577 /// 584 ///
578 /// [Reference](https://doc.rust-lang.org/reference/items/modules.html) 585 /// [Reference](https://doc.rust-lang.org/reference/items/modules.html)
579 struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner { 586 struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner {
580 T![mod], 587 T![mod],
581 ItemList, 588 ItemList,
582 T![;] 589 T![;]
583 } 590 }
584 591
585 /// Item defintion list. 592 /// Item defintion list.
586 /// This is used for both top-level items and impl block items. 593 /// This is used for both top-level items and impl block items.
587 /// 594 ///
588 /// ``` 595 /// ```
589 /// ❰ 596 /// ❰
590 /// fn foo {} 597 /// fn foo {}
591 /// struct Bar; 598 /// struct Bar;
592 /// enum Baz; 599 /// enum Baz;
593 /// trait Bruh; 600 /// trait Bruh;
594 /// const BRUUH: u32 = 42; 601 /// const BRUUH: u32 = 42;
595 /// ❱ 602 /// ❱
596 /// 603 ///
597 /// impl Foo 604 /// impl Foo
598 /// ❰ 605 /// ❰
599 /// { 606 /// {
600 /// fn bar() {} 607 /// fn bar() {}
601 /// const BAZ: u32 = 42; 608 /// const BAZ: u32 = 42;
602 /// } 609 /// }
603 /// ❱ 610 /// ❱
604 /// ``` 611 /// ```
605 /// 612 ///
606 /// [Reference](https://doc.rust-lang.org/reference/items.html) 613 /// [Reference](https://doc.rust-lang.org/reference/items.html)
607 struct ItemList: ModuleItemOwner { 614 struct ItemList: ModuleItemOwner {
608 T!['{'], 615 T!['{'],
609 assoc_items: [AssocItem], 616 assoc_items: [AssocItem],
610 T!['}'] 617 T!['}']
611 } 618 }
612 619
613 /// Constant variable definition. 620 /// Constant variable definition.
614 /// Includes all of its attributes and doc comments. 621 /// Includes all of its attributes and doc comments.
615 /// 622 ///
616 /// ``` 623 /// ```
617 /// ❰ 624 /// ❰
618 /// /// Docs 625 /// /// Docs
619 /// #[attr] 626 /// #[attr]
620 /// pub const FOO: u32 = 42; 627 /// pub const FOO: u32 = 42;
621 /// ❱ 628 /// ❱
622 /// ``` 629 /// ```
623 /// 630 ///
624 /// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html) 631 /// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html)
625 struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { 632 struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
626 T![default], 633 T![default],
627 T![const], 634 T![const],
628 T![=], 635 T![=],
629 body: Expr, 636 body: Expr,
630 T![;] 637 T![;]
631 } 638 }
632 639
633 640
634 /// Static variable definition. 641 /// Static variable definition.
635 /// Includes all of its attributes and doc comments. 642 /// Includes all of its attributes and doc comments.
636 /// 643 ///
637 /// ``` 644 /// ```
638 /// ❰ 645 /// ❰
639 /// /// Docs 646 /// /// Docs
640 /// #[attr] 647 /// #[attr]
641 /// pub static mut FOO: u32 = 42; 648 /// pub static mut FOO: u32 = 42;
642 /// ❱ 649 /// ❱
643 /// ``` 650 /// ```
644 /// 651 ///
645 /// [Reference](https://doc.rust-lang.org/reference/items/static-items.html) 652 /// [Reference](https://doc.rust-lang.org/reference/items/static-items.html)
646 struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { 653 struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
647 T![static], 654 T![static],
648 T![mut], 655 T![mut],
649 T![=], 656 T![=],
650 body: Expr, 657 body: Expr,
651 T![;] 658 T![;]
652 } 659 }
653 660
654 /// Type alias definition. 661 /// Type alias definition.
655 /// Includes associated type clauses with type bounds. 662 /// Includes associated type clauses with type bounds.
656 /// 663 ///
657 /// ``` 664 /// ```
658 /// ❰ 665 /// ❰
659 /// /// Docs 666 /// /// Docs
660 /// #[attr] 667 /// #[attr]
661 /// pub type Foo<T> where T: Debug = T; 668 /// pub type Foo<T> where T: Debug = T;
662 /// ❱ 669 /// ❱
663 /// 670 ///
664 /// trait Bar { 671 /// trait Bar {
665 /// ❰ type Baz: Debug; ❱ 672 /// ❰ type Baz: Debug; ❱
666 /// ❰ type Bruh = String; ❱ 673 /// ❰ type Bruh = String; ❱
667 /// ❰ type Bruuh: Debug = u32; ❱ 674 /// ❰ type Bruuh: Debug = u32; ❱
668 /// } 675 /// }
669 /// ``` 676 /// ```
670 /// 677 ///
671 /// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html) 678 /// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html)
672 struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner { 679 struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner {
673 T![default], 680 T![default],
674 T![type], 681 T![type],
675 T![=], 682 T![=],
676 TypeRef, 683 TypeRef,
677 T![;] 684 T![;]
678 } 685 }
679 686
680 /// Inherent and trait impl definition. 687 /// Inherent and trait impl definition.
681 /// Includes all of its inner and outer attributes. 688 /// Includes all of its inner and outer attributes.
682 /// 689 ///
683 /// ``` 690 /// ```
684 /// ❰ 691 /// ❰
685 /// #[attr] 692 /// #[attr]
686 /// unsafe impl<T> const !Foo for Bar where T: Debug { 693 /// unsafe impl<T> const !Foo for Bar where T: Debug {
687 /// #![inner_attr] 694 /// #![inner_attr]
688 /// // ... 695 /// // ...
689 /// } 696 /// }
690 /// ❱ 697 /// ❱
691 /// ``` 698 /// ```
692 /// 699 ///
693 /// [Reference](https://doc.rust-lang.org/reference/items/implementations.html) 700 /// [Reference](https://doc.rust-lang.org/reference/items/implementations.html)
694 struct ImplDef: TypeParamsOwner, AttrsOwner, DocCommentsOwner { 701 struct ImplDef: TypeParamsOwner, AttrsOwner, DocCommentsOwner {
695 T![default], 702 T![default],
696 T![const], 703 T![const],
697 T![unsafe], 704 T![unsafe],
698 T![impl], 705 T![impl],
699 T![!], 706 T![!],
700 T![for], 707 T![for],
701 ItemList, 708 ItemList,
702 } 709 }
703 710
704 711
705 /// Parenthesized type reference. 712 /// Parenthesized type reference.
706 /// Note: parens are only used for grouping, this is not a tuple type. 713 /// Note: parens are only used for grouping, this is not a tuple type.
707 /// 714 ///
708 /// ``` 715 /// ```
709 /// // This is effectively just `u32`. 716 /// // This is effectively just `u32`.
710 /// // Single-item tuple must be defined with a trailing comma: `(u32,)` 717 /// // Single-item tuple must be defined with a trailing comma: `(u32,)`
711 /// type Foo = ❰ (u32) ❱; 718 /// type Foo = ❰ (u32) ❱;
712 /// 719 ///
713 /// let bar: &'static ❰ (dyn Debug) ❱ = "bruh"; 720 /// let bar: &'static ❰ (dyn Debug) ❱ = "bruh";
714 /// ``` 721 /// ```
715 struct ParenType { T!['('], TypeRef, T![')'] } 722 struct ParenType { T!['('], TypeRef, T![')'] }
716 723
717 /// Unnamed tuple type. 724 /// Unnamed tuple type.
718 /// 725 ///
719 /// ``` 726 /// ```
720 /// let foo: ❰ (u32, bool) ❱ = (42, true); 727 /// let foo: ❰ (u32, bool) ❱ = (42, true);
721 /// ``` 728 /// ```
722 /// 729 ///
723 /// [Reference](https://doc.rust-lang.org/reference/types/tuple.html) 730 /// [Reference](https://doc.rust-lang.org/reference/types/tuple.html)
724 struct TupleType { T!['('], fields: [TypeRef], T![')'] } 731 struct TupleType { T!['('], fields: [TypeRef], T![')'] }
725 732
726 /// The never type (i.e. the exclamation point). 733 /// The never type (i.e. the exclamation point).
727 /// 734 ///
728 /// ``` 735 /// ```
729 /// type T = ❰ ! ❱; 736 /// type T = ❰ ! ❱;
730 /// 737 ///
731 /// fn no_return() -> ❰ ! ❱ { 738 /// fn no_return() -> ❰ ! ❱ {
732 /// loop {} 739 /// loop {}
733 /// } 740 /// }
734 /// ``` 741 /// ```
735 /// 742 ///
736 /// [Reference](https://doc.rust-lang.org/reference/types/never.html) 743 /// [Reference](https://doc.rust-lang.org/reference/types/never.html)
737 struct NeverType { T![!] } 744 struct NeverType { T![!] }
738 745
739 /// Path to a type. 746 /// Path to a type.
740 /// Includes single identifier type names and elaborate paths with 747 /// Includes single identifier type names and elaborate paths with
741 /// generic parameters. 748 /// generic parameters.
742 /// 749 ///
743 /// ``` 750 /// ```
744 /// type Foo = ❰ String ❱; 751 /// type Foo = ❰ String ❱;
745 /// type Bar = ❰ std::vec::Vec<T> ❱; 752 /// type Bar = ❰ std::vec::Vec<T> ❱;
746 /// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱; 753 /// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱;
747 /// ``` 754 /// ```
748 /// 755 ///
749 /// [Reference](https://doc.rust-lang.org/reference/paths.html) 756 /// [Reference](https://doc.rust-lang.org/reference/paths.html)
750 struct PathType { Path } 757 struct PathType { Path }
751 758
752 /// Raw pointer type. 759 /// Raw pointer type.
753 /// 760 ///
754 /// ``` 761 /// ```
755 /// type Foo = ❰ *const u32 ❱; 762 /// type Foo = ❰ *const u32 ❱;
756 /// type Bar = ❰ *mut u32 ❱; 763 /// type Bar = ❰ *mut u32 ❱;
757 /// ``` 764 /// ```
758 /// 765 ///
759 /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut) 766 /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut)
760 struct PointerType { T![*], T![const], T![mut], TypeRef } 767 struct PointerType { T![*], T![const], T![mut], TypeRef }
761 768
762 /// Array type. 769 /// Array type.
763 /// 770 ///
764 /// ``` 771 /// ```
765 /// type Foo = ❰ [u32; 24 - 3] ❱; 772 /// type Foo = ❰ [u32; 24 - 3] ❱;
766 /// ``` 773 /// ```
767 /// 774 ///
768 /// [Reference](https://doc.rust-lang.org/reference/types/array.html) 775 /// [Reference](https://doc.rust-lang.org/reference/types/array.html)
769 struct ArrayType { T!['['], TypeRef, T![;], Expr, T![']'] } 776 struct ArrayType { T!['['], TypeRef, T![;], Expr, T![']'] }
770 777
771 /// Slice type. 778 /// Slice type.
772 /// 779 ///
773 /// ``` 780 /// ```
774 /// type Foo = ❰ [u8] ❱; 781 /// type Foo = ❰ [u8] ❱;
775 /// ``` 782 /// ```
776 /// 783 ///
777 /// [Reference](https://doc.rust-lang.org/reference/types/slice.html) 784 /// [Reference](https://doc.rust-lang.org/reference/types/slice.html)
778 struct SliceType { T!['['], TypeRef, T![']'] } 785 struct SliceType { T!['['], TypeRef, T![']'] }
779 786
780 /// Reference type. 787 /// Reference type.
781 /// 788 ///
782 /// ``` 789 /// ```
783 /// type Foo = ❰ &'static str ❱; 790 /// type Foo = ❰ &'static str ❱;
784 /// ``` 791 /// ```
785 /// 792 ///
786 /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html) 793 /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html)
787 struct ReferenceType { T![&], T![lifetime], T![mut], TypeRef } 794 struct ReferenceType { T![&], T![lifetime], T![mut], TypeRef }
788 795
789 /// Placeholder type (i.e. the underscore). 796 /// Placeholder type (i.e. the underscore).
790 /// 797 ///
791 /// ``` 798 /// ```
792 /// let foo: ❰ _ ❱ = 42_u32; 799 /// let foo: ❰ _ ❱ = 42_u32;
793 /// ``` 800 /// ```
794 /// 801 ///
795 /// [Reference](https://doc.rust-lang.org/reference/types/inferred.html) 802 /// [Reference](https://doc.rust-lang.org/reference/types/inferred.html)
796 struct PlaceholderType { T![_] } 803 struct PlaceholderType { T![_] }
797 804
798 /// Function pointer type (not to be confused with `Fn*` family of traits). 805 /// Function pointer type (not to be confused with `Fn*` family of traits).
799 /// 806 ///
800 /// ``` 807 /// ```
801 /// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱; 808 /// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱;
802 /// 809 ///
803 /// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱; 810 /// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱;
804 /// ``` 811 /// ```
805 /// 812 ///
806 /// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html) 813 /// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html)
807 struct FnPointerType { Abi, T![unsafe], T![fn], ParamList, RetType } 814 struct FnPointerType { Abi, T![unsafe], T![fn], ParamList, RetType }
808 815
809 /// Higher order type. 816 /// Higher order type.
810 /// 817 ///
811 /// ``` 818 /// ```
812 /// type Foo = ❰ for<'a> fn(&'a str) ❱; 819 /// type Foo = ❰ for<'a> fn(&'a str) ❱;
813 /// ``` 820 /// ```
814 /// 821 ///
815 /// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html) 822 /// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html)
816 struct ForType { T![for], TypeParamList, TypeRef } 823 struct ForType { T![for], TypeParamList, TypeRef }
817 824
818 /// Opaque `impl Trait` type. 825 /// Opaque `impl Trait` type.
819 /// 826 ///
820 /// ``` 827 /// ```
821 /// fn foo(bar: ❰ impl Debug + Eq ❱) {} 828 /// fn foo(bar: ❰ impl Debug + Eq ❱) {}
822 /// ``` 829 /// ```
823 /// 830 ///
824 /// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html) 831 /// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html)
825 struct ImplTraitType: TypeBoundsOwner { T![impl] } 832 struct ImplTraitType: TypeBoundsOwner { T![impl] }
826 833
827 /// Trait object type. 834 /// Trait object type.
828 /// 835 ///
829 /// ``` 836 /// ```
830 /// type Foo = ❰ dyn Debug ❱; 837 /// type Foo = ❰ dyn Debug ❱;
831 /// ``` 838 /// ```
832 /// 839 ///
833 /// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html) 840 /// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html)
834 struct DynTraitType: TypeBoundsOwner { T![dyn] } 841 struct DynTraitType: TypeBoundsOwner { T![dyn] }
835 842
836 /// Tuple literal. 843 /// Tuple literal.
837 /// 844 ///
838 /// ``` 845 /// ```
839 /// ❰ (42, true) ❱; 846 /// ❰ (42, true) ❱;
840 /// ``` 847 /// ```
841 /// 848 ///
842 /// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html) 849 /// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html)
843 struct TupleExpr: AttrsOwner { T!['('], exprs: [Expr], T![')'] } 850 struct TupleExpr: AttrsOwner { T!['('], exprs: [Expr], T![')'] }
844 851
845 /// Array literal. 852 /// Array literal.
846 /// 853 ///
847 /// ``` 854 /// ```
848 /// ❰ [#![inner_attr] true, false, true] ❱; 855 /// ❰ [#![inner_attr] true, false, true] ❱;
849 /// 856 ///
850 /// ❰ ["baz"; 24] ❱; 857 /// ❰ ["baz"; 24] ❱;
851 /// ``` 858 /// ```
852 /// 859 ///
853 /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) 860 /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
854 struct ArrayExpr: AttrsOwner { T!['['], exprs: [Expr], T![;], T![']'] } 861 struct ArrayExpr: AttrsOwner { T!['['], exprs: [Expr], T![;], T![']'] }
855 862
856 /// Parenthesized expression. 863 /// Parenthesized expression.
857 /// Note: parens are only used for grouping, this is not a tuple literal. 864 /// Note: parens are only used for grouping, this is not a tuple literal.
858 /// 865 ///
859 /// ``` 866 /// ```
860 /// ❰ (#![inner_attr] 2 + 2) ❱ * 2; 867 /// ❰ (#![inner_attr] 2 + 2) ❱ * 2;
861 /// ``` 868 /// ```
862 /// 869 ///
863 /// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html) 870 /// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html)
864 struct ParenExpr: AttrsOwner { T!['('], Expr, T![')'] } 871 struct ParenExpr: AttrsOwner { T!['('], Expr, T![')'] }
865 872
866 /// Path to a symbol in expression context. 873 /// Path to a symbol in expression context.
867 /// Includes single identifier variable names and elaborate paths with 874 /// Includes single identifier variable names and elaborate paths with
868 /// generic parameters. 875 /// generic parameters.
869 /// 876 ///
870 /// ``` 877 /// ```
871 /// ❰ Some::<i32> ❱; 878 /// ❰ Some::<i32> ❱;
872 /// ❰ foo ❱ + 42; 879 /// ❰ foo ❱ + 42;
873 /// ❰ Vec::<i32>::push ❱; 880 /// ❰ Vec::<i32>::push ❱;
874 /// ❰ <[i32]>::reverse ❱; 881 /// ❰ <[i32]>::reverse ❱;
875 /// ❰ <String as std::borrow::Borrow<str>>::borrow ❱; 882 /// ❰ <String as std::borrow::Borrow<str>>::borrow ❱;
876 /// ``` 883 /// ```
877 /// 884 ///
878 /// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html) 885 /// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html)
879 struct PathExpr { Path } 886 struct PathExpr { Path }
880 887
881 /// Anonymous callable object literal a.k.a. closure, lambda or functor. 888 /// Anonymous callable object literal a.k.a. closure, lambda or functor.
882 /// 889 ///
883 /// ``` 890 /// ```
884 /// ❰ || 42 ❱; 891 /// ❰ || 42 ❱;
885 /// ❰ |a: u32| val + 1 ❱; 892 /// ❰ |a: u32| val + 1 ❱;
886 /// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱; 893 /// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱;
887 /// ❰ move || baz ❱; 894 /// ❰ move || baz ❱;
888 /// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱ 895 /// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱
889 /// ``` 896 /// ```
890 /// 897 ///
891 /// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html) 898 /// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html)
892 struct LambdaExpr: AttrsOwner { 899 struct LambdaExpr: AttrsOwner {
893 T![static], // Note(@matklad): I belive this is (used to be?) syntax for generators 900 T![static], // Note(@matklad): I belive this is (used to be?) syntax for generators
894 T![async], 901 T![async],
895 T![move], 902 T![move],
896 ParamList, 903 ParamList,
897 RetType, 904 RetType,
898 body: Expr, 905 body: Expr,
899 } 906 }
900 907
901 /// If expression. Includes both regular `if` and `if let` forms. 908 /// If expression. Includes both regular `if` and `if let` forms.
902 /// Beware that `else if` is a special case syntax sugar, because in general 909 /// Beware that `else if` is a special case syntax sugar, because in general
903 /// there has to be block expression after `else`. 910 /// there has to be block expression after `else`.
904 /// 911 ///
905 /// ``` 912 /// ```
906 /// ❰ if bool_cond { 42 } ❱ 913 /// ❰ if bool_cond { 42 } ❱
907 /// ❰ if bool_cond { 42 } else { 24 } ❱ 914 /// ❰ if bool_cond { 42 } else { 24 } ❱
908 /// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱ 915 /// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱
909 /// 916 ///
910 /// ❰ 917 /// ❰
911 /// if let Pattern(foo) = bar { 918 /// if let Pattern(foo) = bar {
912 /// foo 919 /// foo
913 /// } else { 920 /// } else {
914 /// panic!(); 921 /// panic!();
915 /// } 922 /// }
916 /// ❱ 923 /// ❱
917 /// ``` 924 /// ```
918 /// 925 ///
919 /// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) 926 /// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
920 struct IfExpr: AttrsOwner { T![if], Condition } 927 struct IfExpr: AttrsOwner { T![if], Condition }
921 928
922 /// Unconditional loop expression. 929 /// Unconditional loop expression.
923 /// 930 ///
924 /// ``` 931 /// ```
925 /// ❰ 932 /// ❰
926 /// loop { 933 /// loop {
927 /// // yeah, it's that simple... 934 /// // yeah, it's that simple...
928 /// } 935 /// }
929 /// ❱ 936 /// ❱
930 /// ``` 937 /// ```
931 /// 938 ///
932 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html) 939 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html)
933 struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] } 940 struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] }
934 941
935 /// Block expression with an optional prefix (label, try ketword, 942 /// Block expression with an optional prefix (label, try ketword,
936 /// unsafe keyword, async keyword...). 943 /// unsafe keyword, async keyword...).
937 /// 944 ///
938 /// ``` 945 /// ```
939 /// ❰ 946 /// ❰
940 /// 'label: try { 947 /// 'label: try {
941 /// None? 948 /// None?
942 /// } 949 /// }
943 /// ❱ 950 /// ❱
944 /// ``` 951 /// ```
945 /// 952 ///
946 /// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html) 953 /// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html)
947 /// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks) 954 /// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks)
948 /// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks) 955 /// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks)
949 struct EffectExpr: AttrsOwner { Label, T![try], T![unsafe], T![async], BlockExpr } 956 struct EffectExpr: AttrsOwner { Label, T![try], T![unsafe], T![async], BlockExpr }
950 957
951 958
952 /// For loop expression. 959 /// For loop expression.
953 /// Note: record struct literals are not valid as iterable expression 960 /// Note: record struct literals are not valid as iterable expression
954 /// due to ambiguity. 961 /// due to ambiguity.
955 /// 962 ///
956 /// ``` 963 /// ```
957 /// ❰ 964 /// ❰
958 /// for i in (0..4) { 965 /// for i in (0..4) {
959 /// dbg!(i); 966 /// dbg!(i);
960 /// } 967 /// }
961 /// ❱ 968 /// ❱
962 /// ``` 969 /// ```
963 /// 970 ///
964 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops) 971 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops)
965 struct ForExpr: AttrsOwner, LoopBodyOwner { 972 struct ForExpr: AttrsOwner, LoopBodyOwner {
966 T![for], 973 T![for],
967 Pat, 974 Pat,
968 T![in], 975 T![in],
969 iterable: Expr, 976 iterable: Expr,
970 } 977 }
971 978
972 /// While loop expression. Includes both regular `while` and `while let` forms. 979 /// While loop expression. Includes both regular `while` and `while let` forms.
973 /// 980 ///
974 /// ``` 981 /// ```
975 /// ❰ 982 /// ❰
976 /// while bool_cond { 983 /// while bool_cond {
977 /// 42; 984 /// 42;
978 /// } 985 /// }
979 /// ❱ 986 /// ❱
980 /// ❰ 987 /// ❰
981 /// while let Pattern(foo) = bar { 988 /// while let Pattern(foo) = bar {
982 /// bar += 1; 989 /// bar += 1;
983 /// } 990 /// }
984 /// ❱ 991 /// ❱
985 /// ``` 992 /// ```
986 /// 993 ///
987 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) 994 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
988 struct WhileExpr: AttrsOwner, LoopBodyOwner { T![while], Condition } 995 struct WhileExpr: AttrsOwner, LoopBodyOwner { T![while], Condition }
989 996
990 /// Continue expression. 997 /// Continue expression.
991 /// 998 ///
992 /// ``` 999 /// ```
993 /// while bool_cond { 1000 /// while bool_cond {
994 /// ❰ continue ❱; 1001 /// ❰ continue ❱;
995 /// } 1002 /// }
996 /// 1003 ///
997 /// 'outer: loop { 1004 /// 'outer: loop {
998 /// loop { 1005 /// loop {
999 /// ❰ continue 'outer ❱; 1006 /// ❰ continue 'outer ❱;
1000 /// } 1007 /// }
1001 /// } 1008 /// }
1002 /// 1009 ///
1003 /// ``` 1010 /// ```
1004 /// 1011 ///
1005 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions) 1012 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions)
1006 struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } 1013 struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] }
1007 1014
1008 /// Break expression. 1015 /// Break expression.
1009 /// 1016 ///
1010 /// ``` 1017 /// ```
1011 /// while bool_cond { 1018 /// while bool_cond {
1012 /// ❰ break ❱; 1019 /// ❰ break ❱;
1013 /// } 1020 /// }
1014 /// 'outer: loop { 1021 /// 'outer: loop {
1015 /// for foo in bar { 1022 /// for foo in bar {
1016 /// ❰ break 'outer ❱; 1023 /// ❰ break 'outer ❱;
1017 /// } 1024 /// }
1018 /// } 1025 /// }
1019 /// 'outer: loop { 1026 /// 'outer: loop {
1020 /// loop { 1027 /// loop {
1021 /// ❰ break 'outer 42 ❱; 1028 /// ❰ break 'outer 42 ❱;
1022 /// } 1029 /// }
1023 /// } 1030 /// }
1024 /// ``` 1031 /// ```
1025 /// 1032 ///
1026 /// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions) 1033 /// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions)
1027 struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } 1034 struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr }
1028 1035
1029 /// Label. 1036 /// Label.
1030 /// 1037 ///
1031 /// ``` 1038 /// ```
1032 /// ❰ 'outer: ❱ loop {} 1039 /// ❰ 'outer: ❱ loop {}
1033 /// 1040 ///
1034 /// let foo = ❰ 'bar: ❱ loop {} 1041 /// let foo = ❰ 'bar: ❱ loop {}
1035 /// 1042 ///
1036 /// ❰ 'baz: ❱ { 1043 /// ❰ 'baz: ❱ {
1037 /// break 'baz; 1044 /// break 'baz;
1038 /// } 1045 /// }
1039 /// ``` 1046 /// ```
1040 /// 1047 ///
1041 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels) 1048 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels)
1042 /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) 1049 /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
1043 struct Label { T![lifetime] } 1050 struct Label { T![lifetime] }
1044 1051
1045 /// Block expression. Includes unsafe blocks and block labels. 1052 /// Block expression. Includes unsafe blocks and block labels.
1046 /// 1053 ///
1047 /// ``` 1054 /// ```
1048 /// let foo = ❰ 1055 /// let foo = ❰
1049 /// { 1056 /// {
1050 /// #![inner_attr] 1057 /// #![inner_attr]
1051 /// ❰ { } ❱ 1058 /// ❰ { } ❱
1052 /// 1059 ///
1053 /// ❰ 'label: { break 'label } ❱ 1060 /// ❰ 'label: { break 'label } ❱
1054 /// } 1061 /// }
1055 /// ❱; 1062 /// ❱;
1056 /// ``` 1063 /// ```
1057 /// 1064 ///
1058 /// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html) 1065 /// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html)
1059 /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) 1066 /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
1060 struct BlockExpr: AttrsOwner, ModuleItemOwner { 1067 struct BlockExpr: AttrsOwner, ModuleItemOwner {
1061 Label, T!['{'], statements: [Stmt], Expr, T!['}'], 1068 Label, T!['{'], statements: [Stmt], Expr, T!['}'],
1062 } 1069 }
1063 1070
1064 /// Return expression. 1071 /// Return expression.
1065 /// 1072 ///
1066 /// ``` 1073 /// ```
1067 /// || ❰ return 42 ❱; 1074 /// || ❰ return 42 ❱;
1068 /// 1075 ///
1069 /// fn bar() { 1076 /// fn bar() {
1070 /// ❰ return ❱; 1077 /// ❰ return ❱;
1071 /// } 1078 /// }
1072 /// ``` 1079 /// ```
1073 /// 1080 ///
1074 /// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html) 1081 /// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html)
1075 struct ReturnExpr: AttrsOwner { Expr } 1082 struct ReturnExpr: AttrsOwner { Expr }
1076 1083
1077 /// Call expression (not to be confused with method call expression, it is 1084 /// Call expression (not to be confused with method call expression, it is
1078 /// a separate ast node). 1085 /// a separate ast node).
1079 /// 1086 ///
1080 /// ``` 1087 /// ```
1081 /// ❰ foo() ❱; 1088 /// ❰ foo() ❱;
1082 /// ❰ &str::len("bar") ❱; 1089 /// ❰ &str::len("bar") ❱;
1083 /// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱; 1090 /// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱;
1084 /// ``` 1091 /// ```
1085 /// 1092 ///
1086 /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) 1093 /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
1087 struct CallExpr: ArgListOwner { Expr } 1094 struct CallExpr: ArgListOwner { Expr }
1088 1095
1089 /// Method call expression. 1096 /// Method call expression.
1090 /// 1097 ///
1091 /// ``` 1098 /// ```
1092 /// ❰ receiver_expr.method() ❱; 1099 /// ❰ receiver_expr.method() ❱;
1093 /// ❰ receiver_expr.method::<T>(42, true) ❱; 1100 /// ❰ receiver_expr.method::<T>(42, true) ❱;
1094 /// 1101 ///
1095 /// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱; 1102 /// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱;
1096 /// ``` 1103 /// ```
1097 /// 1104 ///
1098 /// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html) 1105 /// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html)
1099 struct MethodCallExpr: AttrsOwner, ArgListOwner { 1106 struct MethodCallExpr: AttrsOwner, ArgListOwner {
1100 Expr, T![.], NameRef, TypeArgList, 1107 Expr, T![.], NameRef, TypeArgList,
1101 } 1108 }
1102 1109
1103 /// Index expression a.k.a. subscript operator call. 1110 /// Index expression a.k.a. subscript operator call.
1104 /// 1111 ///
1105 /// ``` 1112 /// ```
1106 /// ❰ foo[42] ❱; 1113 /// ❰ foo[42] ❱;
1107 /// ``` 1114 /// ```
1108 /// 1115 ///
1109 /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) 1116 /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
1110 struct IndexExpr: AttrsOwner { T!['['], T![']'] } 1117 struct IndexExpr: AttrsOwner { T!['['], T![']'] }
1111 1118
1112 /// Field access expression. 1119 /// Field access expression.
1113 /// 1120 ///
1114 /// ``` 1121 /// ```
1115 /// ❰ expr.bar ❱; 1122 /// ❰ expr.bar ❱;
1116 /// 1123 ///
1117 /// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱; 1124 /// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱;
1118 /// ``` 1125 /// ```
1119 /// 1126 ///
1120 /// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html) 1127 /// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html)
1121 struct FieldExpr: AttrsOwner { Expr, T![.], NameRef } 1128 struct FieldExpr: AttrsOwner { Expr, T![.], NameRef }
1122 1129
1123 /// Await operator call expression. 1130 /// Await operator call expression.
1124 /// 1131 ///
1125 /// ``` 1132 /// ```
1126 /// ❰ expr.await ❱; 1133 /// ❰ expr.await ❱;
1127 /// ``` 1134 /// ```
1128 /// 1135 ///
1129 /// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html) 1136 /// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html)
1130 struct AwaitExpr: AttrsOwner { Expr, T![.], T![await] } 1137 struct AwaitExpr: AttrsOwner { Expr, T![.], T![await] }
1131 1138
1132 /// The question mark operator call. 1139 /// The question mark operator call.
1133 /// 1140 ///
1134 /// ``` 1141 /// ```
1135 /// ❰ expr? ❱; 1142 /// ❰ expr? ❱;
1136 /// ``` 1143 /// ```
1137 /// 1144 ///
1138 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator) 1145 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator)
1139 struct TryExpr: AttrsOwner { Expr, T![?] } 1146 struct TryExpr: AttrsOwner { Expr, T![?] }
1140 1147
1141 /// Type cast expression. 1148 /// Type cast expression.
1142 /// 1149 ///
1143 /// ``` 1150 /// ```
1144 /// ❰ expr as T ❱; 1151 /// ❰ expr as T ❱;
1145 /// ``` 1152 /// ```
1146 /// 1153 ///
1147 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions) 1154 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions)
1148 struct CastExpr: AttrsOwner { Expr, T![as], TypeRef } 1155 struct CastExpr: AttrsOwner { Expr, T![as], TypeRef }
1149 1156
1150 1157
1151 /// Borrow operator call. 1158 /// Borrow operator call.
1152 /// 1159 ///
1153 /// ``` 1160 /// ```
1154 /// ❰ &foo ❱; 1161 /// ❰ &foo ❱;
1155 /// ❰ &mut bar ❱; 1162 /// ❰ &mut bar ❱;
1156 /// ❰ &raw const bar ❱; 1163 /// ❰ &raw const bar ❱;
1157 /// ❰ &raw mut bar ❱; 1164 /// ❰ &raw mut bar ❱;
1158 /// ``` 1165 /// ```
1159 /// 1166 ///
1160 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators) 1167 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators)
1161 struct RefExpr: AttrsOwner { T![&], T![raw], T![mut], T![const], Expr } 1168 struct RefExpr: AttrsOwner { T![&], T![raw], T![mut], T![const], Expr }
1162 1169
1163 /// Prefix operator call. This is either `!` or `*` or `-`. 1170 /// Prefix operator call. This is either `!` or `*` or `-`.
1164 /// 1171 ///
1165 /// ``` 1172 /// ```
1166 /// ❰ !foo ❱; 1173 /// ❰ !foo ❱;
1167 /// ❰ *bar ❱; 1174 /// ❰ *bar ❱;
1168 /// ❰ -42 ❱; 1175 /// ❰ -42 ❱;
1169 /// ``` 1176 /// ```
1170 /// 1177 ///
1171 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html) 1178 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html)
1172 struct PrefixExpr: AttrsOwner { /*PrefixOp,*/ Expr } 1179 struct PrefixExpr: AttrsOwner { /*PrefixOp,*/ Expr }
1173 1180
1174 /// Box operator call. 1181 /// Box operator call.
1175 /// 1182 ///
1176 /// ``` 1183 /// ```
1177 /// ❰ box 42 ❱; 1184 /// ❰ box 42 ❱;
1178 /// ``` 1185 /// ```
1179 /// 1186 ///
1180 /// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md) 1187 /// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md)
1181 struct BoxExpr: AttrsOwner { T![box], Expr } 1188 struct BoxExpr: AttrsOwner { T![box], Expr }
1182 1189
1183 /// Range operator call. 1190 /// Range operator call.
1184 /// 1191 ///
1185 /// ``` 1192 /// ```
1186 /// ❰ 0..42 ❱; 1193 /// ❰ 0..42 ❱;
1187 /// ❰ ..42 ❱; 1194 /// ❰ ..42 ❱;
1188 /// ❰ 0.. ❱; 1195 /// ❰ 0.. ❱;
1189 /// ❰ .. ❱; 1196 /// ❰ .. ❱;
1190 /// ❰ 0..=42 ❱; 1197 /// ❰ 0..=42 ❱;
1191 /// ❰ ..=42 ❱; 1198 /// ❰ ..=42 ❱;
1192 /// ``` 1199 /// ```
1193 /// 1200 ///
1194 /// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html) 1201 /// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html)
1195 struct RangeExpr: AttrsOwner { /*RangeOp*/ } 1202 struct RangeExpr: AttrsOwner { /*RangeOp*/ }
1196 1203
1197 1204
1198 /// Binary operator call. 1205 /// Binary operator call.
1199 /// Includes all arithmetic, logic, bitwise and assignment operators. 1206 /// Includes all arithmetic, logic, bitwise and assignment operators.
1200 /// 1207 ///
1201 /// ``` 1208 /// ```
1202 /// ❰ 2 + ❰ 2 * 2 ❱ ❱; 1209 /// ❰ 2 + ❰ 2 * 2 ❱ ❱;
1203 /// ❰ ❰ true && false ❱ || true ❱; 1210 /// ❰ ❰ true && false ❱ || true ❱;
1204 /// ``` 1211 /// ```
1205 /// 1212 ///
1206 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators) 1213 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators)
1207 struct BinExpr: AttrsOwner { /*BinOp*/ } 1214 struct BinExpr: AttrsOwner { /*BinOp*/ }
1208 1215
1209 1216
1210 /// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal. 1217 /// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal.
1211 /// 1218 ///
1212 /// ``` 1219 /// ```
1213 /// ❰ "str" ❱; 1220 /// ❰ "str" ❱;
1214 /// ❰ br##"raw byte str"## ❱; 1221 /// ❰ br##"raw byte str"## ❱;
1215 /// ❰ 'c' ❱; 1222 /// ❰ 'c' ❱;
1216 /// ❰ b'c' ❱; 1223 /// ❰ b'c' ❱;
1217 /// ❰ 42 ❱; 1224 /// ❰ 42 ❱;
1218 /// ❰ 1e9 ❱; 1225 /// ❰ 1e9 ❱;
1219 /// ❰ true ❱; 1226 /// ❰ true ❱;
1220 /// ``` 1227 /// ```
1221 /// 1228 ///
1222 /// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html) 1229 /// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html)
1223 struct Literal { /*LiteralToken*/ } 1230 struct Literal { /*LiteralToken*/ }
1224 1231
1225 /// Match expression. 1232 /// Match expression.
1226 /// 1233 ///
1227 /// ``` 1234 /// ```
1228 /// ❰ 1235 /// ❰
1229 /// match expr { 1236 /// match expr {
1230 /// Pat1 => {} 1237 /// Pat1 => {}
1231 /// Pat2(_) => 42, 1238 /// Pat2(_) => 42,
1232 /// } 1239 /// }
1233 /// ❱ 1240 /// ❱
1234 /// ``` 1241 /// ```
1235 /// 1242 ///
1236 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) 1243 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1237 struct MatchExpr: AttrsOwner { T![match], Expr, MatchArmList } 1244 struct MatchExpr: AttrsOwner { T![match], Expr, MatchArmList }
1238 1245
1239 /// Match arm list part of match expression. Includes its inner attributes. 1246 /// Match arm list part of match expression. Includes its inner attributes.
1240 /// 1247 ///
1241 /// ``` 1248 /// ```
1242 /// match expr 1249 /// match expr
1243 /// ❰ 1250 /// ❰
1244 /// { 1251 /// {
1245 /// #![inner_attr] 1252 /// #![inner_attr]
1246 /// Pat1 => {} 1253 /// Pat1 => {}
1247 /// Pat2(_) => 42, 1254 /// Pat2(_) => 42,
1248 /// } 1255 /// }
1249 /// ❱ 1256 /// ❱
1250 /// ``` 1257 /// ```
1251 /// 1258 ///
1252 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) 1259 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1253 struct MatchArmList: AttrsOwner { T!['{'], arms: [MatchArm], T!['}'] } 1260 struct MatchArmList: AttrsOwner { T!['{'], arms: [MatchArm], T!['}'] }
1254 1261
1255 1262
1256 /// Match arm. 1263 /// Match arm.
1257 /// Note: record struct literals are not valid as target match expression 1264 /// Note: record struct literals are not valid as target match expression
1258 /// due to ambiguity. 1265 /// due to ambiguity.
1259 /// ``` 1266 /// ```
1260 /// match expr { 1267 /// match expr {
1261 /// ❰ #[attr] Pattern(it) if bool_cond => it ❱, 1268 /// ❰ #[attr] Pattern(it) if bool_cond => it ❱,
1262 /// } 1269 /// }
1263 /// ``` 1270 /// ```
1264 /// 1271 ///
1265 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) 1272 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1266 struct MatchArm: AttrsOwner { 1273 struct MatchArm: AttrsOwner {
1267 pat: Pat, 1274 pat: Pat,
1268 guard: MatchGuard, 1275 guard: MatchGuard,
1269 T![=>], 1276 T![=>],
1270 Expr, 1277 Expr,
1271 } 1278 }
1272 1279
1273 /// Match guard. 1280 /// Match guard.
1274 /// 1281 ///
1275 /// ``` 1282 /// ```
1276 /// match expr { 1283 /// match expr {
1277 /// Pattern(it) ❰ if bool_cond ❱ => it, 1284 /// Pattern(it) ❰ if bool_cond ❱ => it,
1278 /// } 1285 /// }
1279 /// ``` 1286 /// ```
1280 /// 1287 ///
1281 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards) 1288 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards)
1282 struct MatchGuard { T![if], Expr } 1289 struct MatchGuard { T![if], Expr }
1283 1290
1284 /// Record literal expression. The same syntax is used for structs, 1291 /// Record literal expression. The same syntax is used for structs,
1285 /// unions and record enum variants. 1292 /// unions and record enum variants.
1286 /// 1293 ///
1287 /// ``` 1294 /// ```
1288 /// ❰ 1295 /// ❰
1289 /// foo::Bar { 1296 /// foo::Bar {
1290 /// #![inner_attr] 1297 /// #![inner_attr]
1291 /// baz: 42, 1298 /// baz: 42,
1292 /// bruh: true, 1299 /// bruh: true,
1293 /// ..spread 1300 /// ..spread
1294 /// } 1301 /// }
1295 /// ❱ 1302 /// ❱
1296 /// ``` 1303 /// ```
1297 /// 1304 ///
1298 /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) 1305 /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1299 struct RecordLit { Path, RecordFieldList} 1306 struct RecordLit { Path, RecordFieldList}
1300 1307
1301 /// Record field list including enclosing curly braces. 1308 /// Record field list including enclosing curly braces.
1302 /// 1309 ///
1303 /// foo::Bar ❰ 1310 /// foo::Bar ❰
1304 /// { 1311 /// {
1305 /// baz: 42, 1312 /// baz: 42,
1306 /// ..spread 1313 /// ..spread
1307 /// } 1314 /// }
1308 /// ❱ 1315 /// ❱
1309 /// 1316 ///
1310 /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) 1317 /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1311 struct RecordFieldList { 1318 struct RecordFieldList {
1312 T!['{'], 1319 T!['{'],
1313 fields: [RecordField], 1320 fields: [RecordField],
1314 T![..], 1321 T![..],
1315 spread: Expr, 1322 spread: Expr,
1316 T!['}'] 1323 T!['}']
1317 } 1324 }
1318 1325
1319 /// Record field. 1326 /// Record field.
1320 /// 1327 ///
1321 /// ``` 1328 /// ```
1322 /// foo::Bar { 1329 /// foo::Bar {
1323 /// ❰ #[attr] baz: 42 ❱ 1330 /// ❰ #[attr] baz: 42 ❱
1324 /// } 1331 /// }
1325 /// ``` 1332 /// ```
1326 /// 1333 ///
1327 /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) 1334 /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1328 struct RecordField: AttrsOwner { NameRef, T![:], Expr } 1335 struct RecordField: AttrsOwner { NameRef, T![:], Expr }
1329 1336
1330 /// Disjunction of patterns. 1337 /// Disjunction of patterns.
1331 /// 1338 ///
1332 /// ``` 1339 /// ```
1333 /// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh; 1340 /// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh;
1334 /// ``` 1341 /// ```
1335 /// 1342 ///
1336 /// [Reference](https://doc.rust-lang.org/reference/patterns.html) 1343 /// [Reference](https://doc.rust-lang.org/reference/patterns.html)
1337 struct OrPat { pats: [Pat] } 1344 struct OrPat { pats: [Pat] }
1338 1345
1339 /// Parenthesized pattern. 1346 /// Parenthesized pattern.
1340 /// Note: parens are only used for grouping, this is not a tuple pattern. 1347 /// Note: parens are only used for grouping, this is not a tuple pattern.
1341 /// 1348 ///
1342 /// ``` 1349 /// ```
1343 /// if let ❰ &(0..=42) ❱ = foo {} 1350 /// if let ❰ &(0..=42) ❱ = foo {}
1344 /// ``` 1351 /// ```
1345 /// 1352 ///
1346 /// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns 1353 /// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns
1347 struct ParenPat { T!['('], Pat, T![')'] } 1354 struct ParenPat { T!['('], Pat, T![')'] }
1348 1355
1349 /// Reference pattern. 1356 /// Reference pattern.
1350 /// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns. 1357 /// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns.
1351 /// 1358 ///
1352 /// ``` 1359 /// ```
1353 /// let ❰ &mut foo ❱ = bar; 1360 /// let ❰ &mut foo ❱ = bar;
1354 /// 1361 ///
1355 /// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz; 1362 /// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz;
1356 /// ``` 1363 /// ```
1357 /// 1364 ///
1358 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns) 1365 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns)
1359 struct RefPat { T![&], T![mut], Pat } 1366 struct RefPat { T![&], T![mut], Pat }
1360 1367
1361 /// Box pattern. 1368 /// Box pattern.
1362 /// 1369 ///
1363 /// ``` 1370 /// ```
1364 /// let ❰ box foo ❱ = box 42; 1371 /// let ❰ box foo ❱ = box 42;
1365 /// ``` 1372 /// ```
1366 /// 1373 ///
1367 /// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html) 1374 /// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html)
1368 struct BoxPat { T![box], Pat } 1375 struct BoxPat { T![box], Pat }
1369 1376
1370 /// Bind pattern. 1377 /// Bind pattern.
1371 /// 1378 ///
1372 /// ``` 1379 /// ```
1373 /// match foo { 1380 /// match foo {
1374 /// Some(❰ ref mut bar ❱) => {} 1381 /// Some(❰ ref mut bar ❱) => {}
1375 /// ❰ baz @ None ❱ => {} 1382 /// ❰ baz @ None ❱ => {}
1376 /// } 1383 /// }
1377 /// ``` 1384 /// ```
1378 /// 1385 ///
1379 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns) 1386 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns)
1380 struct BindPat: AttrsOwner, NameOwner { T![ref], T![mut], T![@], Pat } 1387 struct BindPat: AttrsOwner, NameOwner { T![ref], T![mut], T![@], Pat }
1381 1388
1382 /// Placeholder pattern a.k.a. the wildcard pattern or the underscore. 1389 /// Placeholder pattern a.k.a. the wildcard pattern or the underscore.
1383 /// 1390 ///
1384 /// ``` 1391 /// ```
1385 /// let ❰ _ ❱ = foo; 1392 /// let ❰ _ ❱ = foo;
1386 /// ``` 1393 /// ```
1387 /// 1394 ///
1388 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern) 1395 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern)
1389 struct PlaceholderPat { T![_] } 1396 struct PlaceholderPat { T![_] }
1390 1397
1391 /// Rest-of-the record/tuple pattern. 1398 /// Rest-of-the record/tuple pattern.
1392 /// Note: this is not the unbonded range pattern (even more: it doesn't exist). 1399 /// Note: this is not the unbonded range pattern (even more: it doesn't exist).
1393 /// 1400 ///
1394 /// ``` 1401 /// ```
1395 /// let Foo { bar, ❰ .. ❱ } = baz; 1402 /// let Foo { bar, ❰ .. ❱ } = baz;
1396 /// let (❰ .. ❱, bruh) = (42, 24, 42); 1403 /// let (❰ .. ❱, bruh) = (42, 24, 42);
1397 /// let Bruuh(❰ .. ❱) = bruuuh; 1404 /// let Bruuh(❰ .. ❱) = bruuuh;
1398 /// ``` 1405 /// ```
1399 /// 1406 ///
1400 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) 1407 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1401 struct DotDotPat { T![..] } 1408 struct DotDotPat { T![..] }
1402 1409
1403 /// Path pattern. 1410 /// Path pattern.
1404 /// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`). 1411 /// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`).
1405 /// 1412 ///
1406 /// ``` 1413 /// ```
1407 /// let ❰ foo::bar::Baz ❱ { .. } = bruh; 1414 /// let ❰ foo::bar::Baz ❱ { .. } = bruh;
1408 /// if let ❰ CONST ❱ = 42 {} 1415 /// if let ❰ CONST ❱ = 42 {}
1409 /// ``` 1416 /// ```
1410 /// 1417 ///
1411 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns) 1418 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns)
1412 struct PathPat { Path } 1419 struct PathPat { Path }
1413 1420
1414 /// Slice pattern. 1421 /// Slice pattern.
1415 /// 1422 ///
1416 /// ``` 1423 /// ```
1417 /// let ❰ [foo, bar, baz] ❱ = [1, 2, 3]; 1424 /// let ❰ [foo, bar, baz] ❱ = [1, 2, 3];
1418 /// ``` 1425 /// ```
1419 /// 1426 ///
1420 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns) 1427 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns)
1421 struct SlicePat { T!['['], args: [Pat], T![']'] } 1428 struct SlicePat { T!['['], args: [Pat], T![']'] }
1422 1429
1423 /// Range pattern. 1430 /// Range pattern.
1424 /// 1431 ///
1425 /// ``` 1432 /// ```
1426 /// match foo { 1433 /// match foo {
1427 /// ❰ 0..42 ❱ => {} 1434 /// ❰ 0..42 ❱ => {}
1428 /// ❰ 0..=42 ❱ => {} 1435 /// ❰ 0..=42 ❱ => {}
1429 /// } 1436 /// }
1430 /// ``` 1437 /// ```
1431 /// 1438 ///
1432 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns) 1439 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns)
1433 struct RangePat { } // FIXME(@matklad): here should be T![..], T![..=] I think, if we don't already have an accessor in expresions_ext 1440 struct RangePat { } // FIXME(@matklad): here should be T![..], T![..=] I think, if we don't already have an accessor in expresions_ext
1434 1441
1435 /// Literal pattern. 1442 /// Literal pattern.
1436 /// Includes only bool, number, char, and string literals. 1443 /// Includes only bool, number, char, and string literals.
1437 /// 1444 ///
1438 /// ``` 1445 /// ```
1439 /// match foo { 1446 /// match foo {
1440 /// Number(❰ 42 ❱) => {} 1447 /// Number(❰ 42 ❱) => {}
1441 /// String(❰ "42" ❱) => {} 1448 /// String(❰ "42" ❱) => {}
1442 /// Bool(❰ true ❱) => {} 1449 /// Bool(❰ true ❱) => {}
1443 /// } 1450 /// }
1444 /// ``` 1451 /// ```
1445 /// 1452 ///
1446 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns) 1453 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns)
1447 struct LiteralPat { Literal } 1454 struct LiteralPat { Literal }
1448 1455
1449 /// Macro invocation in pattern position. 1456 /// Macro invocation in pattern position.
1450 /// 1457 ///
1451 /// ``` 1458 /// ```
1452 /// let ❰ foo!(my custom syntax) ❱ = baz; 1459 /// let ❰ foo!(my custom syntax) ❱ = baz;
1453 /// 1460 ///
1454 /// ``` 1461 /// ```
1455 /// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation) 1462 /// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation)
1456 struct MacroPat { MacroCall } 1463 struct MacroPat { MacroCall }
1457 1464
1458 /// Record literal pattern. 1465 /// Record literal pattern.
1459 /// 1466 ///
1460 /// ``` 1467 /// ```
1461 /// let ❰ foo::Bar { baz, .. } ❱ = bruh; 1468 /// let ❰ foo::Bar { baz, .. } ❱ = bruh;
1462 /// ``` 1469 /// ```
1463 /// 1470 ///
1464 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) 1471 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1465 struct RecordPat { RecordFieldPatList, Path } 1472 struct RecordPat { RecordFieldPatList, Path }
1466 1473
1467 /// Record literal's field patterns list including enclosing curly braces. 1474 /// Record literal's field patterns list including enclosing curly braces.
1468 /// 1475 ///
1469 /// ``` 1476 /// ```
1470 /// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh; 1477 /// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh;
1471 /// `` 1478 /// ``
1472 /// 1479 ///
1473 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) 1480 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1474 struct RecordFieldPatList { 1481 struct RecordFieldPatList {
1475 T!['{'], 1482 T!['{'],
1476 pats: [RecordInnerPat], 1483 pats: [RecordInnerPat],
1477 record_field_pats: [RecordFieldPat], 1484 record_field_pats: [RecordFieldPat],
1478 bind_pats: [BindPat], 1485 bind_pats: [BindPat],
1479 T![..], 1486 T![..],
1480 T!['}'] 1487 T!['}']
1481 } 1488 }
1482 1489
1483 /// Record literal's field pattern. 1490 /// Record literal's field pattern.
1484 /// Note: record literal can also match tuple structs. 1491 /// Note: record literal can also match tuple structs.
1485 /// 1492 ///
1486 /// ``` 1493 /// ```
1487 /// let Foo { ❰ bar: _ ❱ } = baz; 1494 /// let Foo { ❰ bar: _ ❱ } = baz;
1488 /// let TupleStruct { ❰ 0: _ ❱ } = bruh; 1495 /// let TupleStruct { ❰ 0: _ ❱ } = bruh;
1489 /// ``` 1496 /// ```
1490 /// 1497 ///
1491 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) 1498 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1492 struct RecordFieldPat: AttrsOwner { NameRef, T![:], Pat } 1499 struct RecordFieldPat: AttrsOwner { NameRef, T![:], Pat }
1493 1500
1494 /// Tuple struct literal pattern. 1501 /// Tuple struct literal pattern.
1495 /// 1502 ///
1496 /// ``` 1503 /// ```
1497 /// let ❰ foo::Bar(baz, bruh) ❱ = bruuh; 1504 /// let ❰ foo::Bar(baz, bruh) ❱ = bruuh;
1498 /// ``` 1505 /// ```
1499 /// 1506 ///
1500 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns) 1507 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns)
1501 struct TupleStructPat { Path, T!['('], args: [Pat], T![')'] } 1508 struct TupleStructPat { Path, T!['('], args: [Pat], T![')'] }
1502 1509
1503 /// Tuple pattern. 1510 /// Tuple pattern.
1504 /// Note: this doesn't include tuple structs (see `TupleStructPat`) 1511 /// Note: this doesn't include tuple structs (see `TupleStructPat`)
1505 /// 1512 ///
1506 /// ``` 1513 /// ```
1507 /// let ❰ (foo, bar, .., baz) ❱ = bruh; 1514 /// let ❰ (foo, bar, .., baz) ❱ = bruh;
1508 /// ``` 1515 /// ```
1509 /// 1516 ///
1510 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns) 1517 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns)
1511 struct TuplePat { T!['('], args: [Pat], T![')'] } 1518 struct TuplePat { T!['('], args: [Pat], T![')'] }
1512 1519
1513 /// Visibility. 1520 /// Visibility.
1514 /// 1521 ///
1515 /// ``` 1522 /// ```
1516 /// ❰ pub mod ❱ foo; 1523 /// ❰ pub mod ❱ foo;
1517 /// ❰ pub(crate) ❱ struct Bar; 1524 /// ❰ pub(crate) ❱ struct Bar;
1518 /// ❰ pub(self) ❱ enum Baz {} 1525 /// ❰ pub(self) ❱ enum Baz {}
1519 /// ❰ pub(super) ❱ fn bruh() {} 1526 /// ❰ pub(super) ❱ fn bruh() {}
1520 /// ❰ pub(in bruuh::bruuuh) ❱ type T = u64; 1527 /// ❰ pub(in bruuh::bruuuh) ❱ type T = u64;
1521 /// ``` 1528 /// ```
1522 /// 1529 ///
1523 /// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html) 1530 /// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html)
1524 struct Visibility { T![pub], T![super], T![self], T![crate] } 1531 struct Visibility { T![pub], T![super], T![self], T![crate] }
1525 1532
1526 /// Single identifier. 1533 /// Single identifier.
1527 /// Note(@matklad): `Name` is for things that install a new name into the scope, 1534 /// Note(@matklad): `Name` is for things that install a new name into the scope,
1528 /// `NameRef` is a usage of a name. Most of the time, this definition/reference 1535 /// `NameRef` is a usage of a name. Most of the time, this definition/reference
1529 /// distinction can be determined purely syntactically, ie in 1536 /// distinction can be determined purely syntactically, ie in
1530 /// ``` 1537 /// ```
1531 /// fn foo() { foo() } 1538 /// fn foo() { foo() }
1532 /// ``` 1539 /// ```
1533 /// the first foo is `Name`, the second one is `NameRef`. 1540 /// the first foo is `Name`, the second one is `NameRef`.
1534 /// The notable exception are patterns, where in 1541 /// The notable exception are patterns, where in
1535 /// `` 1542 /// ``
1536 /// let x = 92 1543 /// let x = 92
1537 /// ``` 1544 /// ```
1538 /// `x` can be semantically either a name or a name ref, depeding on 1545 /// `x` can be semantically either a name or a name ref, depeding on
1539 /// wether there's an `x` constant in scope. 1546 /// wether there's an `x` constant in scope.
1540 /// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db). 1547 /// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db).
1541 /// 1548 ///
1542 /// ``` 1549 /// ```
1543 /// let ❰ foo ❱ = bar; 1550 /// let ❰ foo ❱ = bar;
1544 /// struct ❰ Baz ❱; 1551 /// struct ❰ Baz ❱;
1545 /// fn ❰ bruh ❱() {} 1552 /// fn ❰ bruh ❱() {}
1546 /// ``` 1553 /// ```
1547 /// 1554 ///
1548 /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) 1555 /// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
1549 struct Name { T![ident] } 1556 struct Name { T![ident] }
1550 1557
1551 /// Reference to a name. 1558 /// Reference to a name.
1552 /// See the explanation on the difference between `Name` and `NameRef` 1559 /// See the explanation on the difference between `Name` and `NameRef`
1553 /// in `Name` ast node docs. 1560 /// in `Name` ast node docs.
1554 /// 1561 ///
1555 /// ``` 1562 /// ```
1556 /// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱; 1563 /// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱;
1557 /// ``` 1564 /// ```
1558 /// 1565 ///
1559 /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) 1566 /// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
1560 struct NameRef { } 1567 struct NameRef { }
1561 1568
1562 /// Macro call. 1569 /// Macro call.
1563 /// Includes all of its attributes and doc comments. 1570 /// Includes all of its attributes and doc comments.
1564 /// 1571 ///
1565 /// ``` 1572 /// ```
1566 /// ❰ 1573 /// ❰
1567 /// /// Docs 1574 /// /// Docs
1568 /// #[attr] 1575 /// #[attr]
1569 /// macro_rules! foo { // macro rules is also a macro call 1576 /// macro_rules! foo { // macro rules is also a macro call
1570 /// ($bar: tt) => {} 1577 /// ($bar: tt) => {}
1571 /// } 1578 /// }
1572 /// ❱ 1579 /// ❱
1573 /// 1580 ///
1574 /// // semicolon is a part of `MacroCall` when it is used in item positions 1581 /// // semicolon is a part of `MacroCall` when it is used in item positions
1575 /// ❰ foo!(); ❱ 1582 /// ❰ foo!(); ❱
1576 /// 1583 ///
1577 /// fn main() { 1584 /// fn main() {
1578 /// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi 1585 /// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi
1579 /// } 1586 /// }
1580 /// ``` 1587 /// ```
1581 /// 1588 ///
1582 /// [Reference](https://doc.rust-lang.org/reference/macros.html) 1589 /// [Reference](https://doc.rust-lang.org/reference/macros.html)
1583 struct MacroCall: NameOwner, AttrsOwner, DocCommentsOwner { 1590 struct MacroCall: NameOwner, AttrsOwner, DocCommentsOwner {
1584 Path, T![!], TokenTree, T![;] 1591 Path, T![!], TokenTree, T![;]
1585 } 1592 }
1586 1593
1587 /// Attribute. 1594 /// Attribute.
1588 /// 1595 ///
1589 /// ``` 1596 /// ```
1590 /// ❰ #![inner_attr] ❱ 1597 /// ❰ #![inner_attr] ❱
1591 /// 1598 ///
1592 /// ❰ #[attr] ❱ 1599 /// ❰ #[attr] ❱
1593 /// ❰ #[foo = "bar"] ❱ 1600 /// ❰ #[foo = "bar"] ❱
1594 /// ❰ #[baz(bruh::bruuh = "42")] ❱ 1601 /// ❰ #[baz(bruh::bruuh = "42")] ❱
1595 /// struct Foo; 1602 /// struct Foo;
1596 /// ``` 1603 /// ```
1597 /// 1604 ///
1598 /// [Reference](https://doc.rust-lang.org/reference/attributes.html) 1605 /// [Reference](https://doc.rust-lang.org/reference/attributes.html)
1599 struct Attr { T![#], T![!], T!['['], Path, T![=], input: AttrInput, T![']'] } 1606 struct Attr { T![#], T![!], T!['['], Path, T![=], input: AttrInput, T![']'] }
1600 1607
1601 /// Stores a list of lexer tokens and other `TokenTree`s. 1608 /// Stores a list of lexer tokens and other `TokenTree`s.
1602 /// It appears in attributes, macro_rules and macro call (foo!) 1609 /// It appears in attributes, macro_rules and macro call (foo!)
1603 /// 1610 ///
1604 /// ``` 1611 /// ```
1605 /// macro_call! ❰ { my syntax here } ❱; 1612 /// macro_call! ❰ { my syntax here } ❱;
1606 /// ``` 1613 /// ```
1607 /// 1614 ///
1608 /// [Reference](https://doc.rust-lang.org/reference/macros.html) 1615 /// [Reference](https://doc.rust-lang.org/reference/macros.html)
1609 struct TokenTree {} 1616 struct TokenTree {}
1610 1617
1611 /// Generic lifetime, type and constants parameters list **declaration**. 1618 /// Generic lifetime, type and constants parameters list **declaration**.
1612 /// 1619 ///
1613 /// ``` 1620 /// ```
1614 /// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {} 1621 /// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {}
1615 /// 1622 ///
1616 /// struct Baz❰ <T> ❱(T); 1623 /// struct Baz❰ <T> ❱(T);
1617 /// 1624 ///
1618 /// impl❰ <T> ❱ Bruh<T> {} 1625 /// impl❰ <T> ❱ Bruh<T> {}
1619 /// 1626 ///
1620 /// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str; 1627 /// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str;
1621 /// ``` 1628 /// ```
1622 /// 1629 ///
1623 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) 1630 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1624 struct TypeParamList { 1631 struct TypeParamList {
1625 T![<], 1632 T![<],
1626 generic_params: [GenericParam], 1633 generic_params: [GenericParam],
1627 type_params: [TypeParam], 1634 type_params: [TypeParam],
1628 lifetime_params: [LifetimeParam], 1635 lifetime_params: [LifetimeParam],
1629 const_params: [ConstParam], 1636 const_params: [ConstParam],
1630 T![>] 1637 T![>]
1631 } 1638 }
1632 1639
1633 /// Single type parameter **declaration**. 1640 /// Single type parameter **declaration**.
1634 /// 1641 ///
1635 /// ``` 1642 /// ```
1636 /// fn foo<❰ K ❱, ❰ I ❱, ❰ E: Debug ❱, ❰ V = DefaultType ❱>() {} 1643 /// fn foo<❰ K ❱, ❰ I ❱, ❰ E: Debug ❱, ❰ V = DefaultType ❱>() {}
1637 /// ``` 1644 /// ```
1638 /// 1645 ///
1639 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) 1646 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1640 struct TypeParam: NameOwner, AttrsOwner, TypeBoundsOwner { 1647 struct TypeParam: NameOwner, AttrsOwner, TypeBoundsOwner {
1641 T![=], 1648 T![=],
1642 default_type: TypeRef, 1649 default_type: TypeRef,
1643 } 1650 }
1644 1651
1645 /// Const generic parameter **declaration**. 1652 /// Const generic parameter **declaration**.
1646 /// ``` 1653 /// ```
1647 /// fn foo<T, U, ❰ const BAR: usize ❱, ❰ const BAZ: bool ❱>() {} 1654 /// fn foo<T, U, ❰ const BAR: usize ❱, ❰ const BAZ: bool ❱>() {}
1648 /// ``` 1655 /// ```
1649 /// 1656 ///
1650 /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) 1657 /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter)
1651 struct ConstParam: NameOwner, AttrsOwner, TypeAscriptionOwner { 1658 struct ConstParam: NameOwner, AttrsOwner, TypeAscriptionOwner {
1652 T![=], 1659 T![=],
1653 default_val: Expr, 1660 default_val: Expr,
1654 } 1661 }
1655 1662
1656 /// Lifetime parameter **declaration**. 1663 /// Lifetime parameter **declaration**.
1657 /// 1664 ///
1658 /// ``` 1665 /// ```
1659 /// fn foo<❰ 'a ❱, ❰ 'b ❱, V, G, D>(bar: &'a str, baz: &'b mut str) {} 1666 /// fn foo<❰ 'a ❱, ❰ 'b ❱, V, G, D>(bar: &'a str, baz: &'b mut str) {}
1660 /// ``` 1667 /// ```
1661 /// 1668 ///
1662 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) 1669 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1663 struct LifetimeParam: AttrsOwner { T![lifetime] } 1670 struct LifetimeParam: AttrsOwner { T![lifetime] }
1664 1671
1665 /// Type bound declaration clause. 1672 /// Type bound declaration clause.
1666 /// 1673 ///
1667 /// ``` 1674 /// ```
1668 /// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {} 1675 /// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {}
1669 /// 1676 ///
1670 /// trait Bar<T> 1677 /// trait Bar<T>
1671 /// where 1678 /// where
1672 /// T: ❰ Send ❱ + ❰ Sync ❱ 1679 /// T: ❰ Send ❱ + ❰ Sync ❱
1673 /// { 1680 /// {
1674 /// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱; 1681 /// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱;
1675 /// } 1682 /// }
1676 /// ``` 1683 /// ```
1677 /// 1684 ///
1678 /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) 1685 /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html)
1679 struct TypeBound { T![lifetime], /* Question, */ T![const], /* Question, */ TypeRef } 1686 struct TypeBound { T![lifetime], /* Question, */ T![const], /* Question, */ TypeRef }
1680 1687
1681 /// Type bounds list. 1688 /// Type bounds list.
1682 /// 1689 ///
1683 /// ``` 1690 /// ```
1684 /// 1691 ///
1685 /// fn foo<T: ❰ ?Sized + Debug ❱>() {} 1692 /// fn foo<T: ❰ ?Sized + Debug ❱>() {}
1686 /// 1693 ///
1687 /// trait Bar<T> 1694 /// trait Bar<T>
1688 /// where 1695 /// where
1689 /// T: ❰ Send + Sync ❱ 1696 /// T: ❰ Send + Sync ❱
1690 /// { 1697 /// {
1691 /// type Baz: ❰ !Sync + Debug ❱; 1698 /// type Baz: ❰ !Sync + Debug ❱;
1692 /// } 1699 /// }
1693 /// ``` 1700 /// ```
1694 /// 1701 ///
1695 /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) 1702 /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html)
1696 struct TypeBoundList { bounds: [TypeBound] } 1703 struct TypeBoundList { bounds: [TypeBound] }
1697 1704
1698 /// Single where predicate. 1705 /// Single where predicate.
1699 /// 1706 ///
1700 /// ``` 1707 /// ```
1701 /// trait Foo<'a, 'b, T> 1708 /// trait Foo<'a, 'b, T>
1702 /// where 1709 /// where
1703 /// ❰ 'a: 'b ❱, 1710 /// ❰ 'a: 'b ❱,
1704 /// ❰ T: IntoIterator ❱, 1711 /// ❰ T: IntoIterator ❱,
1705 /// ❰ for<'c> <T as IntoIterator>::Item: Bar<'c> ❱ 1712 /// ❰ for<'c> <T as IntoIterator>::Item: Bar<'c> ❱
1706 /// {} 1713 /// {}
1707 /// ``` 1714 /// ```
1708 /// 1715 ///
1709 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) 1716 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses)
1710 struct WherePred: TypeBoundsOwner { T![for], TypeParamList, T![lifetime], TypeRef } 1717 struct WherePred: TypeBoundsOwner { T![for], TypeParamList, T![lifetime], TypeRef }
1711 1718
1712 /// Where clause. 1719 /// Where clause.
1713 /// 1720 ///
1714 /// ``` 1721 /// ```
1715 /// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {} 1722 /// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {}
1716 /// 1723 ///
1717 /// ``` 1724 /// ```
1718 /// 1725 ///
1719 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) 1726 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses)
1720 struct WhereClause { T![where], predicates: [WherePred] } 1727 struct WhereClause { T![where], predicates: [WherePred] }
1721 1728
1722 /// Abi declaration. 1729 /// Abi declaration.
1723 /// Note: the abi string is optional. 1730 /// Note: the abi string is optional.
1724 /// 1731 ///
1725 /// ``` 1732 /// ```
1726 /// ❰ extern "C" ❱ { 1733 /// ❰ extern "C" ❱ {
1727 /// fn foo() {} 1734 /// fn foo() {}
1728 /// } 1735 /// }
1729 /// 1736 ///
1730 /// type Bar = ❰ extern ❱ fn() -> u32; 1737 /// type Bar = ❰ extern ❱ fn() -> u32;
1731 /// 1738 ///
1732 /// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool; 1739 /// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool;
1733 /// ``` 1740 /// ```
1734 /// 1741 ///
1735 /// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html) 1742 /// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
1736 /// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions) 1743 /// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions)
1737 struct Abi { /*String*/ } 1744 struct Abi { /*String*/ }
1738 1745
1739 /// Expression statement. 1746 /// Expression statement.
1740 /// 1747 ///
1741 /// ``` 1748 /// ```
1742 /// ❰ 42; ❱ 1749 /// ❰ 42; ❱
1743 /// ❰ foo(); ❱ 1750 /// ❰ foo(); ❱
1744 /// ❰ (); ❱ 1751 /// ❰ (); ❱
1745 /// ❰ {}; ❱ 1752 /// ❰ {}; ❱
1746 /// 1753 ///
1747 /// // constructions with trailing curly brace can omit the semicolon 1754 /// // constructions with trailing curly brace can omit the semicolon
1748 /// // but only when there are satements immediately after them (this is important!) 1755 /// // but only when there are satements immediately after them (this is important!)
1749 /// ❰ if bool_cond { } ❱ 1756 /// ❰ if bool_cond { } ❱
1750 /// ❰ loop {} ❱ 1757 /// ❰ loop {} ❱
1751 /// ❰ somestatment; ❱ 1758 /// ❰ somestatment; ❱
1752 /// ``` 1759 /// ```
1753 /// 1760 ///
1754 /// [Reference](https://doc.rust-lang.org/reference/statements.html) 1761 /// [Reference](https://doc.rust-lang.org/reference/statements.html)
1755 struct ExprStmt: AttrsOwner { Expr, T![;] } 1762 struct ExprStmt: AttrsOwner { Expr, T![;] }
1756 1763
1757 /// Let statement. 1764 /// Let statement.
1758 /// 1765 ///
1759 /// ``` 1766 /// ```
1760 /// ❰ #[attr] let foo; ❱ 1767 /// ❰ #[attr] let foo; ❱
1761 /// ❰ let bar: u64; ❱ 1768 /// ❰ let bar: u64; ❱
1762 /// ❰ let baz = 42; ❱ 1769 /// ❰ let baz = 42; ❱
1763 /// ❰ let bruh: bool = true; ❱ 1770 /// ❰ let bruh: bool = true; ❱
1764 /// ``` 1771 /// ```
1765 /// 1772 ///
1766 /// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements) 1773 /// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements)
1767 struct LetStmt: AttrsOwner, TypeAscriptionOwner { 1774 struct LetStmt: AttrsOwner, TypeAscriptionOwner {
1768 T![let], 1775 T![let],
1769 Pat, 1776 Pat,
1770 T![=], 1777 T![=],
1771 initializer: Expr, 1778 initializer: Expr,
1772 T![;], 1779 T![;],
1773 } 1780 }
1774 1781
1775 /// Condition of `if` or `while` expression. 1782 /// Condition of `if` or `while` expression.
1776 /// 1783 ///
1777 /// ``` 1784 /// ```
1778 /// if ❰ true ❱ {} 1785 /// if ❰ true ❱ {}
1779 /// if ❰ let Pat(foo) = bar ❱ {} 1786 /// if ❰ let Pat(foo) = bar ❱ {}
1780 /// 1787 ///
1781 /// while ❰ true ❱ {} 1788 /// while ❰ true ❱ {}
1782 /// while ❰ let Pat(baz) = bruh ❱ {} 1789 /// while ❰ let Pat(baz) = bruh ❱ {}
1783 /// ``` 1790 /// ```
1784 /// 1791 ///
1785 /// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) 1792 /// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
1786 /// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) 1793 /// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
1787 struct Condition { T![let], Pat, T![=], Expr } 1794 struct Condition { T![let], Pat, T![=], Expr }
1788 1795
1789 /// Parameter list **declaration**. 1796 /// Parameter list **declaration**.
1790 /// 1797 ///
1791 /// ``` 1798 /// ```
1792 /// fn foo❰ (a: u32, b: bool) ❱ -> u32 {} 1799 /// fn foo❰ (a: u32, b: bool) ❱ -> u32 {}
1793 /// let bar = ❰ |a, b| ❱ {}; 1800 /// let bar = ❰ |a, b| ❱ {};
1794 /// 1801 ///
1795 /// impl Baz { 1802 /// impl Baz {
1796 /// fn bruh❰ (&self, a: u32) ❱ {} 1803 /// fn bruh❰ (&self, a: u32) ❱ {}
1797 /// } 1804 /// }
1798 /// ``` 1805 /// ```
1799 /// 1806 ///
1800 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script 1807 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script
1801 struct ParamList { // FIXME: this node is used by closure expressions too, but hey use pipes instead of parens... 1808 struct ParamList { // FIXME: this node is used by closure expressions too, but hey use pipes instead of parens...
1802 T!['('], 1809 T!['('],
1803 SelfParam, 1810 SelfParam,
1804 params: [Param], 1811 params: [Param],
1805 T![')'] 1812 T![')']
1806 } 1813 }
1807 1814
1808 /// Self parameter **declaration**. 1815 /// Self parameter **declaration**.
1809 /// 1816 ///
1810 /// ``` 1817 /// ```
1811 /// impl Bruh { 1818 /// impl Bruh {
1812 /// fn foo(❰ self ❱) {} 1819 /// fn foo(❰ self ❱) {}
1813 /// fn bar(❰ &self ❱) {} 1820 /// fn bar(❰ &self ❱) {}
1814 /// fn baz(❰ &mut self ❱) {} 1821 /// fn baz(❰ &mut self ❱) {}
1815 /// fn blah<'a>(❰ &'a self ❱) {} 1822 /// fn blah<'a>(❰ &'a self ❱) {}
1816 /// fn blin(❰ self: Box<Self> ❱) {} 1823 /// fn blin(❰ self: Box<Self> ❱) {}
1817 /// } 1824 /// }
1818 /// ``` 1825 /// ```
1819 /// 1826 ///
1820 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) 1827 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
1821 struct SelfParam: TypeAscriptionOwner, AttrsOwner { T![&], T![mut], T![lifetime], T![self] } 1828 struct SelfParam: TypeAscriptionOwner, AttrsOwner { T![&], T![mut], T![lifetime], T![self] }
1822 1829
1823 /// Parameter **declaration**. 1830 /// Parameter **declaration**.
1824 /// 1831 ///
1825 /// ``` 1832 /// ```
1826 /// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {} 1833 /// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {}
1827 /// 1834 ///
1828 /// extern "C" { 1835 /// extern "C" {
1829 /// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32; 1836 /// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32;
1830 /// } 1837 /// }
1831 /// ``` 1838 /// ```
1832 /// 1839 ///
1833 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) 1840 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
1834 struct Param: TypeAscriptionOwner, AttrsOwner { 1841 struct Param: TypeAscriptionOwner, AttrsOwner {
1835 Pat, 1842 Pat,
1836 T![...] 1843 T![...]
1837 } 1844 }
1838 1845
1839 /// Use declaration. 1846 /// Use declaration.
1840 /// 1847 ///
1841 /// ``` 1848 /// ```
1842 /// ❰ #[attr] pub use foo; ❱ 1849 /// ❰ #[attr] pub use foo; ❱
1843 /// ❰ use bar as baz; ❱ 1850 /// ❰ use bar as baz; ❱
1844 /// ❰ use bruh::{self, bruuh}; ❱ 1851 /// ❰ use bruh::{self, bruuh}; ❱
1845 /// ❰ use { blin::blen, blah::* }; 1852 /// ❰ use { blin::blen, blah::* };
1846 /// ``` 1853 /// ```
1847 /// 1854 ///
1848 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) 1855 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1849 struct UseItem: AttrsOwner, VisibilityOwner { 1856 struct UseItem: AttrsOwner, VisibilityOwner {
1850 T![use], 1857 T![use],
1851 UseTree, 1858 UseTree,
1852 } 1859 }
1853 1860
1854 /// Use tree. 1861 /// Use tree.
1855 /// 1862 ///
1856 /// ``` 1863 /// ```
1857 /// pub use ❰ foo::❰ * ❱ ❱; 1864 /// pub use ❰ foo::❰ * ❱ ❱;
1858 /// use ❰ bar as baz ❱; 1865 /// use ❰ bar as baz ❱;
1859 /// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱; 1866 /// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱;
1860 /// use ❰ { ❰ blin::blen ❱ } ❱ 1867 /// use ❰ { ❰ blin::blen ❱ } ❱
1861 /// ``` 1868 /// ```
1862 /// 1869 ///
1863 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) 1870 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1864 struct UseTree { 1871 struct UseTree {
1865 Path, T![*], UseTreeList, Alias 1872 Path, T![*], UseTreeList, Alias
1866 } 1873 }
1867 1874
1868 /// Item alias. 1875 /// Item alias.
1869 /// Note: this is not the type alias. 1876 /// Note: this is not the type alias.
1870 /// 1877 ///
1871 /// ``` 1878 /// ```
1872 /// use foo ❰ as bar ❱; 1879 /// use foo ❰ as bar ❱;
1873 /// use baz::{bruh ❰ as _ ❱}; 1880 /// use baz::{bruh ❰ as _ ❱};
1874 /// extern crate bruuh ❰ as blin ❱; 1881 /// extern crate bruuh ❰ as blin ❱;
1875 /// ``` 1882 /// ```
1876 /// 1883 ///
1877 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) 1884 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1878 struct Alias: NameOwner { T![as] } 1885 struct Alias: NameOwner { T![as] }
1879 1886
1880 /// Sublist of use trees. 1887 /// Sublist of use trees.
1881 /// 1888 ///
1882 /// ``` 1889 /// ```
1883 /// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱; 1890 /// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱;
1884 /// use ❰ { blin::blen::❰ {} ❱ } ❱ 1891 /// use ❰ { blin::blen::❰ {} ❱ } ❱
1885 /// ``` 1892 /// ```
1886 /// 1893 ///
1887 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) 1894 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1888 struct UseTreeList { T!['{'], use_trees: [UseTree], T!['}'] } 1895 struct UseTreeList { T!['{'], use_trees: [UseTree], T!['}'] }
1889 1896
1890 /// Extern crate item. 1897 /// Extern crate item.
1891 /// 1898 ///
1892 /// ``` 1899 /// ```
1893 /// ❰ #[attr] pub extern crate foo; ❱ 1900 /// ❰ #[attr] pub extern crate foo; ❱
1894 /// ❰ extern crate self as bar; ❱ 1901 /// ❰ extern crate self as bar; ❱
1895 /// ``` 1902 /// ```
1896 /// 1903 ///
1897 /// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html) 1904 /// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html)
1898 struct ExternCrateItem: AttrsOwner, VisibilityOwner { 1905 struct ExternCrateItem: AttrsOwner, VisibilityOwner {
1899 T![extern], T![crate], NameRef, Alias, 1906 T![extern], T![crate], NameRef, Alias,
1900 } 1907 }
1901 1908
1902 /// Call site arguments list. 1909 /// Call site arguments list.
1903 /// 1910 ///
1904 /// ``` 1911 /// ```
1905 /// foo::<T, U>❰ (42, true) ❱; 1912 /// foo::<T, U>❰ (42, true) ❱;
1906 /// ``` 1913 /// ```
1907 /// 1914 ///
1908 /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) 1915 /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
1909 struct ArgList { 1916 struct ArgList {
1910 T!['('], 1917 T!['('],
1911 args: [Expr], 1918 args: [Expr],
1912 T![')'] 1919 T![')']
1913 } 1920 }
1914 1921
1915 /// Path to a symbol. Includes single identifier names and elaborate paths with 1922 /// Path to a symbol. Includes single identifier names and elaborate paths with
1916 /// generic parameters. 1923 /// generic parameters.
1917 /// 1924 ///
1918 /// ``` 1925 /// ```
1919 /// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱(); 1926 /// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱();
1920 /// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024); 1927 /// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024);
1921 /// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱(); 1928 /// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱();
1922 /// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱(); 1929 /// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱();
1923 /// ``` 1930 /// ```
1924 /// 1931 ///
1925 /// [Reference](https://doc.rust-lang.org/reference/paths.html) 1932 /// [Reference](https://doc.rust-lang.org/reference/paths.html)
1926 struct Path { 1933 struct Path {
1927 segment: PathSegment, 1934 segment: PathSegment,
1928 T![::], 1935 T![::],
1929 qualifier: Path, 1936 qualifier: Path,
1930 } 1937 }
1931 1938
1932 /// Segment of the path to a symbol. 1939 /// Segment of the path to a symbol.
1933 /// Only path segment of an absolute path holds the `::` token, 1940 /// Only path segment of an absolute path holds the `::` token,
1934 /// all other `::` tokens that connect path segments reside under `Path` itself.` 1941 /// all other `::` tokens that connect path segments reside under `Path` itself.`
1935 /// 1942 ///
1936 /// ``` 1943 /// ```
1937 /// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱(); 1944 /// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱();
1938 /// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024); 1945 /// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024);
1939 /// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱(); 1946 /// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱();
1940 /// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱(); 1947 /// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱();
1941 /// 1948 ///
1942 /// // Note that only in this case `::` token is inlcuded: 1949 /// // Note that only in this case `::` token is inlcuded:
1943 /// ❰ ::foo ❱; 1950 /// ❰ ::foo ❱;
1944 /// ``` 1951 /// ```
1945 /// 1952 ///
1946 /// [Reference](https://doc.rust-lang.org/reference/paths.html) 1953 /// [Reference](https://doc.rust-lang.org/reference/paths.html)
1947 struct PathSegment { 1954 struct PathSegment {
1948 T![::], T![crate], T![self], T![super], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>] 1955 T![::], T![crate], T![self], T![super], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>]
1949 } 1956 }
1950 1957
1951 /// List of type arguments that are passed at generic instantiation site. 1958 /// List of type arguments that are passed at generic instantiation site.
1952 /// 1959 ///
1953 /// ``` 1960 /// ```
1954 /// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar; 1961 /// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar;
1955 /// 1962 ///
1956 /// Vec❰ ::<bool> ❱::(); 1963 /// Vec❰ ::<bool> ❱::();
1957 /// ``` 1964 /// ```
1958 /// 1965 ///
1959 /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) 1966 /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
1960 struct TypeArgList { 1967 struct TypeArgList {
1961 T![::], 1968 T![::],
1962 T![<], 1969 T![<],
1963 generic_args: [GenericArg], 1970 generic_args: [GenericArg],
1964 type_args: [TypeArg], 1971 type_args: [TypeArg],
1965 lifetime_args: [LifetimeArg], 1972 lifetime_args: [LifetimeArg],
1966 assoc_type_args: [AssocTypeArg], 1973 assoc_type_args: [AssocTypeArg],
1967 const_args: [ConstArg], 1974 const_args: [ConstArg],
1968 T![>] 1975 T![>]
1969 } 1976 }
1970 1977
1971 /// Type argument that is passed at generic instantiation site. 1978 /// Type argument that is passed at generic instantiation site.
1972 /// 1979 ///
1973 /// ``` 1980 /// ```
1974 /// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz; 1981 /// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz;
1975 /// ``` 1982 /// ```
1976 /// 1983 ///
1977 /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) 1984 /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
1978 struct TypeArg { TypeRef } 1985 struct TypeArg { TypeRef }
1979 1986
1980 /// Associated type argument that is passed at generic instantiation site. 1987 /// Associated type argument that is passed at generic instantiation site.
1981 /// ``` 1988 /// ```
1982 /// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh; 1989 /// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh;
1983 /// 1990 ///
1984 /// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {} 1991 /// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {}
1985 /// ``` 1992 /// ```
1986 /// 1993 ///
1987 struct AssocTypeArg : TypeBoundsOwner { NameRef, T![=], TypeRef } 1994 struct AssocTypeArg : TypeBoundsOwner { NameRef, T![=], TypeRef }
1988 1995
1989 /// Lifetime argument that is passed at generic instantiation site. 1996 /// Lifetime argument that is passed at generic instantiation site.
1990 /// 1997 ///
1991 /// ``` 1998 /// ```
1992 /// fn foo<'a>(s: &'a str) { 1999 /// fn foo<'a>(s: &'a str) {
1993 /// bar::<❰ 'a ❱>(s); 2000 /// bar::<❰ 'a ❱>(s);
1994 /// } 2001 /// }
1995 /// ``` 2002 /// ```
1996 /// 2003 ///
1997 /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) 2004 /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
1998 struct LifetimeArg { T![lifetime] } 2005 struct LifetimeArg { T![lifetime] }
1999 2006
2000 /// Constant value argument that is passed at generic instantiation site. 2007 /// Constant value argument that is passed at generic instantiation site.
2001 /// 2008 ///
2002 /// ``` 2009 /// ```
2003 /// foo::<u32, ❰ { true } ❱>(); 2010 /// foo::<u32, ❰ { true } ❱>();
2004 /// 2011 ///
2005 /// bar::<❰ { 2 + 2} ❱>(); 2012 /// bar::<❰ { 2 + 2} ❱>();
2006 /// ``` 2013 /// ```
2007 /// 2014 ///
2008 /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) 2015 /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter)
2009 struct ConstArg { Literal, BlockExpr } 2016 struct ConstArg { Literal, BlockExpr }
2010 2017
2011 2018
2012 /// FIXME: (@edwin0cheng) Remove it to use ItemList instead 2019 /// FIXME: (@edwin0cheng) Remove it to use ItemList instead
2013 /// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243 2020 /// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243
2014 /// 2021 ///
2015 /// [Reference](https://doc.rust-lang.org/reference/macros.html) 2022 /// [Reference](https://doc.rust-lang.org/reference/macros.html)
2016 struct MacroItems: ModuleItemOwner { } 2023 struct MacroItems: ModuleItemOwner { }
2017 2024
2018 /// FIXME: (@edwin0cheng) add some documentation here. As per the writing 2025 /// FIXME: (@edwin0cheng) add some documentation here. As per the writing
2019 /// of this comment this ast node is not used. 2026 /// of this comment this ast node is not used.
2020 /// 2027 ///
2021 /// ``` 2028 /// ```
2022 /// // FIXME: example here 2029 /// // FIXME: example here
2023 /// ``` 2030 /// ```
2024 /// 2031 ///
2025 /// [Reference](https://doc.rust-lang.org/reference/macros.html) 2032 /// [Reference](https://doc.rust-lang.org/reference/macros.html)
2026 struct MacroStmts { 2033 struct MacroStmts {
2027 statements: [Stmt], 2034 statements: [Stmt],
2028 Expr, 2035 Expr,
2029 } 2036 }
2030 2037
2031 /// List of items in an extern block. 2038 /// List of items in an extern block.
2032 /// 2039 ///
2033 /// ``` 2040 /// ```
2034 /// extern "C" ❰ 2041 /// extern "C" ❰
2035 /// { 2042 /// {
2036 /// fn foo(); 2043 /// fn foo();
2037 /// static var: u32; 2044 /// static var: u32;
2038 /// } 2045 /// }
2039 /// ❱ 2046 /// ❱
2040 /// ``` 2047 /// ```
2041 /// 2048 ///
2042 /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) 2049 /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2043 struct ExternItemList: ModuleItemOwner { 2050 struct ExternItemList: ModuleItemOwner {
2044 T!['{'], 2051 T!['{'],
2045 extern_items: [ExternItem], 2052 extern_items: [ExternItem],
2046 T!['}'] 2053 T!['}']
2047 } 2054 }
2048 2055
2049 /// Extern block. 2056 /// Extern block.
2050 /// 2057 ///
2051 /// ``` 2058 /// ```
2052 /// ❰ 2059 /// ❰
2053 /// extern "C" { 2060 /// extern "C" {
2054 /// fn foo(); 2061 /// fn foo();
2055 /// } 2062 /// }
2056 /// ❱ 2063 /// ❱
2057 /// 2064 ///
2058 /// ``` 2065 /// ```
2059 /// 2066 ///
2060 /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) 2067 /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2061 struct ExternBlock { 2068 struct ExternBlock {
2062 Abi, 2069 Abi,
2063 ExternItemList 2070 ExternItemList
2064 } 2071 }
2065 2072
2066 /// Meta item in an attribute. 2073 /// Meta item in an attribute.
2067 /// 2074 ///
2068 /// ``` 2075 /// ```
2069 /// #[❰ bar::baz = "42" ❱] 2076 /// #[❰ bar::baz = "42" ❱]
2070 /// #[❰ bruh(bruuh("true")) ❱] 2077 /// #[❰ bruh(bruuh("true")) ❱]
2071 /// struct Foo; 2078 /// struct Foo;
2072 /// ``` 2079 /// ```
2073 /// 2080 ///
2074 /// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax) 2081 /// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax)
2075 struct MetaItem { 2082 struct MetaItem {
2076 Path, T![=], AttrInput, nested_meta_items: [MetaItem] 2083 Path, T![=], AttrInput, nested_meta_items: [MetaItem]
2077 } 2084 }
2078 2085
2079 /// Macro 2.0 definition. 2086 /// Macro 2.0 definition.
2080 /// Their syntax is still WIP by rustc team... 2087 /// Their syntax is still WIP by rustc team...
2081 /// ``` 2088 /// ```
2082 /// ❰ 2089 /// ❰
2083 /// macro foo { } 2090 /// macro foo { }
2084 /// ❱ 2091 /// ❱
2085 /// ``` 2092 /// ```
2086 /// 2093 ///
2087 /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md) 2094 /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md)
2088 struct MacroDef { 2095 struct MacroDef {
2089 Name, TokenTree 2096 Name, TokenTree
2090 } 2097 }
2091 }, 2098 },
2092 enums: &ast_enums! { 2099 enums: ast_enums! {
2093 /// Any kind of nominal type definition. 2100 /// Any kind of nominal type definition.
2094 enum NominalDef: NameOwner, TypeParamsOwner, AttrsOwner { 2101 enum NominalDef: NameOwner, TypeParamsOwner, AttrsOwner {
2095 StructDef, EnumDef, UnionDef, 2102 StructDef, EnumDef, UnionDef,
2096 } 2103 }
2097 2104
2098 /// Any kind of **declared** generic parameter 2105 /// Any kind of **declared** generic parameter
2099 enum GenericParam { 2106 enum GenericParam {
2100 LifetimeParam, 2107 LifetimeParam,
2101 TypeParam, 2108 TypeParam,
2102 ConstParam 2109 ConstParam
2103 } 2110 }
2104 2111
2105 /// Any kind of generic argument passed at instantiation site 2112 /// Any kind of generic argument passed at instantiation site
2106 enum GenericArg { 2113 enum GenericArg {
2107 LifetimeArg, 2114 LifetimeArg,
2108 TypeArg, 2115 TypeArg,
2109 ConstArg, 2116 ConstArg,
2110 AssocTypeArg 2117 AssocTypeArg
2111 } 2118 }
2112 2119
2113 /// Any kind of construct valid in type context 2120 /// Any kind of construct valid in type context
2114 enum TypeRef { 2121 enum TypeRef {
2115 ParenType, 2122 ParenType,
2116 TupleType, 2123 TupleType,
2117 NeverType, 2124 NeverType,
2118 PathType, 2125 PathType,
2119 PointerType, 2126 PointerType,
2120 ArrayType, 2127 ArrayType,
2121 SliceType, 2128 SliceType,
2122 ReferenceType, 2129 ReferenceType,
2123 PlaceholderType, 2130 PlaceholderType,
2124 FnPointerType, 2131 FnPointerType,
2125 ForType, 2132 ForType,
2126 ImplTraitType, 2133 ImplTraitType,
2127 DynTraitType, 2134 DynTraitType,
2128 } 2135 }
2129 2136
2130 /// Any kind of top-level item that may appear in a module 2137 /// Any kind of top-level item that may appear in a module
2131 enum ModuleItem: NameOwner, AttrsOwner, VisibilityOwner { 2138 enum ModuleItem: NameOwner, AttrsOwner, VisibilityOwner {
2132 StructDef, 2139 StructDef,
2133 UnionDef, 2140 UnionDef,
2134 EnumDef, 2141 EnumDef,
2135 FnDef, 2142 FnDef,
2136 TraitDef, 2143 TraitDef,
2137 TypeAliasDef, 2144 TypeAliasDef,
2138 ImplDef, 2145 ImplDef,
2139 UseItem, 2146 UseItem,
2140 ExternCrateItem, 2147 ExternCrateItem,
2141 ConstDef, 2148 ConstDef,
2142 StaticDef, 2149 StaticDef,
2143 Module, 2150 Module,
2144 MacroCall, 2151 MacroCall,
2145 ExternBlock 2152 ExternBlock
2146 } 2153 }
2147 2154
2148 2155
2149 2156
2150 /// Any kind of item that may appear in an impl block 2157 /// Any kind of item that may appear in an impl block
2151 /// 2158 ///
2152 /// // FIXME: impl blocks can also contain MacroCall 2159 /// // FIXME: impl blocks can also contain MacroCall
2153 enum AssocItem: NameOwner, AttrsOwner { 2160 enum AssocItem: NameOwner, AttrsOwner {
2154 FnDef, TypeAliasDef, ConstDef 2161 FnDef, TypeAliasDef, ConstDef
2155 } 2162 }
2156 2163
2157 /// Any kind of item that may appear in an extern block 2164 /// Any kind of item that may appear in an extern block
2158 /// 2165 ///
2159 /// // FIXME: extern blocks can also contain MacroCall 2166 /// // FIXME: extern blocks can also contain MacroCall
2160 enum ExternItem: NameOwner, AttrsOwner, VisibilityOwner { 2167 enum ExternItem: NameOwner, AttrsOwner, VisibilityOwner {
2161 FnDef, StaticDef 2168 FnDef, StaticDef
2162 } 2169 }
2163 2170
2164 /// Any kind of expression 2171 /// Any kind of expression
2165 enum Expr: AttrsOwner { 2172 enum Expr: AttrsOwner {
2166 TupleExpr, 2173 TupleExpr,
2167 ArrayExpr, 2174 ArrayExpr,
2168 ParenExpr, 2175 ParenExpr,
2169 PathExpr, 2176 PathExpr,
2170 LambdaExpr, 2177 LambdaExpr,
2171 IfExpr, 2178 IfExpr,
2172 LoopExpr, 2179 LoopExpr,
2173 ForExpr, 2180 ForExpr,
2174 WhileExpr, 2181 WhileExpr,
2175 ContinueExpr, 2182 ContinueExpr,
2176 BreakExpr, 2183 BreakExpr,
2177 Label, 2184 Label,
2178 BlockExpr, 2185 BlockExpr,
2179 ReturnExpr, 2186 ReturnExpr,
2180 MatchExpr, 2187 MatchExpr,
2181 RecordLit, 2188 RecordLit,
2182 CallExpr, 2189 CallExpr,
2183 IndexExpr, 2190 IndexExpr,
2184 MethodCallExpr, 2191 MethodCallExpr,
2185 FieldExpr, 2192 FieldExpr,
2186 AwaitExpr, 2193 AwaitExpr,
2187 TryExpr, 2194 TryExpr,
2188 EffectExpr, 2195 EffectExpr,
2189 CastExpr, 2196 CastExpr,
2190 RefExpr, 2197 RefExpr,
2191 PrefixExpr, 2198 PrefixExpr,
2192 RangeExpr, 2199 RangeExpr,
2193 BinExpr, 2200 BinExpr,
2194 Literal, 2201 Literal,
2195 MacroCall, 2202 MacroCall,
2196 BoxExpr, 2203 BoxExpr,
2197 } 2204 }
2198 2205
2199 /// Any kind of pattern 2206 /// Any kind of pattern
2200 enum Pat { 2207 enum Pat {
2201 OrPat, 2208 OrPat,
2202 ParenPat, 2209 ParenPat,
2203 RefPat, 2210 RefPat,
2204 BoxPat, 2211 BoxPat,
2205 BindPat, 2212 BindPat,
2206 PlaceholderPat, 2213 PlaceholderPat,
2207 DotDotPat, 2214 DotDotPat,
2208 PathPat, 2215 PathPat,
2209 RecordPat, 2216 RecordPat,
2210 TupleStructPat, 2217 TupleStructPat,
2211 TuplePat, 2218 TuplePat,
2212 SlicePat, 2219 SlicePat,
2213 RangePat, 2220 RangePat,
2214 LiteralPat, 2221 LiteralPat,
2215 MacroPat, 2222 MacroPat,
2216 } 2223 }
2217 2224
2218 /// Any kind of pattern that appears directly inside of the curly 2225 /// Any kind of pattern that appears directly inside of the curly
2219 /// braces of a record pattern 2226 /// braces of a record pattern
2220 enum RecordInnerPat { 2227 enum RecordInnerPat {
2221 RecordFieldPat, 2228 RecordFieldPat,
2222 BindPat 2229 BindPat
2223 } 2230 }
2224 2231
2225 /// Any kind of input to an attribute 2232 /// Any kind of input to an attribute
2226 enum AttrInput { Literal, TokenTree } 2233 enum AttrInput { Literal, TokenTree }
2227 2234
2228 /// Any kind of statement 2235 /// Any kind of statement
2229 /// Note: there are no empty statements, these are just represented as 2236 /// Note: there are no empty statements, these are just represented as
2230 /// bare semicolons without a dedicated statement ast node. 2237 /// bare semicolons without a dedicated statement ast node.
2231 enum Stmt { 2238 enum Stmt {
2232 LetStmt, 2239 LetStmt,
2233 ExprStmt, 2240 ExprStmt,
2234 // macro calls are parsed as expression statements 2241 // macro calls are parsed as expression statements
2235 } 2242 }
2236 2243
2237 /// Any kind of fields list (record or tuple field lists) 2244 /// Any kind of fields list (record or tuple field lists)
2238 enum FieldDefList { 2245 enum FieldDefList {
2239 RecordFieldDefList, 2246 RecordFieldDefList,
2240 TupleFieldDefList, 2247 TupleFieldDefList,
2241 } 2248 }
2242 }, 2249 },
2243}; 2250 }
2251}
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs
index 745a25862..5a18b3e2b 100644
--- a/xtask/src/codegen/gen_syntax.rs
+++ b/xtask/src/codegen/gen_syntax.rs
@@ -9,28 +9,29 @@ use proc_macro2::{Punct, Spacing};
9use quote::{format_ident, quote}; 9use quote::{format_ident, quote};
10 10
11use crate::{ 11use crate::{
12 ast_src::{AstSrc, Field, FieldSrc, KindsSrc, AST_SRC, KINDS_SRC}, 12 ast_src::{rust_ast, AstSrc, Field, FieldSrc, KindsSrc, KINDS_SRC},
13 codegen::{self, update, Mode}, 13 codegen::{self, update, Mode},
14 project_root, Result, 14 project_root, Result,
15}; 15};
16 16
17pub fn generate_syntax(mode: Mode) -> Result<()> { 17pub fn generate_syntax(mode: Mode) -> Result<()> {
18 let ast = rust_ast();
18 let syntax_kinds_file = project_root().join(codegen::SYNTAX_KINDS); 19 let syntax_kinds_file = project_root().join(codegen::SYNTAX_KINDS);
19 let syntax_kinds = generate_syntax_kinds(KINDS_SRC)?; 20 let syntax_kinds = generate_syntax_kinds(KINDS_SRC)?;
20 update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?; 21 update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?;
21 22
22 let ast_tokens_file = project_root().join(codegen::AST_TOKENS); 23 let ast_tokens_file = project_root().join(codegen::AST_TOKENS);
23 let contents = generate_tokens(AST_SRC)?; 24 let contents = generate_tokens(&ast)?;
24 update(ast_tokens_file.as_path(), &contents, mode)?; 25 update(ast_tokens_file.as_path(), &contents, mode)?;
25 26
26 let ast_nodes_file = project_root().join(codegen::AST_NODES); 27 let ast_nodes_file = project_root().join(codegen::AST_NODES);
27 let contents = generate_nodes(KINDS_SRC, AST_SRC)?; 28 let contents = generate_nodes(KINDS_SRC, &ast)?;
28 update(ast_nodes_file.as_path(), &contents, mode)?; 29 update(ast_nodes_file.as_path(), &contents, mode)?;
29 30
30 Ok(()) 31 Ok(())
31} 32}
32 33
33fn generate_tokens(grammar: AstSrc<'_>) -> Result<String> { 34fn generate_tokens(grammar: &AstSrc) -> Result<String> {
34 let tokens = grammar.tokens.iter().map(|token| { 35 let tokens = grammar.tokens.iter().map(|token| {
35 let name = format_ident!("{}", token); 36 let name = format_ident!("{}", token);
36 let kind = format_ident!("{}", to_upper_snake_case(token)); 37 let kind = format_ident!("{}", to_upper_snake_case(token));
@@ -62,13 +63,13 @@ fn generate_tokens(grammar: AstSrc<'_>) -> Result<String> {
62 Ok(pretty) 63 Ok(pretty)
63} 64}
64 65
65fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> { 66fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> {
66 let (node_defs, node_boilerplate_impls): (Vec<_>, Vec<_>) = grammar 67 let (node_defs, node_boilerplate_impls): (Vec<_>, Vec<_>) = grammar
67 .nodes 68 .nodes
68 .iter() 69 .iter()
69 .map(|node| { 70 .map(|node| {
70 let name = format_ident!("{}", node.name); 71 let name = format_ident!("{}", node.name);
71 let kind = format_ident!("{}", to_upper_snake_case(node.name)); 72 let kind = format_ident!("{}", to_upper_snake_case(&node.name));
72 let traits = node.traits.iter().map(|trait_name| { 73 let traits = node.traits.iter().map(|trait_name| {
73 let trait_name = format_ident!("{}", trait_name); 74 let trait_name = format_ident!("{}", trait_name);
74 quote!(impl ast::#trait_name for #name {}) 75 quote!(impl ast::#trait_name for #name {})
@@ -192,8 +193,8 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
192 }) 193 })
193 .unzip(); 194 .unzip();
194 195
195 let enum_names = grammar.enums.iter().map(|it| it.name); 196 let enum_names = grammar.enums.iter().map(|it| &it.name);
196 let node_names = grammar.nodes.iter().map(|it| it.name); 197 let node_names = grammar.nodes.iter().map(|it| &it.name);
197 198
198 let display_impls = 199 let display_impls =
199 enum_names.chain(node_names.clone()).map(|it| format_ident!("{}", it)).map(|name| { 200 enum_names.chain(node_names.clone()).map(|it| format_ident!("{}", it)).map(|name| {
@@ -212,7 +213,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
212 .nodes 213 .nodes
213 .iter() 214 .iter()
214 .map(|kind| to_pascal_case(kind)) 215 .map(|kind| to_pascal_case(kind))
215 .filter(|name| !defined_nodes.contains(name.as_str())) 216 .filter(|name| !defined_nodes.iter().any(|&it| it == name))
216 { 217 {
217 eprintln!("Warning: node {} not defined in ast source", node); 218 eprintln!("Warning: node {} not defined in ast source", node);
218 } 219 }
@@ -236,12 +237,12 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
236 let mut res = String::with_capacity(ast.len() * 2); 237 let mut res = String::with_capacity(ast.len() * 2);
237 238
238 let mut docs = 239 let mut docs =
239 grammar.nodes.iter().map(|it| it.doc).chain(grammar.enums.iter().map(|it| it.doc)); 240 grammar.nodes.iter().map(|it| &it.doc).chain(grammar.enums.iter().map(|it| &it.doc));
240 241
241 for chunk in ast.split("# [ pretty_doc_comment_placeholder_workaround ]") { 242 for chunk in ast.split("# [ pretty_doc_comment_placeholder_workaround ]") {
242 res.push_str(chunk); 243 res.push_str(chunk);
243 if let Some(doc) = docs.next() { 244 if let Some(doc) = docs.next() {
244 write_doc_comment(doc, &mut res); 245 write_doc_comment(&doc, &mut res);
245 } 246 }
246 } 247 }
247 248
@@ -249,7 +250,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
249 Ok(pretty) 250 Ok(pretty)
250} 251}
251 252
252fn write_doc_comment(contents: &[&str], dest: &mut String) { 253fn write_doc_comment(contents: &[String], dest: &mut String) {
253 for line in contents { 254 for line in contents {
254 writeln!(dest, "///{}", line).unwrap(); 255 writeln!(dest, "///{}", line).unwrap();
255 } 256 }
@@ -413,7 +414,7 @@ fn to_pascal_case(s: &str) -> String {
413 buf 414 buf
414} 415}
415 416
416impl Field<'_> { 417impl Field {
417 fn is_many(&self) -> bool { 418 fn is_many(&self) -> bool {
418 matches!(self, Field::Node { src: FieldSrc::Many(_), .. }) 419 matches!(self, Field::Node { src: FieldSrc::Many(_), .. })
419 } 420 }
@@ -429,7 +430,7 @@ impl Field<'_> {
429 fn method_name(&self) -> proc_macro2::Ident { 430 fn method_name(&self) -> proc_macro2::Ident {
430 match self { 431 match self {
431 Field::Token(name) => { 432 Field::Token(name) => {
432 let name = match *name { 433 let name = match name.as_str() {
433 ";" => "semicolon", 434 ";" => "semicolon",
434 "->" => "thin_arrow", 435 "->" => "thin_arrow",
435 "'{'" => "l_curly", 436 "'{'" => "l_curly",