diff options
-rw-r--r-- | Cargo.lock | 86 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_postfix.rs | 58 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated/nodes.rs | 1504 | ||||
-rw-r--r-- | editors/code/package-lock.json | 92 | ||||
-rw-r--r-- | editors/code/package.json | 18 | ||||
-rw-r--r-- | editors/code/src/commands/syntax_tree.ts | 2 | ||||
-rw-r--r-- | xtask/src/ast_src.rs | 1499 | ||||
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 25 |
9 files changed, 3030 insertions, 258 deletions
diff --git a/Cargo.lock b/Cargo.lock index 5a319a040..3a34978b1 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1,6 +1,15 @@ | |||
1 | # This file is automatically @generated by Cargo. | 1 | # This file is automatically @generated by Cargo. |
2 | # It is not intended for manual editing. | 2 | # It is not intended for manual editing. |
3 | [[package]] | 3 | [[package]] |
4 | name = "addr2line" | ||
5 | version = "0.12.0" | ||
6 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
7 | checksum = "456d75cbb82da1ad150c8a9d97285ffcd21c9931dcb11e995903e7d75141b38b" | ||
8 | dependencies = [ | ||
9 | "gimli", | ||
10 | ] | ||
11 | |||
12 | [[package]] | ||
4 | name = "aho-corasick" | 13 | name = "aho-corasick" |
5 | version = "0.7.10" | 14 | version = "0.7.10" |
6 | source = "registry+https://github.com/rust-lang/crates.io-index" | 15 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -11,9 +20,9 @@ dependencies = [ | |||
11 | 20 | ||
12 | [[package]] | 21 | [[package]] |
13 | name = "anyhow" | 22 | name = "anyhow" |
14 | version = "1.0.28" | 23 | version = "1.0.29" |
15 | source = "registry+https://github.com/rust-lang/crates.io-index" | 24 | source = "registry+https://github.com/rust-lang/crates.io-index" |
16 | checksum = "d9a60d744a80c30fcb657dfe2c1b22bcb3e814c1a1e3674f32bf5820b570fbff" | 25 | checksum = "dc98824304f5513bb8f862f9e5985219003de4d730689e59d8f28818283a6fe4" |
17 | 26 | ||
18 | [[package]] | 27 | [[package]] |
19 | name = "anymap" | 28 | name = "anymap" |
@@ -46,27 +55,18 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" | |||
46 | 55 | ||
47 | [[package]] | 56 | [[package]] |
48 | name = "backtrace" | 57 | name = "backtrace" |
49 | version = "0.3.46" | 58 | version = "0.3.47" |
50 | source = "registry+https://github.com/rust-lang/crates.io-index" | 59 | source = "registry+https://github.com/rust-lang/crates.io-index" |
51 | checksum = "b1e692897359247cc6bb902933361652380af0f1b7651ae5c5013407f30e109e" | 60 | checksum = "a5393cb2f40a6fae0014c9af00018e95846f3b241b331a6b7733c326d3e58108" |
52 | dependencies = [ | 61 | dependencies = [ |
53 | "backtrace-sys", | 62 | "addr2line", |
54 | "cfg-if", | 63 | "cfg-if", |
55 | "libc", | 64 | "libc", |
65 | "object", | ||
56 | "rustc-demangle", | 66 | "rustc-demangle", |
57 | ] | 67 | ] |
58 | 68 | ||
59 | [[package]] | 69 | [[package]] |
60 | name = "backtrace-sys" | ||
61 | version = "0.1.37" | ||
62 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
63 | checksum = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399" | ||
64 | dependencies = [ | ||
65 | "cc", | ||
66 | "libc", | ||
67 | ] | ||
68 | |||
69 | [[package]] | ||
70 | name = "base64" | 70 | name = "base64" |
71 | version = "0.12.1" | 71 | version = "0.12.1" |
72 | source = "registry+https://github.com/rust-lang/crates.io-index" | 72 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -80,9 +80,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" | |||
80 | 80 | ||
81 | [[package]] | 81 | [[package]] |
82 | name = "bstr" | 82 | name = "bstr" |
83 | version = "0.2.12" | 83 | version = "0.2.13" |
84 | source = "registry+https://github.com/rust-lang/crates.io-index" | 84 | source = "registry+https://github.com/rust-lang/crates.io-index" |
85 | checksum = "2889e6d50f394968c8bf4240dc3f2a7eb4680844d27308f798229ac9d4725f41" | 85 | checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" |
86 | dependencies = [ | 86 | dependencies = [ |
87 | "memchr", | 87 | "memchr", |
88 | ] | 88 | ] |
@@ -423,6 +423,12 @@ dependencies = [ | |||
423 | ] | 423 | ] |
424 | 424 | ||
425 | [[package]] | 425 | [[package]] |
426 | name = "gimli" | ||
427 | version = "0.21.0" | ||
428 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
429 | checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" | ||
430 | |||
431 | [[package]] | ||
426 | name = "globset" | 432 | name = "globset" |
427 | version = "0.4.5" | 433 | version = "0.4.5" |
428 | source = "registry+https://github.com/rust-lang/crates.io-index" | 434 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -437,9 +443,9 @@ dependencies = [ | |||
437 | 443 | ||
438 | [[package]] | 444 | [[package]] |
439 | name = "goblin" | 445 | name = "goblin" |
440 | version = "0.2.1" | 446 | version = "0.2.3" |
441 | source = "registry+https://github.com/rust-lang/crates.io-index" | 447 | source = "registry+https://github.com/rust-lang/crates.io-index" |
442 | checksum = "ddd5e3132801a1ac34ac53b97acde50c4685414dd2f291b9ea52afa6f07468c8" | 448 | checksum = "d20fd25aa456527ce4f544271ae4fea65d2eda4a6561ea56f39fb3ee4f7e3884" |
443 | dependencies = [ | 449 | dependencies = [ |
444 | "log", | 450 | "log", |
445 | "plain", | 451 | "plain", |
@@ -613,9 +619,9 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" | |||
613 | 619 | ||
614 | [[package]] | 620 | [[package]] |
615 | name = "libc" | 621 | name = "libc" |
616 | version = "0.2.69" | 622 | version = "0.2.70" |
617 | source = "registry+https://github.com/rust-lang/crates.io-index" | 623 | source = "registry+https://github.com/rust-lang/crates.io-index" |
618 | checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005" | 624 | checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" |
619 | 625 | ||
620 | [[package]] | 626 | [[package]] |
621 | name = "libloading" | 627 | name = "libloading" |
@@ -796,6 +802,12 @@ dependencies = [ | |||
796 | ] | 802 | ] |
797 | 803 | ||
798 | [[package]] | 804 | [[package]] |
805 | name = "object" | ||
806 | version = "0.19.0" | ||
807 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
808 | checksum = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2" | ||
809 | |||
810 | [[package]] | ||
799 | name = "once_cell" | 811 | name = "once_cell" |
800 | version = "1.3.1" | 812 | version = "1.3.1" |
801 | source = "registry+https://github.com/rust-lang/crates.io-index" | 813 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -904,9 +916,9 @@ dependencies = [ | |||
904 | 916 | ||
905 | [[package]] | 917 | [[package]] |
906 | name = "quote" | 918 | name = "quote" |
907 | version = "1.0.4" | 919 | version = "1.0.5" |
908 | source = "registry+https://github.com/rust-lang/crates.io-index" | 920 | source = "registry+https://github.com/rust-lang/crates.io-index" |
909 | checksum = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7" | 921 | checksum = "42934bc9c8ab0d3b273a16d8551c8f0fcff46be73276ca083ec2414c15c4ba5e" |
910 | dependencies = [ | 922 | dependencies = [ |
911 | "proc-macro2", | 923 | "proc-macro2", |
912 | ] | 924 | ] |
@@ -1487,9 +1499,9 @@ dependencies = [ | |||
1487 | 1499 | ||
1488 | [[package]] | 1500 | [[package]] |
1489 | name = "scroll_derive" | 1501 | name = "scroll_derive" |
1490 | version = "0.10.1" | 1502 | version = "0.10.2" |
1491 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1503 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1492 | checksum = "f8584eea9b9ff42825b46faf46a8c24d2cff13ec152fa2a50df788b87c07ee28" | 1504 | checksum = "e367622f934864ffa1c704ba2b82280aab856e3d8213c84c5720257eb34b15b9" |
1493 | dependencies = [ | 1505 | dependencies = [ |
1494 | "proc-macro2", | 1506 | "proc-macro2", |
1495 | "quote", | 1507 | "quote", |
@@ -1514,18 +1526,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" | |||
1514 | 1526 | ||
1515 | [[package]] | 1527 | [[package]] |
1516 | name = "serde" | 1528 | name = "serde" |
1517 | version = "1.0.107" | 1529 | version = "1.0.110" |
1518 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1530 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1519 | checksum = "eba7550f2cdf88ffc23ab0f1607133486c390a8c0f89b57e589b9654ee15e04d" | 1531 | checksum = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c" |
1520 | dependencies = [ | 1532 | dependencies = [ |
1521 | "serde_derive", | 1533 | "serde_derive", |
1522 | ] | 1534 | ] |
1523 | 1535 | ||
1524 | [[package]] | 1536 | [[package]] |
1525 | name = "serde_derive" | 1537 | name = "serde_derive" |
1526 | version = "1.0.107" | 1538 | version = "1.0.110" |
1527 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1539 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1528 | checksum = "10be45e22e5597d4b88afcc71f9d7bfadcd604bf0c78a3ab4582b8d2b37f39f3" | 1540 | checksum = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984" |
1529 | dependencies = [ | 1541 | dependencies = [ |
1530 | "proc-macro2", | 1542 | "proc-macro2", |
1531 | "quote", | 1543 | "quote", |
@@ -1534,9 +1546,9 @@ dependencies = [ | |||
1534 | 1546 | ||
1535 | [[package]] | 1547 | [[package]] |
1536 | name = "serde_json" | 1548 | name = "serde_json" |
1537 | version = "1.0.52" | 1549 | version = "1.0.53" |
1538 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1550 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1539 | checksum = "a7894c8ed05b7a3a279aeb79025fdec1d3158080b75b98a08faf2806bb799edd" | 1551 | checksum = "993948e75b189211a9b31a7528f950c6adc21f9720b6438ff80a7fa2f864cea2" |
1540 | dependencies = [ | 1552 | dependencies = [ |
1541 | "itoa", | 1553 | "itoa", |
1542 | "ryu", | 1554 | "ryu", |
@@ -1556,9 +1568,9 @@ dependencies = [ | |||
1556 | 1568 | ||
1557 | [[package]] | 1569 | [[package]] |
1558 | name = "serde_yaml" | 1570 | name = "serde_yaml" |
1559 | version = "0.8.11" | 1571 | version = "0.8.12" |
1560 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1572 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1561 | checksum = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35" | 1573 | checksum = "16c7a592a1ec97c9c1c68d75b6e537dcbf60c7618e038e7841e00af1d9ccf0c4" |
1562 | dependencies = [ | 1574 | dependencies = [ |
1563 | "dtoa", | 1575 | "dtoa", |
1564 | "linked-hash-map", | 1576 | "linked-hash-map", |
@@ -1599,9 +1611,9 @@ checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" | |||
1599 | 1611 | ||
1600 | [[package]] | 1612 | [[package]] |
1601 | name = "syn" | 1613 | name = "syn" |
1602 | version = "1.0.19" | 1614 | version = "1.0.21" |
1603 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1615 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1604 | checksum = "e8e5aa70697bb26ee62214ae3288465ecec0000f05182f039b477001f08f5ae7" | 1616 | checksum = "4696caa4048ac7ce2bcd2e484b3cef88c1004e41b8e945a277e2c25dc0b72060" |
1605 | dependencies = [ | 1617 | dependencies = [ |
1606 | "proc-macro2", | 1618 | "proc-macro2", |
1607 | "quote", | 1619 | "quote", |
@@ -1685,9 +1697,9 @@ dependencies = [ | |||
1685 | 1697 | ||
1686 | [[package]] | 1698 | [[package]] |
1687 | name = "threadpool" | 1699 | name = "threadpool" |
1688 | version = "1.8.0" | 1700 | version = "1.8.1" |
1689 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1701 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1690 | checksum = "e8dae184447c15d5a6916d973c642aec485105a13cd238192a6927ae3e077d66" | 1702 | checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" |
1691 | dependencies = [ | 1703 | dependencies = [ |
1692 | "num_cpus", | 1704 | "num_cpus", |
1693 | ] | 1705 | ] |
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index d8b3d342c..3bce8f673 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -360,7 +360,7 @@ fn env_expand( | |||
360 | // However, we cannot use an empty string here, because for | 360 | // However, we cannot use an empty string here, because for |
361 | // `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become | 361 | // `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become |
362 | // `include!("foo.rs"), which might go to infinite loop | 362 | // `include!("foo.rs"), which might go to infinite loop |
363 | let s = get_env_inner(db, arg_id, &key).unwrap_or_else(|| "__RA_UNIMPLEMENTATED__".to_string()); | 363 | let s = get_env_inner(db, arg_id, &key).unwrap_or_else(|| "__RA_UNIMPLEMENTED__".to_string()); |
364 | let expanded = quote! { #s }; | 364 | let expanded = quote! { #s }; |
365 | 365 | ||
366 | Ok((expanded, FragmentKind::Expr)) | 366 | Ok((expanded, FragmentKind::Expr)) |
@@ -508,7 +508,7 @@ mod tests { | |||
508 | "#, | 508 | "#, |
509 | ); | 509 | ); |
510 | 510 | ||
511 | assert_eq!(expanded, "\"__RA_UNIMPLEMENTATED__\""); | 511 | assert_eq!(expanded, "\"__RA_UNIMPLEMENTED__\""); |
512 | } | 512 | } |
513 | 513 | ||
514 | #[test] | 514 | #[test] |
diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs index c5c4426cc..f2a52a407 100644 --- a/crates/ra_ide/src/completion/complete_postfix.rs +++ b/crates/ra_ide/src/completion/complete_postfix.rs | |||
@@ -38,8 +38,8 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
38 | Some(it) => it, | 38 | Some(it) => it, |
39 | None => return, | 39 | None => return, |
40 | }; | 40 | }; |
41 | 41 | let try_enum = TryEnum::from_ty(&ctx.sema, &receiver_ty); | |
42 | if let Some(try_enum) = TryEnum::from_ty(&ctx.sema, &receiver_ty) { | 42 | if let Some(try_enum) = &try_enum { |
43 | match try_enum { | 43 | match try_enum { |
44 | TryEnum::Result => { | 44 | TryEnum::Result => { |
45 | postfix_snippet( | 45 | postfix_snippet( |
@@ -104,7 +104,6 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
104 | ) | 104 | ) |
105 | .add_to(acc); | 105 | .add_to(acc); |
106 | } | 106 | } |
107 | |||
108 | // !&&&42 is a compiler error, ergo process it before considering the references | 107 | // !&&&42 is a compiler error, ergo process it before considering the references |
109 | postfix_snippet(ctx, cap, &dot_receiver, "not", "!expr", &format!("!{}", receiver_text)) | 108 | postfix_snippet(ctx, cap, &dot_receiver, "not", "!expr", &format!("!{}", receiver_text)) |
110 | .add_to(acc); | 109 | .add_to(acc); |
@@ -126,16 +125,45 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
126 | let dot_receiver = include_references(dot_receiver); | 125 | let dot_receiver = include_references(dot_receiver); |
127 | let receiver_text = | 126 | let receiver_text = |
128 | get_receiver_text(&dot_receiver, ctx.dot_receiver_is_ambiguous_float_literal); | 127 | get_receiver_text(&dot_receiver, ctx.dot_receiver_is_ambiguous_float_literal); |
129 | 128 | match try_enum { | |
130 | postfix_snippet( | 129 | Some(try_enum) => { |
131 | ctx, | 130 | match try_enum { |
132 | cap, | 131 | TryEnum::Result => { |
133 | &dot_receiver, | 132 | postfix_snippet( |
134 | "match", | 133 | ctx, |
135 | "match expr {}", | 134 | cap, |
136 | &format!("match {} {{\n ${{1:_}} => {{$0\\}},\n}}", receiver_text), | 135 | &dot_receiver, |
137 | ) | 136 | "match", |
138 | .add_to(acc); | 137 | "match expr {}", |
138 | &format!("match {} {{\n Ok(${{1:_}}) => {{$2\\}},\n Err(${{3:_}}) => {{$0\\}},\n}}", receiver_text), | ||
139 | ) | ||
140 | .add_to(acc); | ||
141 | } | ||
142 | TryEnum::Option => { | ||
143 | postfix_snippet( | ||
144 | ctx, | ||
145 | cap, | ||
146 | &dot_receiver, | ||
147 | "match", | ||
148 | "match expr {}", | ||
149 | &format!("match {} {{\n Some(${{1:_}}) => {{$2\\}},\n None => {{$0\\}},\n}}", receiver_text), | ||
150 | ) | ||
151 | .add_to(acc); | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | None => { | ||
156 | postfix_snippet( | ||
157 | ctx, | ||
158 | cap, | ||
159 | &dot_receiver, | ||
160 | "match", | ||
161 | "match expr {}", | ||
162 | &format!("match {} {{\n ${{1:_}} => {{$0\\}},\n}}", receiver_text), | ||
163 | ) | ||
164 | .add_to(acc); | ||
165 | } | ||
166 | } | ||
139 | 167 | ||
140 | postfix_snippet( | 168 | postfix_snippet( |
141 | ctx, | 169 | ctx, |
@@ -324,7 +352,7 @@ mod tests { | |||
324 | label: "match", | 352 | label: "match", |
325 | source_range: 210..210, | 353 | source_range: 210..210, |
326 | delete: 206..210, | 354 | delete: 206..210, |
327 | insert: "match bar {\n ${1:_} => {$0\\},\n}", | 355 | insert: "match bar {\n Some(${1:_}) => {$2\\},\n None => {$0\\},\n}", |
328 | detail: "match expr {}", | 356 | detail: "match expr {}", |
329 | }, | 357 | }, |
330 | CompletionItem { | 358 | CompletionItem { |
@@ -403,7 +431,7 @@ mod tests { | |||
403 | label: "match", | 431 | label: "match", |
404 | source_range: 211..211, | 432 | source_range: 211..211, |
405 | delete: 207..211, | 433 | delete: 207..211, |
406 | insert: "match bar {\n ${1:_} => {$0\\},\n}", | 434 | insert: "match bar {\n Ok(${1:_}) => {$2\\},\n Err(${3:_}) => {$0\\},\n}", |
407 | detail: "match expr {}", | 435 | detail: "match expr {}", |
408 | }, | 436 | }, |
409 | CompletionItem { | 437 | CompletionItem { |
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index b00c15608..cf6067e57 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs | |||
@@ -5,7 +5,9 @@ use crate::{ | |||
5 | SyntaxKind::{self, *}, | 5 | SyntaxKind::{self, *}, |
6 | SyntaxNode, SyntaxToken, T, | 6 | SyntaxNode, SyntaxToken, T, |
7 | }; | 7 | }; |
8 | 8 | /// The entire Rust source file. Includes all top-level inner attributes and module items. | |
9 | /// | ||
10 | /// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html) | ||
9 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 11 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
10 | pub struct SourceFile { | 12 | pub struct SourceFile { |
11 | pub(crate) syntax: SyntaxNode, | 13 | pub(crate) syntax: SyntaxNode, |
@@ -16,7 +18,28 @@ impl ast::DocCommentsOwner for SourceFile {} | |||
16 | impl SourceFile { | 18 | impl SourceFile { |
17 | pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } | 19 | pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } |
18 | } | 20 | } |
19 | 21 | /// Function definition either with body or not. | |
22 | /// Includes all of its attributes and doc comments. | ||
23 | /// | ||
24 | /// ``` | ||
25 | /// ❰ | ||
26 | /// /// Docs | ||
27 | /// #[attr] | ||
28 | /// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32 | ||
29 | /// where | ||
30 | /// T: Debug | ||
31 | /// { | ||
32 | /// 42 | ||
33 | /// } | ||
34 | /// ❱ | ||
35 | /// | ||
36 | /// extern "C" { | ||
37 | /// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱ | ||
38 | /// } | ||
39 | /// ``` | ||
40 | /// | ||
41 | /// - [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
42 | /// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions) | ||
20 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 43 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
21 | pub struct FnDef { | 44 | pub struct FnDef { |
22 | pub(crate) syntax: SyntaxNode, | 45 | pub(crate) syntax: SyntaxNode, |
@@ -38,7 +61,13 @@ impl FnDef { | |||
38 | pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 61 | pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
39 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 62 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
40 | } | 63 | } |
41 | 64 | /// Return type annotation. | |
65 | /// | ||
66 | /// ``` | ||
67 | /// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) } | ||
68 | /// ``` | ||
69 | /// | ||
70 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
42 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 71 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
43 | pub struct RetType { | 72 | pub struct RetType { |
44 | pub(crate) syntax: SyntaxNode, | 73 | pub(crate) syntax: SyntaxNode, |
@@ -47,7 +76,26 @@ impl RetType { | |||
47 | pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } | 76 | pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } |
48 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 77 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
49 | } | 78 | } |
50 | 79 | /// Struct definition. | |
80 | /// Includes all of its attributes and doc comments. | ||
81 | /// | ||
82 | /// ``` | ||
83 | /// ❰ | ||
84 | /// /// Docs | ||
85 | /// #[attr] | ||
86 | /// struct Foo<T> where T: Debug { | ||
87 | /// /// Docs | ||
88 | /// #[attr] | ||
89 | /// pub a: u32, | ||
90 | /// b: T, | ||
91 | /// } | ||
92 | /// ❱ | ||
93 | /// | ||
94 | /// ❰ struct Foo; ❱ | ||
95 | /// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱ | ||
96 | /// ``` | ||
97 | /// | ||
98 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
51 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 99 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
52 | pub struct StructDef { | 100 | pub struct StructDef { |
53 | pub(crate) syntax: SyntaxNode, | 101 | pub(crate) syntax: SyntaxNode, |
@@ -62,7 +110,23 @@ impl StructDef { | |||
62 | pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } | 110 | pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } |
63 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 111 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
64 | } | 112 | } |
65 | 113 | /// Union definition. | |
114 | /// Includes all of its attributes and doc comments. | ||
115 | /// | ||
116 | /// ``` | ||
117 | /// ❰ | ||
118 | /// /// Docs | ||
119 | /// #[attr] | ||
120 | /// pub union Foo<T> where T: Debug { | ||
121 | /// /// Docs | ||
122 | /// #[attr] | ||
123 | /// a: T, | ||
124 | /// b: u32, | ||
125 | /// } | ||
126 | /// ❱ | ||
127 | /// ``` | ||
128 | /// | ||
129 | /// [Reference](https://doc.rust-lang.org/reference/items/unions.html) | ||
66 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 130 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
67 | pub struct UnionDef { | 131 | pub struct UnionDef { |
68 | pub(crate) syntax: SyntaxNode, | 132 | pub(crate) syntax: SyntaxNode, |
@@ -78,7 +142,19 @@ impl UnionDef { | |||
78 | support::child(&self.syntax) | 142 | support::child(&self.syntax) |
79 | } | 143 | } |
80 | } | 144 | } |
81 | 145 | /// Record field definition list including enclosing curly braces. | |
146 | /// | ||
147 | /// ``` | ||
148 | /// struct Foo // same for union | ||
149 | /// ❰ | ||
150 | /// { | ||
151 | /// a: u32, | ||
152 | /// b: bool, | ||
153 | /// } | ||
154 | /// ❱ | ||
155 | /// ``` | ||
156 | /// | ||
157 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
82 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 158 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
83 | pub struct RecordFieldDefList { | 159 | pub struct RecordFieldDefList { |
84 | pub(crate) syntax: SyntaxNode, | 160 | pub(crate) syntax: SyntaxNode, |
@@ -88,7 +164,22 @@ impl RecordFieldDefList { | |||
88 | pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } | 164 | pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } |
89 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 165 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
90 | } | 166 | } |
91 | 167 | /// Record field definition including its attributes and doc comments. | |
168 | /// | ||
169 | /// ` `` | ||
170 | /// same for union | ||
171 | /// struct Foo { | ||
172 | /// ❰ | ||
173 | /// /// Docs | ||
174 | /// #[attr] | ||
175 | /// pub a: u32 | ||
176 | /// ❱ | ||
177 | /// | ||
178 | /// ❰ b: bool ❱ | ||
179 | /// } | ||
180 | /// ``` | ||
181 | /// | ||
182 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
92 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 183 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
93 | pub struct RecordFieldDef { | 184 | pub struct RecordFieldDef { |
94 | pub(crate) syntax: SyntaxNode, | 185 | pub(crate) syntax: SyntaxNode, |
@@ -99,7 +190,13 @@ impl ast::AttrsOwner for RecordFieldDef {} | |||
99 | impl ast::DocCommentsOwner for RecordFieldDef {} | 190 | impl ast::DocCommentsOwner for RecordFieldDef {} |
100 | impl ast::TypeAscriptionOwner for RecordFieldDef {} | 191 | impl ast::TypeAscriptionOwner for RecordFieldDef {} |
101 | impl RecordFieldDef {} | 192 | impl RecordFieldDef {} |
102 | 193 | /// Tuple field definition list including enclosing parens. | |
194 | /// | ||
195 | /// ``` | ||
196 | /// struct Foo ❰ (u32, String, Vec<u32>) ❱; | ||
197 | /// ``` | ||
198 | /// | ||
199 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
103 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 200 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
104 | pub struct TupleFieldDefList { | 201 | pub struct TupleFieldDefList { |
105 | pub(crate) syntax: SyntaxNode, | 202 | pub(crate) syntax: SyntaxNode, |
@@ -109,7 +206,13 @@ impl TupleFieldDefList { | |||
109 | pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) } | 206 | pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) } |
110 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 207 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
111 | } | 208 | } |
112 | 209 | /// Tuple field definition including its attributes. | |
210 | /// | ||
211 | /// ``` | ||
212 | /// struct Foo(❰ #[attr] u32 ❱); | ||
213 | /// ``` | ||
214 | /// | ||
215 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
113 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 216 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
114 | pub struct TupleFieldDef { | 217 | pub struct TupleFieldDef { |
115 | pub(crate) syntax: SyntaxNode, | 218 | pub(crate) syntax: SyntaxNode, |
@@ -119,7 +222,29 @@ impl ast::AttrsOwner for TupleFieldDef {} | |||
119 | impl TupleFieldDef { | 222 | impl TupleFieldDef { |
120 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 223 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
121 | } | 224 | } |
122 | 225 | /// Enum definition. | |
226 | /// Includes all of its attributes and doc comments. | ||
227 | /// | ||
228 | /// ``` | ||
229 | /// ❰ | ||
230 | /// /// Docs | ||
231 | /// #[attr] | ||
232 | /// pub enum Foo<T> where T: Debug { | ||
233 | /// /// Docs | ||
234 | /// #[attr] | ||
235 | /// Bar, | ||
236 | /// Baz(#[attr] u32), | ||
237 | /// Bruh { | ||
238 | /// a: u32, | ||
239 | /// /// Docs | ||
240 | /// #[attr] | ||
241 | /// b: T, | ||
242 | /// } | ||
243 | /// } | ||
244 | /// ❱ | ||
245 | /// ``` | ||
246 | /// | ||
247 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
123 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 248 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
124 | pub struct EnumDef { | 249 | pub struct EnumDef { |
125 | pub(crate) syntax: SyntaxNode, | 250 | pub(crate) syntax: SyntaxNode, |
@@ -133,7 +258,22 @@ impl EnumDef { | |||
133 | pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } | 258 | pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } |
134 | pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } | 259 | pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } |
135 | } | 260 | } |
136 | 261 | /// Enum variant definition list including enclosing curly braces. | |
262 | /// | ||
263 | /// ``` | ||
264 | /// enum Foo | ||
265 | /// ❰ | ||
266 | /// { | ||
267 | /// Bar, | ||
268 | /// Baz(u32), | ||
269 | /// Bruh { | ||
270 | /// a: u32 | ||
271 | /// } | ||
272 | /// } | ||
273 | /// ❱ | ||
274 | /// ``` | ||
275 | /// | ||
276 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
137 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 277 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
138 | pub struct EnumVariantList { | 278 | pub struct EnumVariantList { |
139 | pub(crate) syntax: SyntaxNode, | 279 | pub(crate) syntax: SyntaxNode, |
@@ -143,7 +283,21 @@ impl EnumVariantList { | |||
143 | pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } | 283 | pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } |
144 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 284 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
145 | } | 285 | } |
146 | 286 | /// Enum variant definition including its attributes and discriminant value definition. | |
287 | /// | ||
288 | /// ``` | ||
289 | /// enum Foo { | ||
290 | /// ❰ | ||
291 | /// /// Docs | ||
292 | /// #[attr] | ||
293 | /// Bar | ||
294 | /// ❱ | ||
295 | /// | ||
296 | /// // same for tuple and record variants | ||
297 | /// } | ||
298 | /// ``` | ||
299 | /// | ||
300 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
147 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 301 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
148 | pub struct EnumVariant { | 302 | pub struct EnumVariant { |
149 | pub(crate) syntax: SyntaxNode, | 303 | pub(crate) syntax: SyntaxNode, |
@@ -157,7 +311,20 @@ impl EnumVariant { | |||
157 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 311 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
158 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 312 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
159 | } | 313 | } |
160 | 314 | /// Trait definition. | |
315 | /// Includes all of its attributes and doc comments. | ||
316 | /// | ||
317 | /// ``` | ||
318 | /// ❰ | ||
319 | /// /// Docs | ||
320 | /// #[attr] | ||
321 | /// pub unsafe trait Foo<T>: Debug where T: Debug { | ||
322 | /// // ... | ||
323 | /// } | ||
324 | /// ❱ | ||
325 | /// ``` | ||
326 | /// | ||
327 | /// [Reference](https://doc.rust-lang.org/reference/items/traits.html) | ||
161 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 328 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
162 | pub struct TraitDef { | 329 | pub struct TraitDef { |
163 | pub(crate) syntax: SyntaxNode, | 330 | pub(crate) syntax: SyntaxNode, |
@@ -174,7 +341,27 @@ impl TraitDef { | |||
174 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } | 341 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } |
175 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 342 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } |
176 | } | 343 | } |
177 | 344 | /// Module definition either with body or not. | |
345 | /// Includes all of its inner and outer attributes, module items, doc comments. | ||
346 | /// | ||
347 | /// ``` | ||
348 | /// ❰ | ||
349 | /// /// Docs | ||
350 | /// #[attr] | ||
351 | /// pub mod foo; | ||
352 | /// ❱ | ||
353 | /// | ||
354 | /// ❰ | ||
355 | /// /// Docs | ||
356 | /// #[attr] | ||
357 | /// pub mod bar { | ||
358 | /// //! Inner docs | ||
359 | /// #![inner_attr] | ||
360 | /// } | ||
361 | /// ❱ | ||
362 | /// ``` | ||
363 | /// | ||
364 | /// [Reference](https://doc.rust-lang.org/reference/items/modules.html) | ||
178 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 365 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
179 | pub struct Module { | 366 | pub struct Module { |
180 | pub(crate) syntax: SyntaxNode, | 367 | pub(crate) syntax: SyntaxNode, |
@@ -188,7 +375,28 @@ impl Module { | |||
188 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 375 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } |
189 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 376 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
190 | } | 377 | } |
191 | 378 | /// Item defintion list. | |
379 | /// This is used for both top-level items and impl block items. | ||
380 | /// | ||
381 | /// ``` | ||
382 | /// ❰ | ||
383 | /// fn foo {} | ||
384 | /// struct Bar; | ||
385 | /// enum Baz; | ||
386 | /// trait Bruh; | ||
387 | /// const BRUUH: u32 = 42; | ||
388 | /// ❱ | ||
389 | /// | ||
390 | /// impl Foo | ||
391 | /// ❰ | ||
392 | /// { | ||
393 | /// fn bar() {} | ||
394 | /// const BAZ: u32 = 42; | ||
395 | /// } | ||
396 | /// ❱ | ||
397 | /// ``` | ||
398 | /// | ||
399 | /// [Reference](https://doc.rust-lang.org/reference/items.html) | ||
192 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 400 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
193 | pub struct ItemList { | 401 | pub struct ItemList { |
194 | pub(crate) syntax: SyntaxNode, | 402 | pub(crate) syntax: SyntaxNode, |
@@ -199,7 +407,18 @@ impl ItemList { | |||
199 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } | 407 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } |
200 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 408 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
201 | } | 409 | } |
202 | 410 | /// Constant variable definition. | |
411 | /// Includes all of its attributes and doc comments. | ||
412 | /// | ||
413 | /// ``` | ||
414 | /// ❰ | ||
415 | /// /// Docs | ||
416 | /// #[attr] | ||
417 | /// pub const FOO: u32 = 42; | ||
418 | /// ❱ | ||
419 | /// ``` | ||
420 | /// | ||
421 | /// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html) | ||
203 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 422 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
204 | pub struct ConstDef { | 423 | pub struct ConstDef { |
205 | pub(crate) syntax: SyntaxNode, | 424 | pub(crate) syntax: SyntaxNode, |
@@ -217,7 +436,18 @@ impl ConstDef { | |||
217 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 436 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
218 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 437 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
219 | } | 438 | } |
220 | 439 | /// Static variable definition. | |
440 | /// Includes all of its attributes and doc comments. | ||
441 | /// | ||
442 | /// ``` | ||
443 | /// ❰ | ||
444 | /// /// Docs | ||
445 | /// #[attr] | ||
446 | /// pub static mut FOO: u32 = 42; | ||
447 | /// ❱ | ||
448 | /// ``` | ||
449 | /// | ||
450 | /// [Reference](https://doc.rust-lang.org/reference/items/static-items.html) | ||
221 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 451 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
222 | pub struct StaticDef { | 452 | pub struct StaticDef { |
223 | pub(crate) syntax: SyntaxNode, | 453 | pub(crate) syntax: SyntaxNode, |
@@ -235,7 +465,24 @@ impl StaticDef { | |||
235 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 465 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
236 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 466 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
237 | } | 467 | } |
238 | 468 | /// Type alias definition. | |
469 | /// Includes associated type clauses with type bounds. | ||
470 | /// | ||
471 | /// ``` | ||
472 | /// ❰ | ||
473 | /// /// Docs | ||
474 | /// #[attr] | ||
475 | /// pub type Foo<T> where T: Debug = T; | ||
476 | /// ❱ | ||
477 | /// | ||
478 | /// trait Bar { | ||
479 | /// ❰ type Baz: Debug; ❱ | ||
480 | /// ❰ type Bruh = String; ❱ | ||
481 | /// ❰ type Bruuh: Debug = u32; ❱ | ||
482 | /// } | ||
483 | /// ``` | ||
484 | /// | ||
485 | /// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html) | ||
239 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 486 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
240 | pub struct TypeAliasDef { | 487 | pub struct TypeAliasDef { |
241 | pub(crate) syntax: SyntaxNode, | 488 | pub(crate) syntax: SyntaxNode, |
@@ -253,7 +500,20 @@ impl TypeAliasDef { | |||
253 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 500 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
254 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 501 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
255 | } | 502 | } |
256 | 503 | /// Inherent and trait impl definition. | |
504 | /// Includes all of its inner and outer attributes. | ||
505 | /// | ||
506 | /// ``` | ||
507 | /// ❰ | ||
508 | /// #[attr] | ||
509 | /// unsafe impl<T> const !Foo for Bar where T: Debug { | ||
510 | /// #![inner_attr] | ||
511 | /// // ... | ||
512 | /// } | ||
513 | /// ❱ | ||
514 | /// ``` | ||
515 | /// | ||
516 | /// [Reference](https://doc.rust-lang.org/reference/items/implementations.html) | ||
257 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 517 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
258 | pub struct ImplDef { | 518 | pub struct ImplDef { |
259 | pub(crate) syntax: SyntaxNode, | 519 | pub(crate) syntax: SyntaxNode, |
@@ -270,7 +530,16 @@ impl ImplDef { | |||
270 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | 530 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } |
271 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 531 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } |
272 | } | 532 | } |
273 | 533 | /// Parenthesized type reference. | |
534 | /// Note: parens are only used for grouping, this is not a tuple type. | ||
535 | /// | ||
536 | /// ``` | ||
537 | /// // This is effectively just `u32`. | ||
538 | /// // Single-item tuple must be defined with a trailing comma: `(u32,)` | ||
539 | /// type Foo = ❰ (u32) ❱; | ||
540 | /// | ||
541 | /// let bar: &'static ❰ (dyn Debug) ❱ = "bruh"; | ||
542 | /// ``` | ||
274 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 543 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
275 | pub struct ParenType { | 544 | pub struct ParenType { |
276 | pub(crate) syntax: SyntaxNode, | 545 | pub(crate) syntax: SyntaxNode, |
@@ -280,7 +549,13 @@ impl ParenType { | |||
280 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 549 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
281 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 550 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
282 | } | 551 | } |
283 | 552 | /// Unnamed tuple type. | |
553 | /// | ||
554 | /// ``` | ||
555 | /// let foo: ❰ (u32, bool) ❱ = (42, true); | ||
556 | /// ``` | ||
557 | /// | ||
558 | /// [Reference](https://doc.rust-lang.org/reference/types/tuple.html) | ||
284 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 559 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
285 | pub struct TupleType { | 560 | pub struct TupleType { |
286 | pub(crate) syntax: SyntaxNode, | 561 | pub(crate) syntax: SyntaxNode, |
@@ -290,7 +565,17 @@ impl TupleType { | |||
290 | pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } | 565 | pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } |
291 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 566 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
292 | } | 567 | } |
293 | 568 | /// The never type (i.e. the exclamation point). | |
569 | /// | ||
570 | /// ``` | ||
571 | /// type T = ❰ ! ❱; | ||
572 | /// | ||
573 | /// fn no_return() -> ❰ ! ❱ { | ||
574 | /// loop {} | ||
575 | /// } | ||
576 | /// ``` | ||
577 | /// | ||
578 | /// [Reference](https://doc.rust-lang.org/reference/types/never.html) | ||
294 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 579 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
295 | pub struct NeverType { | 580 | pub struct NeverType { |
296 | pub(crate) syntax: SyntaxNode, | 581 | pub(crate) syntax: SyntaxNode, |
@@ -298,7 +583,17 @@ pub struct NeverType { | |||
298 | impl NeverType { | 583 | impl NeverType { |
299 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | 584 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } |
300 | } | 585 | } |
301 | 586 | /// Path to a type. | |
587 | /// Includes single identifier type names and elaborate paths with | ||
588 | /// generic parameters. | ||
589 | /// | ||
590 | /// ``` | ||
591 | /// type Foo = ❰ String ❱; | ||
592 | /// type Bar = ❰ std::vec::Vec<T> ❱; | ||
593 | /// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱; | ||
594 | /// ``` | ||
595 | /// | ||
596 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
302 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 597 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
303 | pub struct PathType { | 598 | pub struct PathType { |
304 | pub(crate) syntax: SyntaxNode, | 599 | pub(crate) syntax: SyntaxNode, |
@@ -306,7 +601,14 @@ pub struct PathType { | |||
306 | impl PathType { | 601 | impl PathType { |
307 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 602 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
308 | } | 603 | } |
309 | 604 | /// Raw pointer type. | |
605 | /// | ||
606 | /// ``` | ||
607 | /// type Foo = ❰ *const u32 ❱; | ||
608 | /// type Bar = ❰ *mut u32 ❱; | ||
609 | /// ``` | ||
610 | /// | ||
611 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut) | ||
310 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 612 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
311 | pub struct PointerType { | 613 | pub struct PointerType { |
312 | pub(crate) syntax: SyntaxNode, | 614 | pub(crate) syntax: SyntaxNode, |
@@ -317,7 +619,13 @@ impl PointerType { | |||
317 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 619 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
318 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 620 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
319 | } | 621 | } |
320 | 622 | /// Array type. | |
623 | /// | ||
624 | /// ``` | ||
625 | /// type Foo = ❰ [u32; 24 - 3] ❱; | ||
626 | /// ``` | ||
627 | /// | ||
628 | /// [Reference](https://doc.rust-lang.org/reference/types/array.html) | ||
321 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 629 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
322 | pub struct ArrayType { | 630 | pub struct ArrayType { |
323 | pub(crate) syntax: SyntaxNode, | 631 | pub(crate) syntax: SyntaxNode, |
@@ -329,7 +637,13 @@ impl ArrayType { | |||
329 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 637 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
330 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 638 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
331 | } | 639 | } |
332 | 640 | /// Slice type. | |
641 | /// | ||
642 | /// ``` | ||
643 | /// type Foo = ❰ [u8] ❱; | ||
644 | /// ``` | ||
645 | /// | ||
646 | /// [Reference](https://doc.rust-lang.org/reference/types/slice.html) | ||
333 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 647 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
334 | pub struct SliceType { | 648 | pub struct SliceType { |
335 | pub(crate) syntax: SyntaxNode, | 649 | pub(crate) syntax: SyntaxNode, |
@@ -339,7 +653,13 @@ impl SliceType { | |||
339 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 653 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
340 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 654 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
341 | } | 655 | } |
342 | 656 | /// Reference type. | |
657 | /// | ||
658 | /// ``` | ||
659 | /// type Foo = ❰ &'static str ❱; | ||
660 | /// ``` | ||
661 | /// | ||
662 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html) | ||
343 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 663 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
344 | pub struct ReferenceType { | 664 | pub struct ReferenceType { |
345 | pub(crate) syntax: SyntaxNode, | 665 | pub(crate) syntax: SyntaxNode, |
@@ -352,7 +672,13 @@ impl ReferenceType { | |||
352 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 672 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
353 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 673 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
354 | } | 674 | } |
355 | 675 | /// Placeholder type (i.e. the underscore). | |
676 | /// | ||
677 | /// ``` | ||
678 | /// let foo: ❰ _ ❱ = 42_u32; | ||
679 | /// ``` | ||
680 | /// | ||
681 | /// [Reference](https://doc.rust-lang.org/reference/types/inferred.html) | ||
356 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 682 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
357 | pub struct PlaceholderType { | 683 | pub struct PlaceholderType { |
358 | pub(crate) syntax: SyntaxNode, | 684 | pub(crate) syntax: SyntaxNode, |
@@ -360,7 +686,15 @@ pub struct PlaceholderType { | |||
360 | impl PlaceholderType { | 686 | impl PlaceholderType { |
361 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | 687 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } |
362 | } | 688 | } |
363 | 689 | /// Function pointer type (not to be confused with `Fn*` family of traits). | |
690 | /// | ||
691 | /// ``` | ||
692 | /// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱; | ||
693 | /// | ||
694 | /// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱; | ||
695 | /// ``` | ||
696 | /// | ||
697 | /// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html) | ||
364 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 698 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
365 | pub struct FnPointerType { | 699 | pub struct FnPointerType { |
366 | pub(crate) syntax: SyntaxNode, | 700 | pub(crate) syntax: SyntaxNode, |
@@ -372,7 +706,13 @@ impl FnPointerType { | |||
372 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } | 706 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } |
373 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | 707 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } |
374 | } | 708 | } |
375 | 709 | /// Higher order type. | |
710 | /// | ||
711 | /// ``` | ||
712 | /// type Foo = ❰ for<'a> fn(&'a str) ❱; | ||
713 | /// ``` | ||
714 | /// | ||
715 | /// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html) | ||
376 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 716 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
377 | pub struct ForType { | 717 | pub struct ForType { |
378 | pub(crate) syntax: SyntaxNode, | 718 | pub(crate) syntax: SyntaxNode, |
@@ -382,7 +722,13 @@ impl ForType { | |||
382 | pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } | 722 | pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } |
383 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 723 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
384 | } | 724 | } |
385 | 725 | /// Opaque `impl Trait` type. | |
726 | /// | ||
727 | /// ``` | ||
728 | /// fn foo(bar: ❰ impl Debug + Eq ❱) {} | ||
729 | /// ``` | ||
730 | /// | ||
731 | /// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html) | ||
386 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 732 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
387 | pub struct ImplTraitType { | 733 | pub struct ImplTraitType { |
388 | pub(crate) syntax: SyntaxNode, | 734 | pub(crate) syntax: SyntaxNode, |
@@ -391,7 +737,13 @@ impl ast::TypeBoundsOwner for ImplTraitType {} | |||
391 | impl ImplTraitType { | 737 | impl ImplTraitType { |
392 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | 738 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } |
393 | } | 739 | } |
394 | 740 | /// Trait object type. | |
741 | /// | ||
742 | /// ``` | ||
743 | /// type Foo = ❰ dyn Debug ❱; | ||
744 | /// ``` | ||
745 | /// | ||
746 | /// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html) | ||
395 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 747 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
396 | pub struct DynTraitType { | 748 | pub struct DynTraitType { |
397 | pub(crate) syntax: SyntaxNode, | 749 | pub(crate) syntax: SyntaxNode, |
@@ -400,7 +752,13 @@ impl ast::TypeBoundsOwner for DynTraitType {} | |||
400 | impl DynTraitType { | 752 | impl DynTraitType { |
401 | pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } | 753 | pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } |
402 | } | 754 | } |
403 | 755 | /// Tuple literal. | |
756 | /// | ||
757 | /// ``` | ||
758 | /// ❰ (42, true) ❱; | ||
759 | /// ``` | ||
760 | /// | ||
761 | /// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html) | ||
404 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 762 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
405 | pub struct TupleExpr { | 763 | pub struct TupleExpr { |
406 | pub(crate) syntax: SyntaxNode, | 764 | pub(crate) syntax: SyntaxNode, |
@@ -411,7 +769,15 @@ impl TupleExpr { | |||
411 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | 769 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
412 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 770 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
413 | } | 771 | } |
414 | 772 | /// Array literal. | |
773 | /// | ||
774 | /// ``` | ||
775 | /// ❰ [#![inner_attr] true, false, true] ❱; | ||
776 | /// | ||
777 | /// ❰ ["baz"; 24] ❱; | ||
778 | /// ``` | ||
779 | /// | ||
780 | /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) | ||
415 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 781 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
416 | pub struct ArrayExpr { | 782 | pub struct ArrayExpr { |
417 | pub(crate) syntax: SyntaxNode, | 783 | pub(crate) syntax: SyntaxNode, |
@@ -423,7 +789,14 @@ impl ArrayExpr { | |||
423 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 789 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
424 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 790 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
425 | } | 791 | } |
426 | 792 | /// Parenthesized expression. | |
793 | /// Note: parens are only used for grouping, this is not a tuple literal. | ||
794 | /// | ||
795 | /// ``` | ||
796 | /// ❰ (#![inner_attr] 2 + 2) ❱ * 2; | ||
797 | /// ``` | ||
798 | /// | ||
799 | /// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html) | ||
427 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 800 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
428 | pub struct ParenExpr { | 801 | pub struct ParenExpr { |
429 | pub(crate) syntax: SyntaxNode, | 802 | pub(crate) syntax: SyntaxNode, |
@@ -434,7 +807,19 @@ impl ParenExpr { | |||
434 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 807 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
435 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 808 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
436 | } | 809 | } |
437 | 810 | /// Path to a symbol in expression context. | |
811 | /// Includes single identifier variable names and elaborate paths with | ||
812 | /// generic parameters. | ||
813 | /// | ||
814 | /// ``` | ||
815 | /// ❰ Some::<i32> ❱; | ||
816 | /// ❰ foo ❱ + 42; | ||
817 | /// ❰ Vec::<i32>::push ❱; | ||
818 | /// ❰ <[i32]>::reverse ❱; | ||
819 | /// ❰ <String as std::borrow::Borrow<str>>::borrow ❱; | ||
820 | /// ``` | ||
821 | /// | ||
822 | /// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html) | ||
438 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 823 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
439 | pub struct PathExpr { | 824 | pub struct PathExpr { |
440 | pub(crate) syntax: SyntaxNode, | 825 | pub(crate) syntax: SyntaxNode, |
@@ -442,7 +827,17 @@ pub struct PathExpr { | |||
442 | impl PathExpr { | 827 | impl PathExpr { |
443 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 828 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
444 | } | 829 | } |
445 | 830 | /// Anonymous callable object literal a.k.a. closure, lambda or functor. | |
831 | /// | ||
832 | /// ``` | ||
833 | /// ❰ || 42 ❱; | ||
834 | /// ❰ |a: u32| val + 1 ❱; | ||
835 | /// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱; | ||
836 | /// ❰ move || baz ❱; | ||
837 | /// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱ | ||
838 | /// ``` | ||
839 | /// | ||
840 | /// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html) | ||
446 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 841 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
447 | pub struct LambdaExpr { | 842 | pub struct LambdaExpr { |
448 | pub(crate) syntax: SyntaxNode, | 843 | pub(crate) syntax: SyntaxNode, |
@@ -456,7 +851,25 @@ impl LambdaExpr { | |||
456 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | 851 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } |
457 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 852 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
458 | } | 853 | } |
459 | 854 | /// If expression. Includes both regular `if` and `if let` forms. | |
855 | /// Beware that `else if` is a special case syntax sugar, because in general | ||
856 | /// there has to be block expression after `else`. | ||
857 | /// | ||
858 | /// ``` | ||
859 | /// ❰ if bool_cond { 42 } ❱ | ||
860 | /// ❰ if bool_cond { 42 } else { 24 } ❱ | ||
861 | /// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱ | ||
862 | /// | ||
863 | /// ❰ | ||
864 | /// if let Pattern(foo) = bar { | ||
865 | /// foo | ||
866 | /// } else { | ||
867 | /// panic!(); | ||
868 | /// } | ||
869 | /// ❱ | ||
870 | /// ``` | ||
871 | /// | ||
872 | /// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
460 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 873 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
461 | pub struct IfExpr { | 874 | pub struct IfExpr { |
462 | pub(crate) syntax: SyntaxNode, | 875 | pub(crate) syntax: SyntaxNode, |
@@ -466,7 +879,17 @@ impl IfExpr { | |||
466 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | 879 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } |
467 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | 880 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } |
468 | } | 881 | } |
469 | 882 | /// Unconditional loop expression. | |
883 | /// | ||
884 | /// ``` | ||
885 | /// ❰ | ||
886 | /// loop { | ||
887 | /// // yeah, it's that simple... | ||
888 | /// } | ||
889 | /// ❱ | ||
890 | /// ``` | ||
891 | /// | ||
892 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html) | ||
470 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 893 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
471 | pub struct LoopExpr { | 894 | pub struct LoopExpr { |
472 | pub(crate) syntax: SyntaxNode, | 895 | pub(crate) syntax: SyntaxNode, |
@@ -476,7 +899,20 @@ impl ast::LoopBodyOwner for LoopExpr {} | |||
476 | impl LoopExpr { | 899 | impl LoopExpr { |
477 | pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } | 900 | pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } |
478 | } | 901 | } |
479 | 902 | /// Block expression with an optional prefix (label, try ketword, | |
903 | /// unsafe keyword, async keyword...). | ||
904 | /// | ||
905 | /// ``` | ||
906 | /// ❰ | ||
907 | /// 'label: try { | ||
908 | /// None? | ||
909 | /// } | ||
910 | /// ❱ | ||
911 | /// ``` | ||
912 | /// | ||
913 | /// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html) | ||
914 | /// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks) | ||
915 | /// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks) | ||
480 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 916 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
481 | pub struct EffectExpr { | 917 | pub struct EffectExpr { |
482 | pub(crate) syntax: SyntaxNode, | 918 | pub(crate) syntax: SyntaxNode, |
@@ -489,7 +925,19 @@ impl EffectExpr { | |||
489 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } | 925 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } |
490 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 926 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
491 | } | 927 | } |
492 | 928 | /// For loop expression. | |
929 | /// Note: record struct literals are not valid as iterable expression | ||
930 | /// due to ambiguity. | ||
931 | /// | ||
932 | /// ``` | ||
933 | /// ❰ | ||
934 | /// for i in (0..4) { | ||
935 | /// dbg!(i); | ||
936 | /// } | ||
937 | /// ❱ | ||
938 | /// ``` | ||
939 | /// | ||
940 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops) | ||
493 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 941 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
494 | pub struct ForExpr { | 942 | pub struct ForExpr { |
495 | pub(crate) syntax: SyntaxNode, | 943 | pub(crate) syntax: SyntaxNode, |
@@ -502,7 +950,22 @@ impl ForExpr { | |||
502 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } | 950 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } |
503 | pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } | 951 | pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } |
504 | } | 952 | } |
505 | 953 | /// While loop expression. Includes both regular `while` and `while let` forms. | |
954 | /// | ||
955 | /// ``` | ||
956 | /// ❰ | ||
957 | /// while bool_cond { | ||
958 | /// 42; | ||
959 | /// } | ||
960 | /// ❱ | ||
961 | /// ❰ | ||
962 | /// while let Pattern(foo) = bar { | ||
963 | /// bar += 1; | ||
964 | /// } | ||
965 | /// ❱ | ||
966 | /// ``` | ||
967 | /// | ||
968 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
506 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 969 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
507 | pub struct WhileExpr { | 970 | pub struct WhileExpr { |
508 | pub(crate) syntax: SyntaxNode, | 971 | pub(crate) syntax: SyntaxNode, |
@@ -513,7 +976,22 @@ impl WhileExpr { | |||
513 | pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } | 976 | pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } |
514 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | 977 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } |
515 | } | 978 | } |
516 | 979 | /// Continue expression. | |
980 | /// | ||
981 | /// ``` | ||
982 | /// while bool_cond { | ||
983 | /// ❰ continue ❱; | ||
984 | /// } | ||
985 | /// | ||
986 | /// 'outer: loop { | ||
987 | /// loop { | ||
988 | /// ❰ continue 'outer ❱; | ||
989 | /// } | ||
990 | /// } | ||
991 | /// | ||
992 | /// ``` | ||
993 | /// | ||
994 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions) | ||
517 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 995 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
518 | pub struct ContinueExpr { | 996 | pub struct ContinueExpr { |
519 | pub(crate) syntax: SyntaxNode, | 997 | pub(crate) syntax: SyntaxNode, |
@@ -527,7 +1005,25 @@ impl ContinueExpr { | |||
527 | support::token(&self.syntax, T![lifetime]) | 1005 | support::token(&self.syntax, T![lifetime]) |
528 | } | 1006 | } |
529 | } | 1007 | } |
530 | 1008 | /// Break expression. | |
1009 | /// | ||
1010 | /// ``` | ||
1011 | /// while bool_cond { | ||
1012 | /// ❰ break ❱; | ||
1013 | /// } | ||
1014 | /// 'outer: loop { | ||
1015 | /// for foo in bar { | ||
1016 | /// ❰ break 'outer ❱; | ||
1017 | /// } | ||
1018 | /// } | ||
1019 | /// 'outer: loop { | ||
1020 | /// loop { | ||
1021 | /// ❰ break 'outer 42 ❱; | ||
1022 | /// } | ||
1023 | /// } | ||
1024 | /// ``` | ||
1025 | /// | ||
1026 | /// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions) | ||
531 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1027 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
532 | pub struct BreakExpr { | 1028 | pub struct BreakExpr { |
533 | pub(crate) syntax: SyntaxNode, | 1029 | pub(crate) syntax: SyntaxNode, |
@@ -540,7 +1036,20 @@ impl BreakExpr { | |||
540 | } | 1036 | } |
541 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1037 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
542 | } | 1038 | } |
543 | 1039 | /// Label. | |
1040 | /// | ||
1041 | /// ``` | ||
1042 | /// ❰ 'outer: ❱ loop {} | ||
1043 | /// | ||
1044 | /// let foo = ❰ 'bar: ❱ loop {} | ||
1045 | /// | ||
1046 | /// ❰ 'baz: ❱ { | ||
1047 | /// break 'baz; | ||
1048 | /// } | ||
1049 | /// ``` | ||
1050 | /// | ||
1051 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels) | ||
1052 | /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) | ||
544 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1053 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
545 | pub struct Label { | 1054 | pub struct Label { |
546 | pub(crate) syntax: SyntaxNode, | 1055 | pub(crate) syntax: SyntaxNode, |
@@ -550,7 +1059,21 @@ impl Label { | |||
550 | support::token(&self.syntax, T![lifetime]) | 1059 | support::token(&self.syntax, T![lifetime]) |
551 | } | 1060 | } |
552 | } | 1061 | } |
553 | 1062 | /// Block expression. Includes unsafe blocks and block labels. | |
1063 | /// | ||
1064 | /// ``` | ||
1065 | /// let foo = ❰ | ||
1066 | /// { | ||
1067 | /// #![inner_attr] | ||
1068 | /// ❰ { } ❱ | ||
1069 | /// | ||
1070 | /// ❰ 'label: { break 'label } ❱ | ||
1071 | /// } | ||
1072 | /// ❱; | ||
1073 | /// ``` | ||
1074 | /// | ||
1075 | /// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html) | ||
1076 | /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) | ||
554 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1077 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
555 | pub struct BlockExpr { | 1078 | pub struct BlockExpr { |
556 | pub(crate) syntax: SyntaxNode, | 1079 | pub(crate) syntax: SyntaxNode, |
@@ -563,7 +1086,17 @@ impl BlockExpr { | |||
563 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1086 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
564 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 1087 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
565 | } | 1088 | } |
566 | 1089 | /// Return expression. | |
1090 | /// | ||
1091 | /// ``` | ||
1092 | /// || ❰ return 42 ❱; | ||
1093 | /// | ||
1094 | /// fn bar() { | ||
1095 | /// ❰ return ❱; | ||
1096 | /// } | ||
1097 | /// ``` | ||
1098 | /// | ||
1099 | /// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html) | ||
567 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1100 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
568 | pub struct ReturnExpr { | 1101 | pub struct ReturnExpr { |
569 | pub(crate) syntax: SyntaxNode, | 1102 | pub(crate) syntax: SyntaxNode, |
@@ -572,7 +1105,16 @@ impl ast::AttrsOwner for ReturnExpr {} | |||
572 | impl ReturnExpr { | 1105 | impl ReturnExpr { |
573 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1106 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
574 | } | 1107 | } |
575 | 1108 | /// Call expression (not to be confused with method call expression, it is | |
1109 | /// a separate ast node). | ||
1110 | /// | ||
1111 | /// ``` | ||
1112 | /// ❰ foo() ❱; | ||
1113 | /// ❰ &str::len("bar") ❱; | ||
1114 | /// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱; | ||
1115 | /// ``` | ||
1116 | /// | ||
1117 | /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) | ||
576 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1118 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
577 | pub struct CallExpr { | 1119 | pub struct CallExpr { |
578 | pub(crate) syntax: SyntaxNode, | 1120 | pub(crate) syntax: SyntaxNode, |
@@ -581,7 +1123,16 @@ impl ast::ArgListOwner for CallExpr {} | |||
581 | impl CallExpr { | 1123 | impl CallExpr { |
582 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1124 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
583 | } | 1125 | } |
584 | 1126 | /// Method call expression. | |
1127 | /// | ||
1128 | /// ``` | ||
1129 | /// ❰ receiver_expr.method() ❱; | ||
1130 | /// ❰ receiver_expr.method::<T>(42, true) ❱; | ||
1131 | /// | ||
1132 | /// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱; | ||
1133 | /// ``` | ||
1134 | /// | ||
1135 | /// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html) | ||
585 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1136 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
586 | pub struct MethodCallExpr { | 1137 | pub struct MethodCallExpr { |
587 | pub(crate) syntax: SyntaxNode, | 1138 | pub(crate) syntax: SyntaxNode, |
@@ -594,7 +1145,13 @@ impl MethodCallExpr { | |||
594 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 1145 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
595 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } | 1146 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } |
596 | } | 1147 | } |
597 | 1148 | /// Index expression a.k.a. subscript operator call. | |
1149 | /// | ||
1150 | /// ``` | ||
1151 | /// ❰ foo[42] ❱; | ||
1152 | /// ``` | ||
1153 | /// | ||
1154 | /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) | ||
598 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1155 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
599 | pub struct IndexExpr { | 1156 | pub struct IndexExpr { |
600 | pub(crate) syntax: SyntaxNode, | 1157 | pub(crate) syntax: SyntaxNode, |
@@ -604,7 +1161,15 @@ impl IndexExpr { | |||
604 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | 1161 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
605 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 1162 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
606 | } | 1163 | } |
607 | 1164 | /// Field access expression. | |
1165 | /// | ||
1166 | /// ``` | ||
1167 | /// ❰ expr.bar ❱; | ||
1168 | /// | ||
1169 | /// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱; | ||
1170 | /// ``` | ||
1171 | /// | ||
1172 | /// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html) | ||
608 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1173 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
609 | pub struct FieldExpr { | 1174 | pub struct FieldExpr { |
610 | pub(crate) syntax: SyntaxNode, | 1175 | pub(crate) syntax: SyntaxNode, |
@@ -615,7 +1180,13 @@ impl FieldExpr { | |||
615 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | 1180 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } |
616 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 1181 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
617 | } | 1182 | } |
618 | 1183 | /// Await operator call expression. | |
1184 | /// | ||
1185 | /// ``` | ||
1186 | /// ❰ expr.await ❱; | ||
1187 | /// ``` | ||
1188 | /// | ||
1189 | /// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html) | ||
619 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1190 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
620 | pub struct AwaitExpr { | 1191 | pub struct AwaitExpr { |
621 | pub(crate) syntax: SyntaxNode, | 1192 | pub(crate) syntax: SyntaxNode, |
@@ -626,7 +1197,13 @@ impl AwaitExpr { | |||
626 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | 1197 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } |
627 | pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } | 1198 | pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } |
628 | } | 1199 | } |
629 | 1200 | /// The question mark operator call. | |
1201 | /// | ||
1202 | /// ``` | ||
1203 | /// ❰ expr? ❱; | ||
1204 | /// ``` | ||
1205 | /// | ||
1206 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator) | ||
630 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1207 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
631 | pub struct TryExpr { | 1208 | pub struct TryExpr { |
632 | pub(crate) syntax: SyntaxNode, | 1209 | pub(crate) syntax: SyntaxNode, |
@@ -636,7 +1213,13 @@ impl TryExpr { | |||
636 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1213 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
637 | pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } | 1214 | pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } |
638 | } | 1215 | } |
639 | 1216 | /// Type cast expression. | |
1217 | /// | ||
1218 | /// ``` | ||
1219 | /// ❰ expr as T ❱; | ||
1220 | /// ``` | ||
1221 | /// | ||
1222 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions) | ||
640 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1223 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
641 | pub struct CastExpr { | 1224 | pub struct CastExpr { |
642 | pub(crate) syntax: SyntaxNode, | 1225 | pub(crate) syntax: SyntaxNode, |
@@ -647,7 +1230,14 @@ impl CastExpr { | |||
647 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } | 1230 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } |
648 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1231 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
649 | } | 1232 | } |
650 | 1233 | /// Borrow operator call. | |
1234 | /// | ||
1235 | /// ``` | ||
1236 | /// ❰ &foo ❱; | ||
1237 | /// ❰ &mut bar ❱; | ||
1238 | /// ``` | ||
1239 | /// | ||
1240 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators) | ||
651 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1241 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
652 | pub struct RefExpr { | 1242 | pub struct RefExpr { |
653 | pub(crate) syntax: SyntaxNode, | 1243 | pub(crate) syntax: SyntaxNode, |
@@ -659,7 +1249,15 @@ impl RefExpr { | |||
659 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 1249 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
660 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1250 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
661 | } | 1251 | } |
662 | 1252 | /// Prefix operator call. This is either `!` or `*` or `-`. | |
1253 | /// | ||
1254 | /// ``` | ||
1255 | /// ❰ !foo ❱; | ||
1256 | /// ❰ *bar ❱; | ||
1257 | /// ❰ -42 ❱; | ||
1258 | /// ``` | ||
1259 | /// | ||
1260 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html) | ||
663 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1261 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
664 | pub struct PrefixExpr { | 1262 | pub struct PrefixExpr { |
665 | pub(crate) syntax: SyntaxNode, | 1263 | pub(crate) syntax: SyntaxNode, |
@@ -668,7 +1266,13 @@ impl ast::AttrsOwner for PrefixExpr {} | |||
668 | impl PrefixExpr { | 1266 | impl PrefixExpr { |
669 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1267 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
670 | } | 1268 | } |
671 | 1269 | /// Box operator call. | |
1270 | /// | ||
1271 | /// ``` | ||
1272 | /// ❰ box 42 ❱; | ||
1273 | /// ``` | ||
1274 | /// | ||
1275 | /// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md) | ||
672 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1276 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
673 | pub struct BoxExpr { | 1277 | pub struct BoxExpr { |
674 | pub(crate) syntax: SyntaxNode, | 1278 | pub(crate) syntax: SyntaxNode, |
@@ -678,27 +1282,69 @@ impl BoxExpr { | |||
678 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | 1282 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } |
679 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1283 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
680 | } | 1284 | } |
681 | 1285 | /// Range operator call. | |
1286 | /// | ||
1287 | /// ``` | ||
1288 | /// ❰ 0..42 ❱; | ||
1289 | /// ❰ ..42 ❱; | ||
1290 | /// ❰ 0.. ❱; | ||
1291 | /// ❰ .. ❱; | ||
1292 | /// ❰ 0..=42 ❱; | ||
1293 | /// ❰ ..=42 ❱; | ||
1294 | /// ``` | ||
1295 | /// | ||
1296 | /// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html) | ||
682 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1297 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
683 | pub struct RangeExpr { | 1298 | pub struct RangeExpr { |
684 | pub(crate) syntax: SyntaxNode, | 1299 | pub(crate) syntax: SyntaxNode, |
685 | } | 1300 | } |
686 | impl ast::AttrsOwner for RangeExpr {} | 1301 | impl ast::AttrsOwner for RangeExpr {} |
687 | impl RangeExpr {} | 1302 | impl RangeExpr {} |
688 | 1303 | /// Binary operator call. | |
1304 | /// Includes all arithmetic, logic, bitwise and assignment operators. | ||
1305 | /// | ||
1306 | /// ``` | ||
1307 | /// ❰ 2 + ❰ 2 * 2 ❱ ❱; | ||
1308 | /// ❰ ❰ true && false ❱ || true ❱; | ||
1309 | /// ``` | ||
1310 | /// | ||
1311 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators) | ||
689 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1312 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
690 | pub struct BinExpr { | 1313 | pub struct BinExpr { |
691 | pub(crate) syntax: SyntaxNode, | 1314 | pub(crate) syntax: SyntaxNode, |
692 | } | 1315 | } |
693 | impl ast::AttrsOwner for BinExpr {} | 1316 | impl ast::AttrsOwner for BinExpr {} |
694 | impl BinExpr {} | 1317 | impl BinExpr {} |
695 | 1318 | /// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal. | |
1319 | /// | ||
1320 | /// ``` | ||
1321 | /// ❰ "str" ❱; | ||
1322 | /// ❰ br##"raw byte str"## ❱; | ||
1323 | /// ❰ 'c' ❱; | ||
1324 | /// ❰ b'c' ❱; | ||
1325 | /// ❰ 42 ❱; | ||
1326 | /// ❰ 1e9 ❱; | ||
1327 | /// ❰ true ❱; | ||
1328 | /// ``` | ||
1329 | /// | ||
1330 | /// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html) | ||
696 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1331 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
697 | pub struct Literal { | 1332 | pub struct Literal { |
698 | pub(crate) syntax: SyntaxNode, | 1333 | pub(crate) syntax: SyntaxNode, |
699 | } | 1334 | } |
700 | impl Literal {} | 1335 | impl Literal {} |
701 | 1336 | /// Match expression. | |
1337 | /// | ||
1338 | /// ``` | ||
1339 | /// ❰ | ||
1340 | /// match expr { | ||
1341 | /// Pat1 => {} | ||
1342 | /// Pat2(_) => 42, | ||
1343 | /// } | ||
1344 | /// ❱ | ||
1345 | /// ``` | ||
1346 | /// | ||
1347 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
702 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1348 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
703 | pub struct MatchExpr { | 1349 | pub struct MatchExpr { |
704 | pub(crate) syntax: SyntaxNode, | 1350 | pub(crate) syntax: SyntaxNode, |
@@ -709,7 +1355,20 @@ impl MatchExpr { | |||
709 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1355 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
710 | pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } | 1356 | pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } |
711 | } | 1357 | } |
712 | 1358 | /// Match arm list part of match expression. Includes its inner attributes. | |
1359 | /// | ||
1360 | /// ``` | ||
1361 | /// match expr | ||
1362 | /// ❰ | ||
1363 | /// { | ||
1364 | /// #![inner_attr] | ||
1365 | /// Pat1 => {} | ||
1366 | /// Pat2(_) => 42, | ||
1367 | /// } | ||
1368 | /// ❱ | ||
1369 | /// ``` | ||
1370 | /// | ||
1371 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
713 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1372 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
714 | pub struct MatchArmList { | 1373 | pub struct MatchArmList { |
715 | pub(crate) syntax: SyntaxNode, | 1374 | pub(crate) syntax: SyntaxNode, |
@@ -720,7 +1379,16 @@ impl MatchArmList { | |||
720 | pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } | 1379 | pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } |
721 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 1380 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
722 | } | 1381 | } |
723 | 1382 | /// Match arm. | |
1383 | /// Note: record struct literals are not valid as target match expression | ||
1384 | /// due to ambiguity. | ||
1385 | /// ``` | ||
1386 | /// match expr { | ||
1387 | /// ❰ #[attr] Pattern(it) if bool_cond => it ❱, | ||
1388 | /// } | ||
1389 | /// ``` | ||
1390 | /// | ||
1391 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
724 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1392 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
725 | pub struct MatchArm { | 1393 | pub struct MatchArm { |
726 | pub(crate) syntax: SyntaxNode, | 1394 | pub(crate) syntax: SyntaxNode, |
@@ -732,7 +1400,15 @@ impl MatchArm { | |||
732 | pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } | 1400 | pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } |
733 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1401 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
734 | } | 1402 | } |
735 | 1403 | /// Match guard. | |
1404 | /// | ||
1405 | /// ``` | ||
1406 | /// match expr { | ||
1407 | /// Pattern(it) ❰ if bool_cond ❱ => it, | ||
1408 | /// } | ||
1409 | /// ``` | ||
1410 | /// | ||
1411 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards) | ||
736 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1412 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
737 | pub struct MatchGuard { | 1413 | pub struct MatchGuard { |
738 | pub(crate) syntax: SyntaxNode, | 1414 | pub(crate) syntax: SyntaxNode, |
@@ -741,7 +1417,21 @@ impl MatchGuard { | |||
741 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | 1417 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } |
742 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1418 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
743 | } | 1419 | } |
744 | 1420 | /// Record literal expression. The same syntax is used for structs, | |
1421 | /// unions and record enum variants. | ||
1422 | /// | ||
1423 | /// ``` | ||
1424 | /// ❰ | ||
1425 | /// foo::Bar { | ||
1426 | /// #![inner_attr] | ||
1427 | /// baz: 42, | ||
1428 | /// bruh: true, | ||
1429 | /// ..spread | ||
1430 | /// } | ||
1431 | /// ❱ | ||
1432 | /// ``` | ||
1433 | /// | ||
1434 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
745 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1435 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
746 | pub struct RecordLit { | 1436 | pub struct RecordLit { |
747 | pub(crate) syntax: SyntaxNode, | 1437 | pub(crate) syntax: SyntaxNode, |
@@ -750,7 +1440,16 @@ impl RecordLit { | |||
750 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 1440 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
751 | pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } | 1441 | pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } |
752 | } | 1442 | } |
753 | 1443 | /// Record field list including enclosing curly braces. | |
1444 | /// | ||
1445 | /// foo::Bar ❰ | ||
1446 | /// { | ||
1447 | /// baz: 42, | ||
1448 | /// ..spread | ||
1449 | /// } | ||
1450 | /// ❱ | ||
1451 | /// | ||
1452 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
754 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1453 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
755 | pub struct RecordFieldList { | 1454 | pub struct RecordFieldList { |
756 | pub(crate) syntax: SyntaxNode, | 1455 | pub(crate) syntax: SyntaxNode, |
@@ -762,7 +1461,15 @@ impl RecordFieldList { | |||
762 | pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } | 1461 | pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } |
763 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 1462 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
764 | } | 1463 | } |
765 | 1464 | /// Record field. | |
1465 | /// | ||
1466 | /// ``` | ||
1467 | /// foo::Bar { | ||
1468 | /// ❰ #[attr] baz: 42 ❱ | ||
1469 | /// } | ||
1470 | /// ``` | ||
1471 | /// | ||
1472 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
766 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1473 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
767 | pub struct RecordField { | 1474 | pub struct RecordField { |
768 | pub(crate) syntax: SyntaxNode, | 1475 | pub(crate) syntax: SyntaxNode, |
@@ -773,7 +1480,13 @@ impl RecordField { | |||
773 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | 1480 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
774 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1481 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
775 | } | 1482 | } |
776 | 1483 | /// Disjunction of patterns. | |
1484 | /// | ||
1485 | /// ``` | ||
1486 | /// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh; | ||
1487 | /// ``` | ||
1488 | /// | ||
1489 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html) | ||
777 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1490 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
778 | pub struct OrPat { | 1491 | pub struct OrPat { |
779 | pub(crate) syntax: SyntaxNode, | 1492 | pub(crate) syntax: SyntaxNode, |
@@ -781,7 +1494,14 @@ pub struct OrPat { | |||
781 | impl OrPat { | 1494 | impl OrPat { |
782 | pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1495 | pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
783 | } | 1496 | } |
784 | 1497 | /// Parenthesized pattern. | |
1498 | /// Note: parens are only used for grouping, this is not a tuple pattern. | ||
1499 | /// | ||
1500 | /// ``` | ||
1501 | /// if let ❰ &(0..=42) ❱ = foo {} | ||
1502 | /// ``` | ||
1503 | /// | ||
1504 | /// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns | ||
785 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1505 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
786 | pub struct ParenPat { | 1506 | pub struct ParenPat { |
787 | pub(crate) syntax: SyntaxNode, | 1507 | pub(crate) syntax: SyntaxNode, |
@@ -791,7 +1511,16 @@ impl ParenPat { | |||
791 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1511 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
792 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 1512 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
793 | } | 1513 | } |
794 | 1514 | /// Reference pattern. | |
1515 | /// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns. | ||
1516 | /// | ||
1517 | /// ``` | ||
1518 | /// let ❰ &mut foo ❱ = bar; | ||
1519 | /// | ||
1520 | /// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz; | ||
1521 | /// ``` | ||
1522 | /// | ||
1523 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns) | ||
795 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1524 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
796 | pub struct RefPat { | 1525 | pub struct RefPat { |
797 | pub(crate) syntax: SyntaxNode, | 1526 | pub(crate) syntax: SyntaxNode, |
@@ -801,7 +1530,13 @@ impl RefPat { | |||
801 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 1530 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
802 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1531 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
803 | } | 1532 | } |
804 | 1533 | /// Box pattern. | |
1534 | /// | ||
1535 | /// ``` | ||
1536 | /// let ❰ box foo ❱ = box 42; | ||
1537 | /// ``` | ||
1538 | /// | ||
1539 | /// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html) | ||
805 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1540 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
806 | pub struct BoxPat { | 1541 | pub struct BoxPat { |
807 | pub(crate) syntax: SyntaxNode, | 1542 | pub(crate) syntax: SyntaxNode, |
@@ -810,7 +1545,16 @@ impl BoxPat { | |||
810 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | 1545 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } |
811 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1546 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
812 | } | 1547 | } |
813 | 1548 | /// Bind pattern. | |
1549 | /// | ||
1550 | /// ``` | ||
1551 | /// match foo { | ||
1552 | /// Some(❰ ref mut bar ❱) => {} | ||
1553 | /// ❰ baz @ None ❱ => {} | ||
1554 | /// } | ||
1555 | /// ``` | ||
1556 | /// | ||
1557 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns) | ||
814 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1558 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
815 | pub struct BindPat { | 1559 | pub struct BindPat { |
816 | pub(crate) syntax: SyntaxNode, | 1560 | pub(crate) syntax: SyntaxNode, |
@@ -823,7 +1567,13 @@ impl BindPat { | |||
823 | pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } | 1567 | pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } |
824 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1568 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
825 | } | 1569 | } |
826 | 1570 | /// Placeholder pattern a.k.a. the wildcard pattern or the underscore. | |
1571 | /// | ||
1572 | /// ``` | ||
1573 | /// let ❰ _ ❱ = foo; | ||
1574 | /// ``` | ||
1575 | /// | ||
1576 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern) | ||
827 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1577 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
828 | pub struct PlaceholderPat { | 1578 | pub struct PlaceholderPat { |
829 | pub(crate) syntax: SyntaxNode, | 1579 | pub(crate) syntax: SyntaxNode, |
@@ -831,7 +1581,16 @@ pub struct PlaceholderPat { | |||
831 | impl PlaceholderPat { | 1581 | impl PlaceholderPat { |
832 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | 1582 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } |
833 | } | 1583 | } |
834 | 1584 | /// Rest-of-the record/tuple pattern. | |
1585 | /// Note: this is not the unbonded range pattern (even more: it doesn't exist). | ||
1586 | /// | ||
1587 | /// ``` | ||
1588 | /// let Foo { bar, ❰ .. ❱ } = baz; | ||
1589 | /// let (❰ .. ❱, bruh) = (42, 24, 42); | ||
1590 | /// let Bruuh(❰ .. ❱) = bruuuh; | ||
1591 | /// ``` | ||
1592 | /// | ||
1593 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
835 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1594 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
836 | pub struct DotDotPat { | 1595 | pub struct DotDotPat { |
837 | pub(crate) syntax: SyntaxNode, | 1596 | pub(crate) syntax: SyntaxNode, |
@@ -839,7 +1598,15 @@ pub struct DotDotPat { | |||
839 | impl DotDotPat { | 1598 | impl DotDotPat { |
840 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | 1599 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
841 | } | 1600 | } |
842 | 1601 | /// Path pattern. | |
1602 | /// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`). | ||
1603 | /// | ||
1604 | /// ``` | ||
1605 | /// let ❰ foo::bar::Baz ❱ { .. } = bruh; | ||
1606 | /// if let ❰ CONST ❱ = 42 {} | ||
1607 | /// ``` | ||
1608 | /// | ||
1609 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns) | ||
843 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1610 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
844 | pub struct PathPat { | 1611 | pub struct PathPat { |
845 | pub(crate) syntax: SyntaxNode, | 1612 | pub(crate) syntax: SyntaxNode, |
@@ -847,7 +1614,13 @@ pub struct PathPat { | |||
847 | impl PathPat { | 1614 | impl PathPat { |
848 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 1615 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
849 | } | 1616 | } |
850 | 1617 | /// Slice pattern. | |
1618 | /// | ||
1619 | /// ``` | ||
1620 | /// let ❰ [foo, bar, baz] ❱ = [1, 2, 3]; | ||
1621 | /// ``` | ||
1622 | /// | ||
1623 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns) | ||
851 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1624 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
852 | pub struct SlicePat { | 1625 | pub struct SlicePat { |
853 | pub(crate) syntax: SyntaxNode, | 1626 | pub(crate) syntax: SyntaxNode, |
@@ -857,13 +1630,33 @@ impl SlicePat { | |||
857 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1630 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
858 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 1631 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
859 | } | 1632 | } |
860 | 1633 | /// Range pattern. | |
1634 | /// | ||
1635 | /// ``` | ||
1636 | /// match foo { | ||
1637 | /// ❰ 0..42 ❱ => {} | ||
1638 | /// ❰ 0..=42 ❱ => {} | ||
1639 | /// } | ||
1640 | /// ``` | ||
1641 | /// | ||
1642 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns) | ||
861 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1643 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
862 | pub struct RangePat { | 1644 | pub struct RangePat { |
863 | pub(crate) syntax: SyntaxNode, | 1645 | pub(crate) syntax: SyntaxNode, |
864 | } | 1646 | } |
865 | impl RangePat {} | 1647 | impl RangePat {} |
866 | 1648 | /// Literal pattern. | |
1649 | /// Includes only bool, number, char, and string literals. | ||
1650 | /// | ||
1651 | /// ``` | ||
1652 | /// match foo { | ||
1653 | /// Number(❰ 42 ❱) => {} | ||
1654 | /// String(❰ "42" ❱) => {} | ||
1655 | /// Bool(❰ true ❱) => {} | ||
1656 | /// } | ||
1657 | /// ``` | ||
1658 | /// | ||
1659 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns) | ||
867 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1660 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
868 | pub struct LiteralPat { | 1661 | pub struct LiteralPat { |
869 | pub(crate) syntax: SyntaxNode, | 1662 | pub(crate) syntax: SyntaxNode, |
@@ -871,7 +1664,13 @@ pub struct LiteralPat { | |||
871 | impl LiteralPat { | 1664 | impl LiteralPat { |
872 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | 1665 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } |
873 | } | 1666 | } |
874 | 1667 | /// Macro invocation in pattern position. | |
1668 | /// | ||
1669 | /// ``` | ||
1670 | /// let ❰ foo!(my custom syntax) ❱ = baz; | ||
1671 | /// | ||
1672 | /// ``` | ||
1673 | /// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation) | ||
875 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1674 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
876 | pub struct MacroPat { | 1675 | pub struct MacroPat { |
877 | pub(crate) syntax: SyntaxNode, | 1676 | pub(crate) syntax: SyntaxNode, |
@@ -879,7 +1678,13 @@ pub struct MacroPat { | |||
879 | impl MacroPat { | 1678 | impl MacroPat { |
880 | pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } | 1679 | pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } |
881 | } | 1680 | } |
882 | 1681 | /// Record literal pattern. | |
1682 | /// | ||
1683 | /// ``` | ||
1684 | /// let ❰ foo::Bar { baz, .. } ❱ = bruh; | ||
1685 | /// ``` | ||
1686 | /// | ||
1687 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
883 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1688 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
884 | pub struct RecordPat { | 1689 | pub struct RecordPat { |
885 | pub(crate) syntax: SyntaxNode, | 1690 | pub(crate) syntax: SyntaxNode, |
@@ -890,7 +1695,13 @@ impl RecordPat { | |||
890 | } | 1695 | } |
891 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 1696 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
892 | } | 1697 | } |
893 | 1698 | /// Record literal's field patterns list including enclosing curly braces. | |
1699 | /// | ||
1700 | /// ``` | ||
1701 | /// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh; | ||
1702 | /// `` | ||
1703 | /// | ||
1704 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
894 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1705 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
895 | pub struct RecordFieldPatList { | 1706 | pub struct RecordFieldPatList { |
896 | pub(crate) syntax: SyntaxNode, | 1707 | pub(crate) syntax: SyntaxNode, |
@@ -905,7 +1716,15 @@ impl RecordFieldPatList { | |||
905 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | 1716 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
906 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 1717 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
907 | } | 1718 | } |
908 | 1719 | /// Record literal's field pattern. | |
1720 | /// Note: record literal can also match tuple structs. | ||
1721 | /// | ||
1722 | /// ``` | ||
1723 | /// let Foo { ❰ bar: _ ❱ } = baz; | ||
1724 | /// let TupleStruct { ❰ 0: _ ❱ } = bruh; | ||
1725 | /// ``` | ||
1726 | /// | ||
1727 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
909 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1728 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
910 | pub struct RecordFieldPat { | 1729 | pub struct RecordFieldPat { |
911 | pub(crate) syntax: SyntaxNode, | 1730 | pub(crate) syntax: SyntaxNode, |
@@ -916,7 +1735,13 @@ impl RecordFieldPat { | |||
916 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | 1735 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
917 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1736 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
918 | } | 1737 | } |
919 | 1738 | /// Tuple struct literal pattern. | |
1739 | /// | ||
1740 | /// ``` | ||
1741 | /// let ❰ foo::Bar(baz, bruh) ❱ = bruuh; | ||
1742 | /// ``` | ||
1743 | /// | ||
1744 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns) | ||
920 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1745 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
921 | pub struct TupleStructPat { | 1746 | pub struct TupleStructPat { |
922 | pub(crate) syntax: SyntaxNode, | 1747 | pub(crate) syntax: SyntaxNode, |
@@ -927,7 +1752,14 @@ impl TupleStructPat { | |||
927 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1752 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
928 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 1753 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
929 | } | 1754 | } |
930 | 1755 | /// Tuple pattern. | |
1756 | /// Note: this doesn't include tuple structs (see `TupleStructPat`) | ||
1757 | /// | ||
1758 | /// ``` | ||
1759 | /// let ❰ (foo, bar, .., baz) ❱ = bruh; | ||
1760 | /// ``` | ||
1761 | /// | ||
1762 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns) | ||
931 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1763 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
932 | pub struct TuplePat { | 1764 | pub struct TuplePat { |
933 | pub(crate) syntax: SyntaxNode, | 1765 | pub(crate) syntax: SyntaxNode, |
@@ -937,7 +1769,17 @@ impl TuplePat { | |||
937 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1769 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
938 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 1770 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
939 | } | 1771 | } |
940 | 1772 | /// Visibility. | |
1773 | /// | ||
1774 | /// ``` | ||
1775 | /// ❰ pub mod ❱ foo; | ||
1776 | /// ❰ pub(crate) ❱ struct Bar; | ||
1777 | /// ❰ pub(self) ❱ enum Baz {} | ||
1778 | /// ❰ pub(super) ❱ fn bruh() {} | ||
1779 | /// ❰ pub(in bruuh::bruuuh) ❱ type T = u64; | ||
1780 | /// ``` | ||
1781 | /// | ||
1782 | /// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html) | ||
941 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1783 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
942 | pub struct Visibility { | 1784 | pub struct Visibility { |
943 | pub(crate) syntax: SyntaxNode, | 1785 | pub(crate) syntax: SyntaxNode, |
@@ -948,7 +1790,29 @@ impl Visibility { | |||
948 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | 1790 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } |
949 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | 1791 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } |
950 | } | 1792 | } |
951 | 1793 | /// Single identifier. | |
1794 | /// Note(@matklad): `Name` is for things that install a new name into the scope, | ||
1795 | /// `NameRef` is a usage of a name. Most of the time, this definition/reference | ||
1796 | /// distinction can be determined purely syntactically, ie in | ||
1797 | /// ``` | ||
1798 | /// fn foo() { foo() } | ||
1799 | /// ``` | ||
1800 | /// the first foo is `Name`, the second one is `NameRef`. | ||
1801 | /// The notable exception are patterns, where in | ||
1802 | /// `` | ||
1803 | /// let x = 92 | ||
1804 | /// ``` | ||
1805 | /// `x` can be semantically either a name or a name ref, depeding on | ||
1806 | /// wether there's an `x` constant in scope. | ||
1807 | /// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db). | ||
1808 | /// | ||
1809 | /// ``` | ||
1810 | /// let ❰ foo ❱ = bar; | ||
1811 | /// struct ❰ Baz ❱; | ||
1812 | /// fn ❰ bruh ❱() {} | ||
1813 | /// ``` | ||
1814 | /// | ||
1815 | /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) | ||
952 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1816 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
953 | pub struct Name { | 1817 | pub struct Name { |
954 | pub(crate) syntax: SyntaxNode, | 1818 | pub(crate) syntax: SyntaxNode, |
@@ -956,13 +1820,41 @@ pub struct Name { | |||
956 | impl Name { | 1820 | impl Name { |
957 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } | 1821 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } |
958 | } | 1822 | } |
959 | 1823 | /// Reference to a name. | |
1824 | /// See the explanation on the difference between `Name` and `NameRef` | ||
1825 | /// in `Name` ast node docs. | ||
1826 | /// | ||
1827 | /// ``` | ||
1828 | /// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱; | ||
1829 | /// ``` | ||
1830 | /// | ||
1831 | /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) | ||
960 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1832 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
961 | pub struct NameRef { | 1833 | pub struct NameRef { |
962 | pub(crate) syntax: SyntaxNode, | 1834 | pub(crate) syntax: SyntaxNode, |
963 | } | 1835 | } |
964 | impl NameRef {} | 1836 | impl NameRef {} |
965 | 1837 | /// Macro call. | |
1838 | /// Includes all of its attributes and doc comments. | ||
1839 | /// | ||
1840 | /// ``` | ||
1841 | /// ❰ | ||
1842 | /// /// Docs | ||
1843 | /// #[attr] | ||
1844 | /// macro_rules! foo { // macro rules is also a macro call | ||
1845 | /// ($bar: tt) => {} | ||
1846 | /// } | ||
1847 | /// ❱ | ||
1848 | /// | ||
1849 | /// // semicolon is a part of `MacroCall` when it is used in item positions | ||
1850 | /// ❰ foo!(); ❱ | ||
1851 | /// | ||
1852 | /// fn main() { | ||
1853 | /// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi | ||
1854 | /// } | ||
1855 | /// ``` | ||
1856 | /// | ||
1857 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
966 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1858 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
967 | pub struct MacroCall { | 1859 | pub struct MacroCall { |
968 | pub(crate) syntax: SyntaxNode, | 1860 | pub(crate) syntax: SyntaxNode, |
@@ -976,7 +1868,18 @@ impl MacroCall { | |||
976 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | 1868 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } |
977 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 1869 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
978 | } | 1870 | } |
979 | 1871 | /// Attribute. | |
1872 | /// | ||
1873 | /// ``` | ||
1874 | /// ❰ #![inner_attr] ❱ | ||
1875 | /// | ||
1876 | /// ❰ #[attr] ❱ | ||
1877 | /// ❰ #[foo = "bar"] ❱ | ||
1878 | /// ❰ #[baz(bruh::bruuh = "42")] ❱ | ||
1879 | /// struct Foo; | ||
1880 | /// ``` | ||
1881 | /// | ||
1882 | /// [Reference](https://doc.rust-lang.org/reference/attributes.html) | ||
980 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1883 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
981 | pub struct Attr { | 1884 | pub struct Attr { |
982 | pub(crate) syntax: SyntaxNode, | 1885 | pub(crate) syntax: SyntaxNode, |
@@ -990,13 +1893,32 @@ impl Attr { | |||
990 | pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) } | 1893 | pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) } |
991 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 1894 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
992 | } | 1895 | } |
993 | 1896 | /// Stores a list of lexer tokens and other `TokenTree`s. | |
1897 | /// It appears in attributes, macro_rules and macro call (foo!) | ||
1898 | /// | ||
1899 | /// ``` | ||
1900 | /// macro_call! ❰ { my syntax here } ❱; | ||
1901 | /// ``` | ||
1902 | /// | ||
1903 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
994 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1904 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
995 | pub struct TokenTree { | 1905 | pub struct TokenTree { |
996 | pub(crate) syntax: SyntaxNode, | 1906 | pub(crate) syntax: SyntaxNode, |
997 | } | 1907 | } |
998 | impl TokenTree {} | 1908 | impl TokenTree {} |
999 | 1909 | /// Generic lifetime, type and constants parameters list **declaration**. | |
1910 | /// | ||
1911 | /// ``` | ||
1912 | /// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {} | ||
1913 | /// | ||
1914 | /// struct Baz❰ <T> ❱(T); | ||
1915 | /// | ||
1916 | /// impl❰ <T> ❱ Bruh<T> {} | ||
1917 | /// | ||
1918 | /// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str; | ||
1919 | /// ``` | ||
1920 | /// | ||
1921 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
1000 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1922 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1001 | pub struct TypeParamList { | 1923 | pub struct TypeParamList { |
1002 | pub(crate) syntax: SyntaxNode, | 1924 | pub(crate) syntax: SyntaxNode, |
@@ -1009,7 +1931,13 @@ impl TypeParamList { | |||
1009 | pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) } | 1931 | pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) } |
1010 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | 1932 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } |
1011 | } | 1933 | } |
1012 | 1934 | /// Single type parameter **declaration**. | |
1935 | /// | ||
1936 | /// ``` | ||
1937 | /// fn foo<❰ K ❱, ❰ I ❱, ❰ E: Debug ❱, ❰ V = DefaultType ❱>() {} | ||
1938 | /// ``` | ||
1939 | /// | ||
1940 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
1013 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1941 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1014 | pub struct TypeParam { | 1942 | pub struct TypeParam { |
1015 | pub(crate) syntax: SyntaxNode, | 1943 | pub(crate) syntax: SyntaxNode, |
@@ -1021,7 +1949,12 @@ impl TypeParam { | |||
1021 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 1949 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
1022 | pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1950 | pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1023 | } | 1951 | } |
1024 | 1952 | /// Const generic parameter **declaration**. | |
1953 | /// ``` | ||
1954 | /// fn foo<T, U, ❰ const BAR: usize ❱, ❰ const BAZ: bool ❱>() {} | ||
1955 | /// ``` | ||
1956 | /// | ||
1957 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) | ||
1025 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1958 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1026 | pub struct ConstParam { | 1959 | pub struct ConstParam { |
1027 | pub(crate) syntax: SyntaxNode, | 1960 | pub(crate) syntax: SyntaxNode, |
@@ -1033,7 +1966,13 @@ impl ConstParam { | |||
1033 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 1966 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
1034 | pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } | 1967 | pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } |
1035 | } | 1968 | } |
1036 | 1969 | /// Lifetime parameter **declaration**. | |
1970 | /// | ||
1971 | /// ``` | ||
1972 | /// fn foo<❰ 'a ❱, ❰ 'b ❱, V, G, D>(bar: &'a str, baz: &'b mut str) {} | ||
1973 | /// ``` | ||
1974 | /// | ||
1975 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
1037 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1976 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1038 | pub struct LifetimeParam { | 1977 | pub struct LifetimeParam { |
1039 | pub(crate) syntax: SyntaxNode, | 1978 | pub(crate) syntax: SyntaxNode, |
@@ -1044,7 +1983,20 @@ impl LifetimeParam { | |||
1044 | support::token(&self.syntax, T![lifetime]) | 1983 | support::token(&self.syntax, T![lifetime]) |
1045 | } | 1984 | } |
1046 | } | 1985 | } |
1047 | 1986 | /// Type bound declaration clause. | |
1987 | /// | ||
1988 | /// ``` | ||
1989 | /// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {} | ||
1990 | /// | ||
1991 | /// trait Bar<T> | ||
1992 | /// where | ||
1993 | /// T: ❰ Send ❱ + ❰ Sync ❱ | ||
1994 | /// { | ||
1995 | /// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱; | ||
1996 | /// } | ||
1997 | /// ``` | ||
1998 | /// | ||
1999 | /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) | ||
1048 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2000 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1049 | pub struct TypeBound { | 2001 | pub struct TypeBound { |
1050 | pub(crate) syntax: SyntaxNode, | 2002 | pub(crate) syntax: SyntaxNode, |
@@ -1056,7 +2008,21 @@ impl TypeBound { | |||
1056 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 2008 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
1057 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 2009 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1058 | } | 2010 | } |
1059 | 2011 | /// Type bounds list. | |
2012 | /// | ||
2013 | /// ``` | ||
2014 | /// | ||
2015 | /// fn foo<T: ❰ ?Sized + Debug ❱>() {} | ||
2016 | /// | ||
2017 | /// trait Bar<T> | ||
2018 | /// where | ||
2019 | /// T: ❰ Send + Sync ❱ | ||
2020 | /// { | ||
2021 | /// type Baz: ❰ !Sync + Debug ❱; | ||
2022 | /// } | ||
2023 | /// ``` | ||
2024 | /// | ||
2025 | /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) | ||
1060 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2026 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1061 | pub struct TypeBoundList { | 2027 | pub struct TypeBoundList { |
1062 | pub(crate) syntax: SyntaxNode, | 2028 | pub(crate) syntax: SyntaxNode, |
@@ -1064,7 +2030,18 @@ pub struct TypeBoundList { | |||
1064 | impl TypeBoundList { | 2030 | impl TypeBoundList { |
1065 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } | 2031 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } |
1066 | } | 2032 | } |
1067 | 2033 | /// Single where predicate. | |
2034 | /// | ||
2035 | /// ``` | ||
2036 | /// trait Foo<'a, 'b, T> | ||
2037 | /// where | ||
2038 | /// ❰ 'a: 'b ❱, | ||
2039 | /// ❰ T: IntoIterator ❱, | ||
2040 | /// ❰ for<'c> <T as IntoIterator>::Item: Bar<'c> ❱ | ||
2041 | /// {} | ||
2042 | /// ``` | ||
2043 | /// | ||
2044 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) | ||
1068 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2045 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1069 | pub struct WherePred { | 2046 | pub struct WherePred { |
1070 | pub(crate) syntax: SyntaxNode, | 2047 | pub(crate) syntax: SyntaxNode, |
@@ -1076,7 +2053,14 @@ impl WherePred { | |||
1076 | } | 2053 | } |
1077 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 2054 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1078 | } | 2055 | } |
1079 | 2056 | /// Where clause. | |
2057 | /// | ||
2058 | /// ``` | ||
2059 | /// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {} | ||
2060 | /// | ||
2061 | /// ``` | ||
2062 | /// | ||
2063 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) | ||
1080 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2064 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1081 | pub struct WhereClause { | 2065 | pub struct WhereClause { |
1082 | pub(crate) syntax: SyntaxNode, | 2066 | pub(crate) syntax: SyntaxNode, |
@@ -1085,13 +2069,42 @@ impl WhereClause { | |||
1085 | pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } | 2069 | pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } |
1086 | pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } | 2070 | pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } |
1087 | } | 2071 | } |
1088 | 2072 | /// Abi declaration. | |
2073 | /// Note: the abi string is optional. | ||
2074 | /// | ||
2075 | /// ``` | ||
2076 | /// ❰ extern "C" ❱ { | ||
2077 | /// fn foo() {} | ||
2078 | /// } | ||
2079 | /// | ||
2080 | /// type Bar = ❰ extern ❱ fn() -> u32; | ||
2081 | /// | ||
2082 | /// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool; | ||
2083 | /// ``` | ||
2084 | /// | ||
2085 | /// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
2086 | /// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions) | ||
1089 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2087 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1090 | pub struct Abi { | 2088 | pub struct Abi { |
1091 | pub(crate) syntax: SyntaxNode, | 2089 | pub(crate) syntax: SyntaxNode, |
1092 | } | 2090 | } |
1093 | impl Abi {} | 2091 | impl Abi {} |
1094 | 2092 | /// Expression statement. | |
2093 | /// | ||
2094 | /// ``` | ||
2095 | /// ❰ 42; ❱ | ||
2096 | /// ❰ foo(); ❱ | ||
2097 | /// ❰ (); ❱ | ||
2098 | /// ❰ {}; ❱ | ||
2099 | /// | ||
2100 | /// // constructions with trailing curly brace can omit the semicolon | ||
2101 | /// // but only when there are satements immediately after them (this is important!) | ||
2102 | /// ❰ if bool_cond { } ❱ | ||
2103 | /// ❰ loop {} ❱ | ||
2104 | /// ❰ somestatment; ❱ | ||
2105 | /// ``` | ||
2106 | /// | ||
2107 | /// [Reference](https://doc.rust-lang.org/reference/statements.html) | ||
1095 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2108 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1096 | pub struct ExprStmt { | 2109 | pub struct ExprStmt { |
1097 | pub(crate) syntax: SyntaxNode, | 2110 | pub(crate) syntax: SyntaxNode, |
@@ -1101,7 +2114,16 @@ impl ExprStmt { | |||
1101 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 2114 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1102 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 2115 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
1103 | } | 2116 | } |
1104 | 2117 | /// Let statement. | |
2118 | /// | ||
2119 | /// ``` | ||
2120 | /// ❰ #[attr] let foo; ❱ | ||
2121 | /// ❰ let bar: u64; ❱ | ||
2122 | /// ❰ let baz = 42; ❱ | ||
2123 | /// ❰ let bruh: bool = true; ❱ | ||
2124 | /// ``` | ||
2125 | /// | ||
2126 | /// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements) | ||
1105 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2127 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1106 | pub struct LetStmt { | 2128 | pub struct LetStmt { |
1107 | pub(crate) syntax: SyntaxNode, | 2129 | pub(crate) syntax: SyntaxNode, |
@@ -1115,7 +2137,18 @@ impl LetStmt { | |||
1115 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } | 2137 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } |
1116 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 2138 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
1117 | } | 2139 | } |
1118 | 2140 | /// Condition of `if` or `while` expression. | |
2141 | /// | ||
2142 | /// ``` | ||
2143 | /// if ❰ true ❱ {} | ||
2144 | /// if ❰ let Pat(foo) = bar ❱ {} | ||
2145 | /// | ||
2146 | /// while ❰ true ❱ {} | ||
2147 | /// while ❰ let Pat(baz) = bruh ❱ {} | ||
2148 | /// ``` | ||
2149 | /// | ||
2150 | /// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
2151 | /// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
1119 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2152 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1120 | pub struct Condition { | 2153 | pub struct Condition { |
1121 | pub(crate) syntax: SyntaxNode, | 2154 | pub(crate) syntax: SyntaxNode, |
@@ -1126,7 +2159,18 @@ impl Condition { | |||
1126 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 2159 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
1127 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 2160 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1128 | } | 2161 | } |
1129 | 2162 | /// Parameter list **declaration**. | |
2163 | /// | ||
2164 | /// ``` | ||
2165 | /// fn foo❰ (a: u32, b: bool) ❱ -> u32 {} | ||
2166 | /// let bar = ❰ |a, b| ❱ {}; | ||
2167 | /// | ||
2168 | /// impl Baz { | ||
2169 | /// fn bruh❰ (&self, a: u32) ❱ {} | ||
2170 | /// } | ||
2171 | /// ``` | ||
2172 | /// | ||
2173 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script | ||
1130 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2174 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1131 | pub struct ParamList { | 2175 | pub struct ParamList { |
1132 | pub(crate) syntax: SyntaxNode, | 2176 | pub(crate) syntax: SyntaxNode, |
@@ -1137,7 +2181,19 @@ impl ParamList { | |||
1137 | pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } | 2181 | pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } |
1138 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 2182 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1139 | } | 2183 | } |
1140 | 2184 | /// Self parameter **declaration**. | |
2185 | /// | ||
2186 | /// ``` | ||
2187 | /// impl Bruh { | ||
2188 | /// fn foo(❰ self ❱) {} | ||
2189 | /// fn bar(❰ &self ❱) {} | ||
2190 | /// fn baz(❰ &mut self ❱) {} | ||
2191 | /// fn blah<'a>(❰ &'a self ❱) {} | ||
2192 | /// fn blin(❰ self: Box<Self> ❱) {} | ||
2193 | /// } | ||
2194 | /// ``` | ||
2195 | /// | ||
2196 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
1141 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2197 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1142 | pub struct SelfParam { | 2198 | pub struct SelfParam { |
1143 | pub(crate) syntax: SyntaxNode, | 2199 | pub(crate) syntax: SyntaxNode, |
@@ -1152,7 +2208,17 @@ impl SelfParam { | |||
1152 | } | 2208 | } |
1153 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | 2209 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } |
1154 | } | 2210 | } |
1155 | 2211 | /// Parameter **declaration**. | |
2212 | /// | ||
2213 | /// ``` | ||
2214 | /// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {} | ||
2215 | /// | ||
2216 | /// extern "C" { | ||
2217 | /// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32; | ||
2218 | /// } | ||
2219 | /// ``` | ||
2220 | /// | ||
2221 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
1156 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2222 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1157 | pub struct Param { | 2223 | pub struct Param { |
1158 | pub(crate) syntax: SyntaxNode, | 2224 | pub(crate) syntax: SyntaxNode, |
@@ -1163,7 +2229,16 @@ impl Param { | |||
1163 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 2229 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1164 | pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } | 2230 | pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } |
1165 | } | 2231 | } |
1166 | 2232 | /// Use declaration. | |
2233 | /// | ||
2234 | /// ``` | ||
2235 | /// ❰ #[attr] pub use foo; ❱ | ||
2236 | /// ❰ use bar as baz; ❱ | ||
2237 | /// ❰ use bruh::{self, bruuh}; ❱ | ||
2238 | /// ❰ use { blin::blen, blah::* }; | ||
2239 | /// ``` | ||
2240 | /// | ||
2241 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1167 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2242 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1168 | pub struct UseItem { | 2243 | pub struct UseItem { |
1169 | pub(crate) syntax: SyntaxNode, | 2244 | pub(crate) syntax: SyntaxNode, |
@@ -1174,7 +2249,16 @@ impl UseItem { | |||
1174 | pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } | 2249 | pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } |
1175 | pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } | 2250 | pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } |
1176 | } | 2251 | } |
1177 | 2252 | /// Use tree. | |
2253 | /// | ||
2254 | /// ``` | ||
2255 | /// pub use ❰ foo::❰ * ❱ ❱; | ||
2256 | /// use ❰ bar as baz ❱; | ||
2257 | /// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱; | ||
2258 | /// use ❰ { ❰ blin::blen ❱ } ❱ | ||
2259 | /// ``` | ||
2260 | /// | ||
2261 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1178 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2262 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1179 | pub struct UseTree { | 2263 | pub struct UseTree { |
1180 | pub(crate) syntax: SyntaxNode, | 2264 | pub(crate) syntax: SyntaxNode, |
@@ -1185,7 +2269,16 @@ impl UseTree { | |||
1185 | pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } | 2269 | pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } |
1186 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } | 2270 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } |
1187 | } | 2271 | } |
1188 | 2272 | /// Item alias. | |
2273 | /// Note: this is not the type alias. | ||
2274 | /// | ||
2275 | /// ``` | ||
2276 | /// use foo ❰ as bar ❱; | ||
2277 | /// use baz::{bruh ❰ as _ ❱}; | ||
2278 | /// extern crate bruuh ❰ as blin ❱; | ||
2279 | /// ``` | ||
2280 | /// | ||
2281 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1189 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2282 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1190 | pub struct Alias { | 2283 | pub struct Alias { |
1191 | pub(crate) syntax: SyntaxNode, | 2284 | pub(crate) syntax: SyntaxNode, |
@@ -1194,7 +2287,14 @@ impl ast::NameOwner for Alias {} | |||
1194 | impl Alias { | 2287 | impl Alias { |
1195 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } | 2288 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } |
1196 | } | 2289 | } |
1197 | 2290 | /// Sublist of use trees. | |
2291 | /// | ||
2292 | /// ``` | ||
2293 | /// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱; | ||
2294 | /// use ❰ { blin::blen::❰ {} ❱ } ❱ | ||
2295 | /// ``` | ||
2296 | /// | ||
2297 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1198 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2298 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1199 | pub struct UseTreeList { | 2299 | pub struct UseTreeList { |
1200 | pub(crate) syntax: SyntaxNode, | 2300 | pub(crate) syntax: SyntaxNode, |
@@ -1204,7 +2304,14 @@ impl UseTreeList { | |||
1204 | pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } | 2304 | pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } |
1205 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 2305 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1206 | } | 2306 | } |
1207 | 2307 | /// Extern crate item. | |
2308 | /// | ||
2309 | /// ``` | ||
2310 | /// ❰ #[attr] pub extern crate foo; ❱ | ||
2311 | /// ❰ extern crate self as bar; ❱ | ||
2312 | /// ``` | ||
2313 | /// | ||
2314 | /// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html) | ||
1208 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2315 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1209 | pub struct ExternCrateItem { | 2316 | pub struct ExternCrateItem { |
1210 | pub(crate) syntax: SyntaxNode, | 2317 | pub(crate) syntax: SyntaxNode, |
@@ -1217,7 +2324,13 @@ impl ExternCrateItem { | |||
1217 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 2324 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
1218 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } | 2325 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } |
1219 | } | 2326 | } |
1220 | 2327 | /// Call site arguments list. | |
2328 | /// | ||
2329 | /// ``` | ||
2330 | /// foo::<T, U>❰ (42, true) ❱; | ||
2331 | /// ``` | ||
2332 | /// | ||
2333 | /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) | ||
1221 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2334 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1222 | pub struct ArgList { | 2335 | pub struct ArgList { |
1223 | pub(crate) syntax: SyntaxNode, | 2336 | pub(crate) syntax: SyntaxNode, |
@@ -1227,16 +2340,41 @@ impl ArgList { | |||
1227 | pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | 2340 | pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
1228 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 2341 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1229 | } | 2342 | } |
1230 | 2343 | /// Path to a symbol. Includes single identifier names and elaborate paths with | |
2344 | /// generic parameters. | ||
2345 | /// | ||
2346 | /// ``` | ||
2347 | /// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱(); | ||
2348 | /// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024); | ||
2349 | /// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱(); | ||
2350 | /// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱(); | ||
2351 | /// ``` | ||
2352 | /// | ||
2353 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
1231 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2354 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1232 | pub struct Path { | 2355 | pub struct Path { |
1233 | pub(crate) syntax: SyntaxNode, | 2356 | pub(crate) syntax: SyntaxNode, |
1234 | } | 2357 | } |
1235 | impl Path { | 2358 | impl Path { |
1236 | pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) } | 2359 | pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) } |
2360 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
1237 | pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) } | 2361 | pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) } |
1238 | } | 2362 | } |
1239 | 2363 | /// Segment of the path to a symbol. | |
2364 | /// Only path segment of an absolute path holds the `::` token, | ||
2365 | /// all other `::` tokens that connect path segments reside under `Path` itself.` | ||
2366 | /// | ||
2367 | /// ``` | ||
2368 | /// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱(); | ||
2369 | /// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024); | ||
2370 | /// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱(); | ||
2371 | /// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱(); | ||
2372 | /// | ||
2373 | /// // Note that only in this case `::` token is inlcuded: | ||
2374 | /// ❰ ::foo ❱; | ||
2375 | /// ``` | ||
2376 | /// | ||
2377 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
1240 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2378 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1241 | pub struct PathSegment { | 2379 | pub struct PathSegment { |
1242 | pub(crate) syntax: SyntaxNode, | 2380 | pub(crate) syntax: SyntaxNode, |
@@ -1254,7 +2392,15 @@ impl PathSegment { | |||
1254 | pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } | 2392 | pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } |
1255 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | 2393 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } |
1256 | } | 2394 | } |
1257 | 2395 | /// List of type arguments that are passed at generic instantiation site. | |
2396 | /// | ||
2397 | /// ``` | ||
2398 | /// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar; | ||
2399 | /// | ||
2400 | /// Vec❰ ::<bool> ❱::(); | ||
2401 | /// ``` | ||
2402 | /// | ||
2403 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
1258 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2404 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1259 | pub struct TypeArgList { | 2405 | pub struct TypeArgList { |
1260 | pub(crate) syntax: SyntaxNode, | 2406 | pub(crate) syntax: SyntaxNode, |
@@ -1269,7 +2415,13 @@ impl TypeArgList { | |||
1269 | pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) } | 2415 | pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) } |
1270 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | 2416 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } |
1271 | } | 2417 | } |
1272 | 2418 | /// Type argument that is passed at generic instantiation site. | |
2419 | /// | ||
2420 | /// ``` | ||
2421 | /// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz; | ||
2422 | /// ``` | ||
2423 | /// | ||
2424 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
1273 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2425 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1274 | pub struct TypeArg { | 2426 | pub struct TypeArg { |
1275 | pub(crate) syntax: SyntaxNode, | 2427 | pub(crate) syntax: SyntaxNode, |
@@ -1277,7 +2429,13 @@ pub struct TypeArg { | |||
1277 | impl TypeArg { | 2429 | impl TypeArg { |
1278 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 2430 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1279 | } | 2431 | } |
1280 | 2432 | /// Associated type argument that is passed at generic instantiation site. | |
2433 | /// ``` | ||
2434 | /// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh; | ||
2435 | /// | ||
2436 | /// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {} | ||
2437 | /// ``` | ||
2438 | /// | ||
1281 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2439 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1282 | pub struct AssocTypeArg { | 2440 | pub struct AssocTypeArg { |
1283 | pub(crate) syntax: SyntaxNode, | 2441 | pub(crate) syntax: SyntaxNode, |
@@ -1288,7 +2446,15 @@ impl AssocTypeArg { | |||
1288 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 2446 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
1289 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 2447 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1290 | } | 2448 | } |
1291 | 2449 | /// Lifetime argument that is passed at generic instantiation site. | |
2450 | /// | ||
2451 | /// ``` | ||
2452 | /// fn foo<'a>(s: &'a str) { | ||
2453 | /// bar::<❰ 'a ❱>(s); | ||
2454 | /// } | ||
2455 | /// ``` | ||
2456 | /// | ||
2457 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
1292 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2458 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1293 | pub struct LifetimeArg { | 2459 | pub struct LifetimeArg { |
1294 | pub(crate) syntax: SyntaxNode, | 2460 | pub(crate) syntax: SyntaxNode, |
@@ -1298,24 +2464,41 @@ impl LifetimeArg { | |||
1298 | support::token(&self.syntax, T![lifetime]) | 2464 | support::token(&self.syntax, T![lifetime]) |
1299 | } | 2465 | } |
1300 | } | 2466 | } |
1301 | 2467 | /// Constant value argument that is passed at generic instantiation site. | |
2468 | /// | ||
2469 | /// ``` | ||
2470 | /// foo::<u32, ❰ { true } ❱>(); | ||
2471 | /// | ||
2472 | /// bar::<❰ { 2 + 2} ❱>(); | ||
2473 | /// ``` | ||
2474 | /// | ||
2475 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) | ||
1302 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2476 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1303 | pub struct ConstArg { | 2477 | pub struct ConstArg { |
1304 | pub(crate) syntax: SyntaxNode, | 2478 | pub(crate) syntax: SyntaxNode, |
1305 | } | 2479 | } |
1306 | impl ConstArg { | 2480 | impl ConstArg { |
1307 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | 2481 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } |
1308 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
1309 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 2482 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
1310 | } | 2483 | } |
1311 | 2484 | /// FIXME: (@edwin0cheng) Remove it to use ItemList instead | |
2485 | /// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243 | ||
2486 | /// | ||
2487 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
1312 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2488 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1313 | pub struct MacroItems { | 2489 | pub struct MacroItems { |
1314 | pub(crate) syntax: SyntaxNode, | 2490 | pub(crate) syntax: SyntaxNode, |
1315 | } | 2491 | } |
1316 | impl ast::ModuleItemOwner for MacroItems {} | 2492 | impl ast::ModuleItemOwner for MacroItems {} |
1317 | impl MacroItems {} | 2493 | impl MacroItems {} |
1318 | 2494 | /// FIXME: (@edwin0cheng) add some documentation here. As per the writing | |
2495 | /// of this comment this ast node is not used. | ||
2496 | /// | ||
2497 | /// ``` | ||
2498 | /// // FIXME: example here | ||
2499 | /// ``` | ||
2500 | /// | ||
2501 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
1319 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2502 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1320 | pub struct MacroStmts { | 2503 | pub struct MacroStmts { |
1321 | pub(crate) syntax: SyntaxNode, | 2504 | pub(crate) syntax: SyntaxNode, |
@@ -1324,7 +2507,18 @@ impl MacroStmts { | |||
1324 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } | 2507 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } |
1325 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 2508 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1326 | } | 2509 | } |
1327 | 2510 | /// List of items in an extern block. | |
2511 | /// | ||
2512 | /// ``` | ||
2513 | /// extern "C" ❰ | ||
2514 | /// { | ||
2515 | /// fn foo(); | ||
2516 | /// static var: u32; | ||
2517 | /// } | ||
2518 | /// ❱ | ||
2519 | /// ``` | ||
2520 | /// | ||
2521 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
1328 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2522 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1329 | pub struct ExternItemList { | 2523 | pub struct ExternItemList { |
1330 | pub(crate) syntax: SyntaxNode, | 2524 | pub(crate) syntax: SyntaxNode, |
@@ -1335,7 +2529,18 @@ impl ExternItemList { | |||
1335 | pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } | 2529 | pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } |
1336 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 2530 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1337 | } | 2531 | } |
1338 | 2532 | /// Extern block. | |
2533 | /// | ||
2534 | /// ``` | ||
2535 | /// ❰ | ||
2536 | /// extern "C" { | ||
2537 | /// fn foo(); | ||
2538 | /// } | ||
2539 | /// ❱ | ||
2540 | /// | ||
2541 | /// ``` | ||
2542 | /// | ||
2543 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
1339 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2544 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1340 | pub struct ExternBlock { | 2545 | pub struct ExternBlock { |
1341 | pub(crate) syntax: SyntaxNode, | 2546 | pub(crate) syntax: SyntaxNode, |
@@ -1344,7 +2549,15 @@ impl ExternBlock { | |||
1344 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | 2549 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } |
1345 | pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) } | 2550 | pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) } |
1346 | } | 2551 | } |
1347 | 2552 | /// Meta item in an attribute. | |
2553 | /// | ||
2554 | /// ``` | ||
2555 | /// #[❰ bar::baz = "42" ❱] | ||
2556 | /// #[❰ bruh(bruuh("true")) ❱] | ||
2557 | /// struct Foo; | ||
2558 | /// ``` | ||
2559 | /// | ||
2560 | /// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax) | ||
1348 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2561 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1349 | pub struct MetaItem { | 2562 | pub struct MetaItem { |
1350 | pub(crate) syntax: SyntaxNode, | 2563 | pub(crate) syntax: SyntaxNode, |
@@ -1355,7 +2568,15 @@ impl MetaItem { | |||
1355 | pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } | 2568 | pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } |
1356 | pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) } | 2569 | pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) } |
1357 | } | 2570 | } |
1358 | 2571 | /// Macro 2.0 definition. | |
2572 | /// Their syntax is still WIP by rustc team... | ||
2573 | /// ``` | ||
2574 | /// ❰ | ||
2575 | /// macro foo { } | ||
2576 | /// ❱ | ||
2577 | /// ``` | ||
2578 | /// | ||
2579 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md) | ||
1359 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2580 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1360 | pub struct MacroDef { | 2581 | pub struct MacroDef { |
1361 | pub(crate) syntax: SyntaxNode, | 2582 | pub(crate) syntax: SyntaxNode, |
@@ -1364,7 +2585,7 @@ impl MacroDef { | |||
1364 | pub fn name(&self) -> Option<Name> { support::child(&self.syntax) } | 2585 | pub fn name(&self) -> Option<Name> { support::child(&self.syntax) } |
1365 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | 2586 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } |
1366 | } | 2587 | } |
1367 | 2588 | /// Any kind of nominal type definition. | |
1368 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2589 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1369 | pub enum NominalDef { | 2590 | pub enum NominalDef { |
1370 | StructDef(StructDef), | 2591 | StructDef(StructDef), |
@@ -1374,14 +2595,14 @@ pub enum NominalDef { | |||
1374 | impl ast::NameOwner for NominalDef {} | 2595 | impl ast::NameOwner for NominalDef {} |
1375 | impl ast::TypeParamsOwner for NominalDef {} | 2596 | impl ast::TypeParamsOwner for NominalDef {} |
1376 | impl ast::AttrsOwner for NominalDef {} | 2597 | impl ast::AttrsOwner for NominalDef {} |
1377 | 2598 | /// Any kind of **declared** generic parameter | |
1378 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2599 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1379 | pub enum GenericParam { | 2600 | pub enum GenericParam { |
1380 | LifetimeParam(LifetimeParam), | 2601 | LifetimeParam(LifetimeParam), |
1381 | TypeParam(TypeParam), | 2602 | TypeParam(TypeParam), |
1382 | ConstParam(ConstParam), | 2603 | ConstParam(ConstParam), |
1383 | } | 2604 | } |
1384 | 2605 | /// Any kind of generic argument passed at instantiation site | |
1385 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2606 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1386 | pub enum GenericArg { | 2607 | pub enum GenericArg { |
1387 | LifetimeArg(LifetimeArg), | 2608 | LifetimeArg(LifetimeArg), |
@@ -1389,7 +2610,7 @@ pub enum GenericArg { | |||
1389 | ConstArg(ConstArg), | 2610 | ConstArg(ConstArg), |
1390 | AssocTypeArg(AssocTypeArg), | 2611 | AssocTypeArg(AssocTypeArg), |
1391 | } | 2612 | } |
1392 | 2613 | /// Any kind of construct valid in type context | |
1393 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2614 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1394 | pub enum TypeRef { | 2615 | pub enum TypeRef { |
1395 | ParenType(ParenType), | 2616 | ParenType(ParenType), |
@@ -1406,7 +2627,7 @@ pub enum TypeRef { | |||
1406 | ImplTraitType(ImplTraitType), | 2627 | ImplTraitType(ImplTraitType), |
1407 | DynTraitType(DynTraitType), | 2628 | DynTraitType(DynTraitType), |
1408 | } | 2629 | } |
1409 | 2630 | /// Any kind of top-level item that may appear in a module | |
1410 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2631 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1411 | pub enum ModuleItem { | 2632 | pub enum ModuleItem { |
1412 | StructDef(StructDef), | 2633 | StructDef(StructDef), |
@@ -1427,7 +2648,9 @@ pub enum ModuleItem { | |||
1427 | impl ast::NameOwner for ModuleItem {} | 2648 | impl ast::NameOwner for ModuleItem {} |
1428 | impl ast::AttrsOwner for ModuleItem {} | 2649 | impl ast::AttrsOwner for ModuleItem {} |
1429 | impl ast::VisibilityOwner for ModuleItem {} | 2650 | impl ast::VisibilityOwner for ModuleItem {} |
1430 | 2651 | /// Any kind of item that may appear in an impl block | |
2652 | /// | ||
2653 | /// // FIXME: impl blocks can also contain MacroCall | ||
1431 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2654 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1432 | pub enum AssocItem { | 2655 | pub enum AssocItem { |
1433 | FnDef(FnDef), | 2656 | FnDef(FnDef), |
@@ -1436,7 +2659,9 @@ pub enum AssocItem { | |||
1436 | } | 2659 | } |
1437 | impl ast::NameOwner for AssocItem {} | 2660 | impl ast::NameOwner for AssocItem {} |
1438 | impl ast::AttrsOwner for AssocItem {} | 2661 | impl ast::AttrsOwner for AssocItem {} |
1439 | 2662 | /// Any kind of item that may appear in an extern block | |
2663 | /// | ||
2664 | /// // FIXME: extern blocks can also contain MacroCall | ||
1440 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2665 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1441 | pub enum ExternItem { | 2666 | pub enum ExternItem { |
1442 | FnDef(FnDef), | 2667 | FnDef(FnDef), |
@@ -1445,7 +2670,7 @@ pub enum ExternItem { | |||
1445 | impl ast::NameOwner for ExternItem {} | 2670 | impl ast::NameOwner for ExternItem {} |
1446 | impl ast::AttrsOwner for ExternItem {} | 2671 | impl ast::AttrsOwner for ExternItem {} |
1447 | impl ast::VisibilityOwner for ExternItem {} | 2672 | impl ast::VisibilityOwner for ExternItem {} |
1448 | 2673 | /// Any kind of expression | |
1449 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2674 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1450 | pub enum Expr { | 2675 | pub enum Expr { |
1451 | TupleExpr(TupleExpr), | 2676 | TupleExpr(TupleExpr), |
@@ -1481,7 +2706,7 @@ pub enum Expr { | |||
1481 | BoxExpr(BoxExpr), | 2706 | BoxExpr(BoxExpr), |
1482 | } | 2707 | } |
1483 | impl ast::AttrsOwner for Expr {} | 2708 | impl ast::AttrsOwner for Expr {} |
1484 | 2709 | /// Any kind of pattern | |
1485 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2710 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1486 | pub enum Pat { | 2711 | pub enum Pat { |
1487 | OrPat(OrPat), | 2712 | OrPat(OrPat), |
@@ -1500,25 +2725,28 @@ pub enum Pat { | |||
1500 | LiteralPat(LiteralPat), | 2725 | LiteralPat(LiteralPat), |
1501 | MacroPat(MacroPat), | 2726 | MacroPat(MacroPat), |
1502 | } | 2727 | } |
1503 | 2728 | /// Any kind of pattern that appears directly inside of the curly | |
2729 | /// braces of a record pattern | ||
1504 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2730 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1505 | pub enum RecordInnerPat { | 2731 | pub enum RecordInnerPat { |
1506 | RecordFieldPat(RecordFieldPat), | 2732 | RecordFieldPat(RecordFieldPat), |
1507 | BindPat(BindPat), | 2733 | BindPat(BindPat), |
1508 | } | 2734 | } |
1509 | 2735 | /// Any kind of input to an attribute | |
1510 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2736 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1511 | pub enum AttrInput { | 2737 | pub enum AttrInput { |
1512 | Literal(Literal), | 2738 | Literal(Literal), |
1513 | TokenTree(TokenTree), | 2739 | TokenTree(TokenTree), |
1514 | } | 2740 | } |
1515 | 2741 | /// Any kind of statement | |
2742 | /// Note: there are no empty statements, these are just represented as | ||
2743 | /// bare semicolons without a dedicated statement ast node. | ||
1516 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2744 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1517 | pub enum Stmt { | 2745 | pub enum Stmt { |
1518 | LetStmt(LetStmt), | 2746 | LetStmt(LetStmt), |
1519 | ExprStmt(ExprStmt), | 2747 | ExprStmt(ExprStmt), |
1520 | } | 2748 | } |
1521 | 2749 | /// Any kind of fields list (record or tuple field lists) | |
1522 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2750 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1523 | pub enum FieldDefList { | 2751 | pub enum FieldDefList { |
1524 | RecordFieldDefList(RecordFieldDefList), | 2752 | RecordFieldDefList(RecordFieldDefList), |
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index 71c627a2a..06178990f 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json | |||
@@ -88,15 +88,15 @@ | |||
88 | "dev": true | 88 | "dev": true |
89 | }, | 89 | }, |
90 | "@types/node": { | 90 | "@types/node": { |
91 | "version": "12.12.37", | 91 | "version": "12.12.39", |
92 | "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.37.tgz", | 92 | "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.39.tgz", |
93 | "integrity": "sha512-4mXKoDptrXAwZErQHrLzpe0FN/0Wmf5JRniSVIdwUrtDf9wnmEV1teCNLBo/TwuXhkK/bVegoEn/wmb+x0AuPg==", | 93 | "integrity": "sha512-pADGfwnDkr6zagDwEiCVE4yQrv7XDkoeVa4OfA9Ju/zRTk6YNDLGtQbkdL4/56mCQQCs4AhNrBIag6jrp7ZuOg==", |
94 | "dev": true | 94 | "dev": true |
95 | }, | 95 | }, |
96 | "@types/node-fetch": { | 96 | "@types/node-fetch": { |
97 | "version": "2.5.6", | 97 | "version": "2.5.7", |
98 | "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.6.tgz", | 98 | "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.7.tgz", |
99 | "integrity": "sha512-2w0NTwMWF1d3NJMK0Uiq2UNN8htVCyOWOD0jIPjPgC5Ph/YP4dVhs9YxxcMcuLuwAslz0dVEcZQUaqkLs3IzOQ==", | 99 | "integrity": "sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==", |
100 | "dev": true, | 100 | "dev": true, |
101 | "requires": { | 101 | "requires": { |
102 | "@types/node": "*", | 102 | "@types/node": "*", |
@@ -113,31 +113,31 @@ | |||
113 | } | 113 | } |
114 | }, | 114 | }, |
115 | "@types/vscode": { | 115 | "@types/vscode": { |
116 | "version": "1.44.0", | 116 | "version": "1.45.0", |
117 | "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.44.0.tgz", | 117 | "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.45.0.tgz", |
118 | "integrity": "sha512-WJZtZlinE3meRdH+I7wTsIhpz/GLhqEQwmPGeh4s1irWLwMzCeTV8WZ+pgPTwrDXoafVUWwo1LiZ9HJVHFlJSQ==", | 118 | "integrity": "sha512-b0Gyir7sPBCqiKLygAhn/AYVfzWD+SMPkWltBrIuPEyTOxSU1wVApWY/FcxYO2EWTRacoubTl4+gvZf86RkecA==", |
119 | "dev": true | 119 | "dev": true |
120 | }, | 120 | }, |
121 | "@typescript-eslint/eslint-plugin": { | 121 | "@typescript-eslint/eslint-plugin": { |
122 | "version": "2.29.0", | 122 | "version": "2.33.0", |
123 | "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.29.0.tgz", | 123 | "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.33.0.tgz", |
124 | "integrity": "sha512-X/YAY7azKirENm4QRpT7OVmzok02cSkqeIcLmdz6gXUQG4Hk0Fi9oBAynSAyNXeGdMRuZvjBa0c1Lu0dn/u6VA==", | 124 | "integrity": "sha512-QV6P32Btu1sCI/kTqjTNI/8OpCYyvlGjW5vD8MpTIg+HGE5S88HtT1G+880M4bXlvXj/NjsJJG0aGcVh0DdbeQ==", |
125 | "dev": true, | 125 | "dev": true, |
126 | "requires": { | 126 | "requires": { |
127 | "@typescript-eslint/experimental-utils": "2.29.0", | 127 | "@typescript-eslint/experimental-utils": "2.33.0", |
128 | "functional-red-black-tree": "^1.0.1", | 128 | "functional-red-black-tree": "^1.0.1", |
129 | "regexpp": "^3.0.0", | 129 | "regexpp": "^3.0.0", |
130 | "tsutils": "^3.17.1" | 130 | "tsutils": "^3.17.1" |
131 | } | 131 | } |
132 | }, | 132 | }, |
133 | "@typescript-eslint/experimental-utils": { | 133 | "@typescript-eslint/experimental-utils": { |
134 | "version": "2.29.0", | 134 | "version": "2.33.0", |
135 | "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.29.0.tgz", | 135 | "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.33.0.tgz", |
136 | "integrity": "sha512-H/6VJr6eWYstyqjWXBP2Nn1hQJyvJoFdDtsHxGiD+lEP7piGnGpb/ZQd+z1ZSB1F7dN+WsxUDh8+S4LwI+f3jw==", | 136 | "integrity": "sha512-qzPM2AuxtMrRq78LwyZa8Qn6gcY8obkIrBs1ehqmQADwkYzTE1Pb4y2W+U3rE/iFkSWcWHG2LS6MJfj6SmHApg==", |
137 | "dev": true, | 137 | "dev": true, |
138 | "requires": { | 138 | "requires": { |
139 | "@types/json-schema": "^7.0.3", | 139 | "@types/json-schema": "^7.0.3", |
140 | "@typescript-eslint/typescript-estree": "2.29.0", | 140 | "@typescript-eslint/typescript-estree": "2.33.0", |
141 | "eslint-scope": "^5.0.0", | 141 | "eslint-scope": "^5.0.0", |
142 | "eslint-utils": "^2.0.0" | 142 | "eslint-utils": "^2.0.0" |
143 | }, | 143 | }, |
@@ -154,21 +154,21 @@ | |||
154 | } | 154 | } |
155 | }, | 155 | }, |
156 | "@typescript-eslint/parser": { | 156 | "@typescript-eslint/parser": { |
157 | "version": "2.29.0", | 157 | "version": "2.33.0", |
158 | "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.29.0.tgz", | 158 | "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.33.0.tgz", |
159 | "integrity": "sha512-H78M+jcu5Tf6m/5N8iiFblUUv+HJDguMSdFfzwa6vSg9lKR8Mk9BsgeSjO8l2EshKnJKcbv0e8IDDOvSNjl0EA==", | 159 | "integrity": "sha512-AUtmwUUhJoH6yrtxZMHbRUEMsC2G6z5NSxg9KsROOGqNXasM71I8P2NihtumlWTUCRld70vqIZ6Pm4E5PAziEA==", |
160 | "dev": true, | 160 | "dev": true, |
161 | "requires": { | 161 | "requires": { |
162 | "@types/eslint-visitor-keys": "^1.0.0", | 162 | "@types/eslint-visitor-keys": "^1.0.0", |
163 | "@typescript-eslint/experimental-utils": "2.29.0", | 163 | "@typescript-eslint/experimental-utils": "2.33.0", |
164 | "@typescript-eslint/typescript-estree": "2.29.0", | 164 | "@typescript-eslint/typescript-estree": "2.33.0", |
165 | "eslint-visitor-keys": "^1.1.0" | 165 | "eslint-visitor-keys": "^1.1.0" |
166 | } | 166 | } |
167 | }, | 167 | }, |
168 | "@typescript-eslint/typescript-estree": { | 168 | "@typescript-eslint/typescript-estree": { |
169 | "version": "2.29.0", | 169 | "version": "2.33.0", |
170 | "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.29.0.tgz", | 170 | "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.33.0.tgz", |
171 | "integrity": "sha512-3YGbtnWy4az16Egy5Fj5CckkVlpIh0MADtAQza+jiMADRSKkjdpzZp/5WuvwK/Qib3Z0HtzrDFeWanS99dNhnA==", | 171 | "integrity": "sha512-d8rY6/yUxb0+mEwTShCQF2zYQdLlqihukNfG9IUlLYz5y1CH6G/9XYbrxQLq3Z14RNvkCC6oe+OcFlyUpwUbkg==", |
172 | "dev": true, | 172 | "dev": true, |
173 | "requires": { | 173 | "requires": { |
174 | "debug": "^4.1.1", | 174 | "debug": "^4.1.1", |
@@ -176,8 +176,16 @@ | |||
176 | "glob": "^7.1.6", | 176 | "glob": "^7.1.6", |
177 | "is-glob": "^4.0.1", | 177 | "is-glob": "^4.0.1", |
178 | "lodash": "^4.17.15", | 178 | "lodash": "^4.17.15", |
179 | "semver": "^6.3.0", | 179 | "semver": "^7.3.2", |
180 | "tsutils": "^3.17.1" | 180 | "tsutils": "^3.17.1" |
181 | }, | ||
182 | "dependencies": { | ||
183 | "semver": { | ||
184 | "version": "7.3.2", | ||
185 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", | ||
186 | "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", | ||
187 | "dev": true | ||
188 | } | ||
181 | } | 189 | } |
182 | }, | 190 | }, |
183 | "acorn": { | 191 | "acorn": { |
@@ -1160,18 +1168,18 @@ | |||
1160 | "dev": true | 1168 | "dev": true |
1161 | }, | 1169 | }, |
1162 | "mime-db": { | 1170 | "mime-db": { |
1163 | "version": "1.43.0", | 1171 | "version": "1.44.0", |
1164 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", | 1172 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", |
1165 | "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==", | 1173 | "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==", |
1166 | "dev": true | 1174 | "dev": true |
1167 | }, | 1175 | }, |
1168 | "mime-types": { | 1176 | "mime-types": { |
1169 | "version": "2.1.26", | 1177 | "version": "2.1.27", |
1170 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", | 1178 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", |
1171 | "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", | 1179 | "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", |
1172 | "dev": true, | 1180 | "dev": true, |
1173 | "requires": { | 1181 | "requires": { |
1174 | "mime-db": "1.43.0" | 1182 | "mime-db": "1.44.0" |
1175 | } | 1183 | } |
1176 | }, | 1184 | }, |
1177 | "mimic-fn": { | 1185 | "mimic-fn": { |
@@ -1452,9 +1460,9 @@ | |||
1452 | } | 1460 | } |
1453 | }, | 1461 | }, |
1454 | "rollup": { | 1462 | "rollup": { |
1455 | "version": "2.7.1", | 1463 | "version": "2.10.0", |
1456 | "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.7.1.tgz", | 1464 | "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.10.0.tgz", |
1457 | "integrity": "sha512-c1FCjY8HK1nAq0bTZHaR72ZknpP7p0EjxbcVc6BcmtOosurK//P5jtwxX+f/4fgtbrjczqf0uvR+EdtxpriE8g==", | 1465 | "integrity": "sha512-7BmpEfUN9P6esJzWIn3DmR//90mW6YwYB1t3y48LpF8ITpYtL8s1kEirMKqUu44dVH/6a/rs0EuwYVL3FuRDoA==", |
1458 | "dev": true, | 1466 | "dev": true, |
1459 | "requires": { | 1467 | "requires": { |
1460 | "fsevents": "~2.1.2" | 1468 | "fsevents": "~2.1.2" |
@@ -1684,9 +1692,9 @@ | |||
1684 | } | 1692 | } |
1685 | }, | 1693 | }, |
1686 | "tslib": { | 1694 | "tslib": { |
1687 | "version": "1.11.1", | 1695 | "version": "1.12.0", |
1688 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz", | 1696 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.12.0.tgz", |
1689 | "integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==", | 1697 | "integrity": "sha512-5rxCQkP0kytf4H1T4xz1imjxaUUPMvc5aWp0rJ/VMIN7ClRiH1FwFvBt8wOeMasp/epeUnmSW6CixSIePtiLqA==", |
1690 | "dev": true | 1698 | "dev": true |
1691 | }, | 1699 | }, |
1692 | "tsutils": { | 1700 | "tsutils": { |
@@ -1730,9 +1738,9 @@ | |||
1730 | } | 1738 | } |
1731 | }, | 1739 | }, |
1732 | "typescript": { | 1740 | "typescript": { |
1733 | "version": "3.8.3", | 1741 | "version": "3.9.2", |
1734 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", | 1742 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.2.tgz", |
1735 | "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", | 1743 | "integrity": "sha512-q2ktq4n/uLuNNShyayit+DTobV2ApPEo/6so68JaD5ojvc/6GClBipedB9zNWYxRSAlZXAe405Rlijzl6qDiSw==", |
1736 | "dev": true | 1744 | "dev": true |
1737 | }, | 1745 | }, |
1738 | "typescript-formatter": { | 1746 | "typescript-formatter": { |
diff --git a/editors/code/package.json b/editors/code/package.json index 321353f22..b8a2182f0 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -21,7 +21,7 @@ | |||
21 | "Programming Languages" | 21 | "Programming Languages" |
22 | ], | 22 | ], |
23 | "engines": { | 23 | "engines": { |
24 | "vscode": "^1.44.0" | 24 | "vscode": "^1.45.0" |
25 | }, | 25 | }, |
26 | "enableProposedApi": true, | 26 | "enableProposedApi": true, |
27 | "scripts": { | 27 | "scripts": { |
@@ -39,15 +39,15 @@ | |||
39 | "devDependencies": { | 39 | "devDependencies": { |
40 | "@rollup/plugin-commonjs": "^11.1.0", | 40 | "@rollup/plugin-commonjs": "^11.1.0", |
41 | "@rollup/plugin-node-resolve": "^7.1.3", | 41 | "@rollup/plugin-node-resolve": "^7.1.3", |
42 | "@types/node": "^12.12.37", | 42 | "@types/node": "^12.12.39", |
43 | "@types/node-fetch": "^2.5.6", | 43 | "@types/node-fetch": "^2.5.7", |
44 | "@types/vscode": "^1.44.0", | 44 | "@types/vscode": "^1.45.0", |
45 | "@typescript-eslint/eslint-plugin": "^2.29.0", | 45 | "@typescript-eslint/eslint-plugin": "^2.33.0", |
46 | "@typescript-eslint/parser": "^2.29.0", | 46 | "@typescript-eslint/parser": "^2.33.0", |
47 | "eslint": "^6.8.0", | 47 | "eslint": "^6.8.0", |
48 | "rollup": "^2.7.1", | 48 | "rollup": "^2.10.0", |
49 | "tslib": "^1.11.1", | 49 | "tslib": "^1.12.0", |
50 | "typescript": "^3.8.3", | 50 | "typescript": "^3.9.2", |
51 | "typescript-formatter": "^7.2.2", | 51 | "typescript-formatter": "^7.2.2", |
52 | "vsce": "^1.75.0" | 52 | "vsce": "^1.75.0" |
53 | }, | 53 | }, |
diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index b80a18a47..a5446c327 100644 --- a/editors/code/src/commands/syntax_tree.ts +++ b/editors/code/src/commands/syntax_tree.ts | |||
@@ -206,7 +206,7 @@ class AstInspector implements vscode.HoverProvider, vscode.DefinitionProvider, D | |||
206 | } | 206 | } |
207 | 207 | ||
208 | private parseRustTextRange(doc: vscode.TextDocument, astLine: string): undefined | vscode.Range { | 208 | private parseRustTextRange(doc: vscode.TextDocument, astLine: string): undefined | vscode.Range { |
209 | const parsedRange = /\[(\d+); (\d+)\)/.exec(astLine); | 209 | const parsedRange = /(\d+)\.\.(\d+)/.exec(astLine); |
210 | if (!parsedRange) return; | 210 | if (!parsedRange) return; |
211 | 211 | ||
212 | const [begin, end] = parsedRange | 212 | const [begin, end] = parsedRange |
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index fe3eb85de..394a7bc88 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs | |||
@@ -230,6 +230,7 @@ pub(crate) struct AstSrc<'a> { | |||
230 | } | 230 | } |
231 | 231 | ||
232 | pub(crate) struct AstNodeSrc<'a> { | 232 | pub(crate) struct AstNodeSrc<'a> { |
233 | pub(crate) doc: &'a [&'a str], | ||
233 | pub(crate) name: &'a str, | 234 | pub(crate) name: &'a str, |
234 | pub(crate) traits: &'a [&'a str], | 235 | pub(crate) traits: &'a [&'a str], |
235 | pub(crate) fields: &'a [Field<'a>], | 236 | pub(crate) fields: &'a [Field<'a>], |
@@ -247,6 +248,7 @@ pub(crate) enum FieldSrc<'a> { | |||
247 | } | 248 | } |
248 | 249 | ||
249 | pub(crate) struct AstEnumSrc<'a> { | 250 | pub(crate) struct AstEnumSrc<'a> { |
251 | pub(crate) doc: &'a [&'a str], | ||
250 | pub(crate) name: &'a str, | 252 | pub(crate) name: &'a str, |
251 | pub(crate) traits: &'a [&'a str], | 253 | pub(crate) traits: &'a [&'a str], |
252 | pub(crate) variants: &'a [&'a str], | 254 | pub(crate) variants: &'a [&'a str], |
@@ -254,12 +256,14 @@ pub(crate) struct AstEnumSrc<'a> { | |||
254 | 256 | ||
255 | macro_rules! ast_nodes { | 257 | macro_rules! ast_nodes { |
256 | ($( | 258 | ($( |
259 | $(#[doc = $doc:expr])+ | ||
257 | struct $name:ident$(: $($trait:ident),*)? { | 260 | struct $name:ident$(: $($trait:ident),*)? { |
258 | $($field_name:ident $(![$token:tt])? $(: $ty:tt)?),*$(,)? | 261 | $($field_name:ident $(![$token:tt])? $(: $ty:tt)?),*$(,)? |
259 | } | 262 | } |
260 | )*) => { | 263 | )*) => { |
261 | [$( | 264 | [$( |
262 | AstNodeSrc { | 265 | AstNodeSrc { |
266 | doc: &[$($doc),*], | ||
263 | name: stringify!($name), | 267 | name: stringify!($name), |
264 | traits: &[$($(stringify!($trait)),*)?], | 268 | traits: &[$($(stringify!($trait)),*)?], |
265 | fields: &[ | 269 | fields: &[ |
@@ -288,12 +292,14 @@ macro_rules! field { | |||
288 | 292 | ||
289 | macro_rules! ast_enums { | 293 | macro_rules! ast_enums { |
290 | ($( | 294 | ($( |
295 | $(#[doc = $doc:expr])+ | ||
291 | enum $name:ident $(: $($trait:ident),*)? { | 296 | enum $name:ident $(: $($trait:ident),*)? { |
292 | $($variant:ident),*$(,)? | 297 | $($variant:ident),*$(,)? |
293 | } | 298 | } |
294 | )*) => { | 299 | )*) => { |
295 | [$( | 300 | [$( |
296 | AstEnumSrc { | 301 | AstEnumSrc { |
302 | doc: &[$($doc),*], | ||
297 | name: stringify!($name), | 303 | name: stringify!($name), |
298 | traits: &[$($(stringify!($trait)),*)?], | 304 | traits: &[$($(stringify!($trait)),*)?], |
299 | variants: &[$(stringify!($variant)),*], | 305 | variants: &[$(stringify!($variant)),*], |
@@ -305,10 +311,35 @@ macro_rules! ast_enums { | |||
305 | pub(crate) const AST_SRC: AstSrc = AstSrc { | 311 | pub(crate) const AST_SRC: AstSrc = AstSrc { |
306 | tokens: &["Whitespace", "Comment", "String", "RawString"], | 312 | tokens: &["Whitespace", "Comment", "String", "RawString"], |
307 | nodes: &ast_nodes! { | 313 | nodes: &ast_nodes! { |
314 | /// The entire Rust source file. Includes all top-level inner attributes and module items. | ||
315 | /// | ||
316 | /// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html) | ||
308 | struct SourceFile: ModuleItemOwner, AttrsOwner, DocCommentsOwner { | 317 | struct SourceFile: ModuleItemOwner, AttrsOwner, DocCommentsOwner { |
309 | modules: [Module], | 318 | modules: [Module], |
310 | } | 319 | } |
311 | 320 | ||
321 | /// Function definition either with body or not. | ||
322 | /// Includes all of its attributes and doc comments. | ||
323 | /// | ||
324 | /// ``` | ||
325 | /// ❰ | ||
326 | /// /// Docs | ||
327 | /// #[attr] | ||
328 | /// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32 | ||
329 | /// where | ||
330 | /// T: Debug | ||
331 | /// { | ||
332 | /// 42 | ||
333 | /// } | ||
334 | /// ❱ | ||
335 | /// | ||
336 | /// extern "C" { | ||
337 | /// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱ | ||
338 | /// } | ||
339 | /// ``` | ||
340 | /// | ||
341 | /// - [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
342 | /// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions) | ||
312 | struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner { | 343 | struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner { |
313 | Abi, | 344 | Abi, |
314 | T![const], | 345 | T![const], |
@@ -322,42 +353,201 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
322 | T![;] | 353 | T![;] |
323 | } | 354 | } |
324 | 355 | ||
356 | /// Return type annotation. | ||
357 | /// | ||
358 | /// ``` | ||
359 | /// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) } | ||
360 | /// ``` | ||
361 | /// | ||
362 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
325 | struct RetType { T![->], TypeRef } | 363 | struct RetType { T![->], TypeRef } |
326 | 364 | ||
365 | /// Struct definition. | ||
366 | /// Includes all of its attributes and doc comments. | ||
367 | /// | ||
368 | /// ``` | ||
369 | /// ❰ | ||
370 | /// /// Docs | ||
371 | /// #[attr] | ||
372 | /// struct Foo<T> where T: Debug { | ||
373 | /// /// Docs | ||
374 | /// #[attr] | ||
375 | /// pub a: u32, | ||
376 | /// b: T, | ||
377 | /// } | ||
378 | /// ❱ | ||
379 | /// | ||
380 | /// ❰ struct Foo; ❱ | ||
381 | /// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱ | ||
382 | /// ``` | ||
383 | /// | ||
384 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
327 | struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { | 385 | struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { |
328 | T![struct], | 386 | T![struct], |
329 | FieldDefList, | 387 | FieldDefList, |
330 | T![;] | 388 | T![;] |
331 | } | 389 | } |
332 | 390 | ||
391 | /// Union definition. | ||
392 | /// Includes all of its attributes and doc comments. | ||
393 | /// | ||
394 | /// ``` | ||
395 | /// ❰ | ||
396 | /// /// Docs | ||
397 | /// #[attr] | ||
398 | /// pub union Foo<T> where T: Debug { | ||
399 | /// /// Docs | ||
400 | /// #[attr] | ||
401 | /// a: T, | ||
402 | /// b: u32, | ||
403 | /// } | ||
404 | /// ❱ | ||
405 | /// ``` | ||
406 | /// | ||
407 | /// [Reference](https://doc.rust-lang.org/reference/items/unions.html) | ||
333 | struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { | 408 | struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { |
334 | T![union], | 409 | T![union], |
335 | RecordFieldDefList, | 410 | RecordFieldDefList, |
336 | } | 411 | } |
337 | 412 | ||
413 | /// Record field definition list including enclosing curly braces. | ||
414 | /// | ||
415 | /// ``` | ||
416 | /// struct Foo // same for union | ||
417 | /// ❰ | ||
418 | /// { | ||
419 | /// a: u32, | ||
420 | /// b: bool, | ||
421 | /// } | ||
422 | /// ❱ | ||
423 | /// ``` | ||
424 | /// | ||
425 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
338 | struct RecordFieldDefList { T!['{'], fields: [RecordFieldDef], T!['}'] } | 426 | struct RecordFieldDefList { T!['{'], fields: [RecordFieldDef], T!['}'] } |
427 | |||
428 | /// Record field definition including its attributes and doc comments. | ||
429 | /// | ||
430 | /// ` `` | ||
431 | /// same for union | ||
432 | /// struct Foo { | ||
433 | /// ❰ | ||
434 | /// /// Docs | ||
435 | /// #[attr] | ||
436 | /// pub a: u32 | ||
437 | /// ❱ | ||
438 | /// | ||
439 | /// ❰ b: bool ❱ | ||
440 | /// } | ||
441 | /// ``` | ||
442 | /// | ||
443 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
339 | struct RecordFieldDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { } | 444 | struct RecordFieldDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { } |
340 | 445 | ||
446 | /// Tuple field definition list including enclosing parens. | ||
447 | /// | ||
448 | /// ``` | ||
449 | /// struct Foo ❰ (u32, String, Vec<u32>) ❱; | ||
450 | /// ``` | ||
451 | /// | ||
452 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
341 | struct TupleFieldDefList { T!['('], fields: [TupleFieldDef], T![')'] } | 453 | struct TupleFieldDefList { T!['('], fields: [TupleFieldDef], T![')'] } |
454 | |||
455 | /// Tuple field definition including its attributes. | ||
456 | /// | ||
457 | /// ``` | ||
458 | /// struct Foo(❰ #[attr] u32 ❱); | ||
459 | /// ``` | ||
460 | /// | ||
461 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
342 | struct TupleFieldDef: VisibilityOwner, AttrsOwner { | 462 | struct TupleFieldDef: VisibilityOwner, AttrsOwner { |
343 | TypeRef, | 463 | TypeRef, |
344 | } | 464 | } |
345 | 465 | ||
466 | /// Enum definition. | ||
467 | /// Includes all of its attributes and doc comments. | ||
468 | /// | ||
469 | /// ``` | ||
470 | /// ❰ | ||
471 | /// /// Docs | ||
472 | /// #[attr] | ||
473 | /// pub enum Foo<T> where T: Debug { | ||
474 | /// /// Docs | ||
475 | /// #[attr] | ||
476 | /// Bar, | ||
477 | /// Baz(#[attr] u32), | ||
478 | /// Bruh { | ||
479 | /// a: u32, | ||
480 | /// /// Docs | ||
481 | /// #[attr] | ||
482 | /// b: T, | ||
483 | /// } | ||
484 | /// } | ||
485 | /// ❱ | ||
486 | /// ``` | ||
487 | /// | ||
488 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
346 | struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { | 489 | struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { |
347 | T![enum], | 490 | T![enum], |
348 | variant_list: EnumVariantList, | 491 | variant_list: EnumVariantList, |
349 | } | 492 | } |
493 | |||
494 | /// Enum variant definition list including enclosing curly braces. | ||
495 | /// | ||
496 | /// ``` | ||
497 | /// enum Foo | ||
498 | /// ❰ | ||
499 | /// { | ||
500 | /// Bar, | ||
501 | /// Baz(u32), | ||
502 | /// Bruh { | ||
503 | /// a: u32 | ||
504 | /// } | ||
505 | /// } | ||
506 | /// ❱ | ||
507 | /// ``` | ||
508 | /// | ||
509 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
350 | struct EnumVariantList { | 510 | struct EnumVariantList { |
351 | T!['{'], | 511 | T!['{'], |
352 | variants: [EnumVariant], | 512 | variants: [EnumVariant], |
353 | T!['}'] | 513 | T!['}'] |
354 | } | 514 | } |
515 | |||
516 | /// Enum variant definition including its attributes and discriminant value definition. | ||
517 | /// | ||
518 | /// ``` | ||
519 | /// enum Foo { | ||
520 | /// ❰ | ||
521 | /// /// Docs | ||
522 | /// #[attr] | ||
523 | /// Bar | ||
524 | /// ❱ | ||
525 | /// | ||
526 | /// // same for tuple and record variants | ||
527 | /// } | ||
528 | /// ``` | ||
529 | /// | ||
530 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
355 | struct EnumVariant: VisibilityOwner, NameOwner, DocCommentsOwner, AttrsOwner { | 531 | struct EnumVariant: VisibilityOwner, NameOwner, DocCommentsOwner, AttrsOwner { |
356 | FieldDefList, | 532 | FieldDefList, |
357 | T![=], | 533 | T![=], |
358 | Expr | 534 | Expr |
359 | } | 535 | } |
360 | 536 | ||
537 | /// Trait definition. | ||
538 | /// Includes all of its attributes and doc comments. | ||
539 | /// | ||
540 | /// ``` | ||
541 | /// ❰ | ||
542 | /// /// Docs | ||
543 | /// #[attr] | ||
544 | /// pub unsafe trait Foo<T>: Debug where T: Debug { | ||
545 | /// // ... | ||
546 | /// } | ||
547 | /// ❱ | ||
548 | /// ``` | ||
549 | /// | ||
550 | /// [Reference](https://doc.rust-lang.org/reference/items/traits.html) | ||
361 | struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner { | 551 | struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner { |
362 | T![unsafe], | 552 | T![unsafe], |
363 | T![auto], | 553 | T![auto], |
@@ -365,18 +555,73 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
365 | ItemList, | 555 | ItemList, |
366 | } | 556 | } |
367 | 557 | ||
558 | /// Module definition either with body or not. | ||
559 | /// Includes all of its inner and outer attributes, module items, doc comments. | ||
560 | /// | ||
561 | /// ``` | ||
562 | /// ❰ | ||
563 | /// /// Docs | ||
564 | /// #[attr] | ||
565 | /// pub mod foo; | ||
566 | /// ❱ | ||
567 | /// | ||
568 | /// ❰ | ||
569 | /// /// Docs | ||
570 | /// #[attr] | ||
571 | /// pub mod bar { | ||
572 | /// //! Inner docs | ||
573 | /// #![inner_attr] | ||
574 | /// } | ||
575 | /// ❱ | ||
576 | /// ``` | ||
577 | /// | ||
578 | /// [Reference](https://doc.rust-lang.org/reference/items/modules.html) | ||
368 | struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner { | 579 | struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner { |
369 | T![mod], | 580 | T![mod], |
370 | ItemList, | 581 | ItemList, |
371 | T![;] | 582 | T![;] |
372 | } | 583 | } |
373 | 584 | ||
585 | /// Item defintion list. | ||
586 | /// This is used for both top-level items and impl block items. | ||
587 | /// | ||
588 | /// ``` | ||
589 | /// ❰ | ||
590 | /// fn foo {} | ||
591 | /// struct Bar; | ||
592 | /// enum Baz; | ||
593 | /// trait Bruh; | ||
594 | /// const BRUUH: u32 = 42; | ||
595 | /// ❱ | ||
596 | /// | ||
597 | /// impl Foo | ||
598 | /// ❰ | ||
599 | /// { | ||
600 | /// fn bar() {} | ||
601 | /// const BAZ: u32 = 42; | ||
602 | /// } | ||
603 | /// ❱ | ||
604 | /// ``` | ||
605 | /// | ||
606 | /// [Reference](https://doc.rust-lang.org/reference/items.html) | ||
374 | struct ItemList: ModuleItemOwner { | 607 | struct ItemList: ModuleItemOwner { |
375 | T!['{'], | 608 | T!['{'], |
376 | assoc_items: [AssocItem], | 609 | assoc_items: [AssocItem], |
377 | T!['}'] | 610 | T!['}'] |
378 | } | 611 | } |
379 | 612 | ||
613 | /// Constant variable definition. | ||
614 | /// Includes all of its attributes and doc comments. | ||
615 | /// | ||
616 | /// ``` | ||
617 | /// ❰ | ||
618 | /// /// Docs | ||
619 | /// #[attr] | ||
620 | /// pub const FOO: u32 = 42; | ||
621 | /// ❱ | ||
622 | /// ``` | ||
623 | /// | ||
624 | /// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html) | ||
380 | struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { | 625 | struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { |
381 | T![default], | 626 | T![default], |
382 | T![const], | 627 | T![const], |
@@ -385,6 +630,19 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
385 | T![;] | 630 | T![;] |
386 | } | 631 | } |
387 | 632 | ||
633 | |||
634 | /// Static variable definition. | ||
635 | /// Includes all of its attributes and doc comments. | ||
636 | /// | ||
637 | /// ``` | ||
638 | /// ❰ | ||
639 | /// /// Docs | ||
640 | /// #[attr] | ||
641 | /// pub static mut FOO: u32 = 42; | ||
642 | /// ❱ | ||
643 | /// ``` | ||
644 | /// | ||
645 | /// [Reference](https://doc.rust-lang.org/reference/items/static-items.html) | ||
388 | struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { | 646 | struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { |
389 | T![static], | 647 | T![static], |
390 | T![mut], | 648 | T![mut], |
@@ -393,6 +651,24 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
393 | T![;] | 651 | T![;] |
394 | } | 652 | } |
395 | 653 | ||
654 | /// Type alias definition. | ||
655 | /// Includes associated type clauses with type bounds. | ||
656 | /// | ||
657 | /// ``` | ||
658 | /// ❰ | ||
659 | /// /// Docs | ||
660 | /// #[attr] | ||
661 | /// pub type Foo<T> where T: Debug = T; | ||
662 | /// ❱ | ||
663 | /// | ||
664 | /// trait Bar { | ||
665 | /// ❰ type Baz: Debug; ❱ | ||
666 | /// ❰ type Bruh = String; ❱ | ||
667 | /// ❰ type Bruuh: Debug = u32; ❱ | ||
668 | /// } | ||
669 | /// ``` | ||
670 | /// | ||
671 | /// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html) | ||
396 | struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner { | 672 | struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner { |
397 | T![default], | 673 | T![default], |
398 | T![type], | 674 | T![type], |
@@ -401,6 +677,20 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
401 | T![;] | 677 | T![;] |
402 | } | 678 | } |
403 | 679 | ||
680 | /// Inherent and trait impl definition. | ||
681 | /// Includes all of its inner and outer attributes. | ||
682 | /// | ||
683 | /// ``` | ||
684 | /// ❰ | ||
685 | /// #[attr] | ||
686 | /// unsafe impl<T> const !Foo for Bar where T: Debug { | ||
687 | /// #![inner_attr] | ||
688 | /// // ... | ||
689 | /// } | ||
690 | /// ❱ | ||
691 | /// ``` | ||
692 | /// | ||
693 | /// [Reference](https://doc.rust-lang.org/reference/items/implementations.html) | ||
404 | struct ImplDef: TypeParamsOwner, AttrsOwner, DocCommentsOwner { | 694 | struct ImplDef: TypeParamsOwner, AttrsOwner, DocCommentsOwner { |
405 | T![default], | 695 | T![default], |
406 | T![const], | 696 | T![const], |
@@ -411,76 +701,611 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
411 | ItemList, | 701 | ItemList, |
412 | } | 702 | } |
413 | 703 | ||
704 | |||
705 | /// Parenthesized type reference. | ||
706 | /// Note: parens are only used for grouping, this is not a tuple type. | ||
707 | /// | ||
708 | /// ``` | ||
709 | /// // This is effectively just `u32`. | ||
710 | /// // Single-item tuple must be defined with a trailing comma: `(u32,)` | ||
711 | /// type Foo = ❰ (u32) ❱; | ||
712 | /// | ||
713 | /// let bar: &'static ❰ (dyn Debug) ❱ = "bruh"; | ||
714 | /// ``` | ||
414 | struct ParenType { T!['('], TypeRef, T![')'] } | 715 | struct ParenType { T!['('], TypeRef, T![')'] } |
716 | |||
717 | /// Unnamed tuple type. | ||
718 | /// | ||
719 | /// ``` | ||
720 | /// let foo: ❰ (u32, bool) ❱ = (42, true); | ||
721 | /// ``` | ||
722 | /// | ||
723 | /// [Reference](https://doc.rust-lang.org/reference/types/tuple.html) | ||
415 | struct TupleType { T!['('], fields: [TypeRef], T![')'] } | 724 | struct TupleType { T!['('], fields: [TypeRef], T![')'] } |
725 | |||
726 | /// The never type (i.e. the exclamation point). | ||
727 | /// | ||
728 | /// ``` | ||
729 | /// type T = ❰ ! ❱; | ||
730 | /// | ||
731 | /// fn no_return() -> ❰ ! ❱ { | ||
732 | /// loop {} | ||
733 | /// } | ||
734 | /// ``` | ||
735 | /// | ||
736 | /// [Reference](https://doc.rust-lang.org/reference/types/never.html) | ||
416 | struct NeverType { T![!] } | 737 | struct NeverType { T![!] } |
738 | |||
739 | /// Path to a type. | ||
740 | /// Includes single identifier type names and elaborate paths with | ||
741 | /// generic parameters. | ||
742 | /// | ||
743 | /// ``` | ||
744 | /// type Foo = ❰ String ❱; | ||
745 | /// type Bar = ❰ std::vec::Vec<T> ❱; | ||
746 | /// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱; | ||
747 | /// ``` | ||
748 | /// | ||
749 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
417 | struct PathType { Path } | 750 | struct PathType { Path } |
751 | |||
752 | /// Raw pointer type. | ||
753 | /// | ||
754 | /// ``` | ||
755 | /// type Foo = ❰ *const u32 ❱; | ||
756 | /// type Bar = ❰ *mut u32 ❱; | ||
757 | /// ``` | ||
758 | /// | ||
759 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut) | ||
418 | struct PointerType { T![*], T![const], T![mut], TypeRef } | 760 | struct PointerType { T![*], T![const], T![mut], TypeRef } |
761 | |||
762 | /// Array type. | ||
763 | /// | ||
764 | /// ``` | ||
765 | /// type Foo = ❰ [u32; 24 - 3] ❱; | ||
766 | /// ``` | ||
767 | /// | ||
768 | /// [Reference](https://doc.rust-lang.org/reference/types/array.html) | ||
419 | struct ArrayType { T!['['], TypeRef, T![;], Expr, T![']'] } | 769 | struct ArrayType { T!['['], TypeRef, T![;], Expr, T![']'] } |
770 | |||
771 | /// Slice type. | ||
772 | /// | ||
773 | /// ``` | ||
774 | /// type Foo = ❰ [u8] ❱; | ||
775 | /// ``` | ||
776 | /// | ||
777 | /// [Reference](https://doc.rust-lang.org/reference/types/slice.html) | ||
420 | struct SliceType { T!['['], TypeRef, T![']'] } | 778 | struct SliceType { T!['['], TypeRef, T![']'] } |
779 | |||
780 | /// Reference type. | ||
781 | /// | ||
782 | /// ``` | ||
783 | /// type Foo = ❰ &'static str ❱; | ||
784 | /// ``` | ||
785 | /// | ||
786 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html) | ||
421 | struct ReferenceType { T![&], T![lifetime], T![mut], TypeRef } | 787 | struct ReferenceType { T![&], T![lifetime], T![mut], TypeRef } |
788 | |||
789 | /// Placeholder type (i.e. the underscore). | ||
790 | /// | ||
791 | /// ``` | ||
792 | /// let foo: ❰ _ ❱ = 42_u32; | ||
793 | /// ``` | ||
794 | /// | ||
795 | /// [Reference](https://doc.rust-lang.org/reference/types/inferred.html) | ||
422 | struct PlaceholderType { T![_] } | 796 | struct PlaceholderType { T![_] } |
797 | |||
798 | /// Function pointer type (not to be confused with `Fn*` family of traits). | ||
799 | /// | ||
800 | /// ``` | ||
801 | /// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱; | ||
802 | /// | ||
803 | /// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱; | ||
804 | /// ``` | ||
805 | /// | ||
806 | /// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html) | ||
423 | struct FnPointerType { Abi, T![unsafe], T![fn], ParamList, RetType } | 807 | struct FnPointerType { Abi, T![unsafe], T![fn], ParamList, RetType } |
808 | |||
809 | /// Higher order type. | ||
810 | /// | ||
811 | /// ``` | ||
812 | /// type Foo = ❰ for<'a> fn(&'a str) ❱; | ||
813 | /// ``` | ||
814 | /// | ||
815 | /// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html) | ||
424 | struct ForType { T![for], TypeParamList, TypeRef } | 816 | struct ForType { T![for], TypeParamList, TypeRef } |
817 | |||
818 | /// Opaque `impl Trait` type. | ||
819 | /// | ||
820 | /// ``` | ||
821 | /// fn foo(bar: ❰ impl Debug + Eq ❱) {} | ||
822 | /// ``` | ||
823 | /// | ||
824 | /// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html) | ||
425 | struct ImplTraitType: TypeBoundsOwner { T![impl] } | 825 | struct ImplTraitType: TypeBoundsOwner { T![impl] } |
826 | |||
827 | /// Trait object type. | ||
828 | /// | ||
829 | /// ``` | ||
830 | /// type Foo = ❰ dyn Debug ❱; | ||
831 | /// ``` | ||
832 | /// | ||
833 | /// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html) | ||
426 | struct DynTraitType: TypeBoundsOwner { T![dyn] } | 834 | struct DynTraitType: TypeBoundsOwner { T![dyn] } |
427 | 835 | ||
836 | /// Tuple literal. | ||
837 | /// | ||
838 | /// ``` | ||
839 | /// ❰ (42, true) ❱; | ||
840 | /// ``` | ||
841 | /// | ||
842 | /// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html) | ||
428 | struct TupleExpr: AttrsOwner { T!['('], exprs: [Expr], T![')'] } | 843 | struct TupleExpr: AttrsOwner { T!['('], exprs: [Expr], T![')'] } |
844 | |||
845 | /// Array literal. | ||
846 | /// | ||
847 | /// ``` | ||
848 | /// ❰ [#![inner_attr] true, false, true] ❱; | ||
849 | /// | ||
850 | /// ❰ ["baz"; 24] ❱; | ||
851 | /// ``` | ||
852 | /// | ||
853 | /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) | ||
429 | struct ArrayExpr: AttrsOwner { T!['['], exprs: [Expr], T![;], T![']'] } | 854 | struct ArrayExpr: AttrsOwner { T!['['], exprs: [Expr], T![;], T![']'] } |
855 | |||
856 | /// Parenthesized expression. | ||
857 | /// Note: parens are only used for grouping, this is not a tuple literal. | ||
858 | /// | ||
859 | /// ``` | ||
860 | /// ❰ (#![inner_attr] 2 + 2) ❱ * 2; | ||
861 | /// ``` | ||
862 | /// | ||
863 | /// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html) | ||
430 | struct ParenExpr: AttrsOwner { T!['('], Expr, T![')'] } | 864 | struct ParenExpr: AttrsOwner { T!['('], Expr, T![')'] } |
431 | struct PathExpr { Path } | 865 | |
866 | /// Path to a symbol in expression context. | ||
867 | /// Includes single identifier variable names and elaborate paths with | ||
868 | /// generic parameters. | ||
869 | /// | ||
870 | /// ``` | ||
871 | /// ❰ Some::<i32> ❱; | ||
872 | /// ❰ foo ❱ + 42; | ||
873 | /// ❰ Vec::<i32>::push ❱; | ||
874 | /// ❰ <[i32]>::reverse ❱; | ||
875 | /// ❰ <String as std::borrow::Borrow<str>>::borrow ❱; | ||
876 | /// ``` | ||
877 | /// | ||
878 | /// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html) | ||
879 | struct PathExpr { Path } | ||
880 | |||
881 | /// Anonymous callable object literal a.k.a. closure, lambda or functor. | ||
882 | /// | ||
883 | /// ``` | ||
884 | /// ❰ || 42 ❱; | ||
885 | /// ❰ |a: u32| val + 1 ❱; | ||
886 | /// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱; | ||
887 | /// ❰ move || baz ❱; | ||
888 | /// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱ | ||
889 | /// ``` | ||
890 | /// | ||
891 | /// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html) | ||
432 | struct LambdaExpr: AttrsOwner { | 892 | struct LambdaExpr: AttrsOwner { |
433 | T![static], | 893 | T![static], // Note(@matklad): I belive this is (used to be?) syntax for generators |
434 | T![async], | 894 | T![async], |
435 | T![move], | 895 | T![move], |
436 | ParamList, | 896 | ParamList, |
437 | RetType, | 897 | RetType, |
438 | body: Expr, | 898 | body: Expr, |
439 | } | 899 | } |
900 | |||
901 | /// If expression. Includes both regular `if` and `if let` forms. | ||
902 | /// Beware that `else if` is a special case syntax sugar, because in general | ||
903 | /// there has to be block expression after `else`. | ||
904 | /// | ||
905 | /// ``` | ||
906 | /// ❰ if bool_cond { 42 } ❱ | ||
907 | /// ❰ if bool_cond { 42 } else { 24 } ❱ | ||
908 | /// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱ | ||
909 | /// | ||
910 | /// ❰ | ||
911 | /// if let Pattern(foo) = bar { | ||
912 | /// foo | ||
913 | /// } else { | ||
914 | /// panic!(); | ||
915 | /// } | ||
916 | /// ❱ | ||
917 | /// ``` | ||
918 | /// | ||
919 | /// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
440 | struct IfExpr: AttrsOwner { T![if], Condition } | 920 | struct IfExpr: AttrsOwner { T![if], Condition } |
921 | |||
922 | /// Unconditional loop expression. | ||
923 | /// | ||
924 | /// ``` | ||
925 | /// ❰ | ||
926 | /// loop { | ||
927 | /// // yeah, it's that simple... | ||
928 | /// } | ||
929 | /// ❱ | ||
930 | /// ``` | ||
931 | /// | ||
932 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html) | ||
441 | struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] } | 933 | struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] } |
934 | |||
935 | /// Block expression with an optional prefix (label, try ketword, | ||
936 | /// unsafe keyword, async keyword...). | ||
937 | /// | ||
938 | /// ``` | ||
939 | /// ❰ | ||
940 | /// 'label: try { | ||
941 | /// None? | ||
942 | /// } | ||
943 | /// ❱ | ||
944 | /// ``` | ||
945 | /// | ||
946 | /// - [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) | ||
948 | /// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks) | ||
442 | struct EffectExpr: AttrsOwner { Label, T![try], T![unsafe], T![async], BlockExpr } | 949 | struct EffectExpr: AttrsOwner { Label, T![try], T![unsafe], T![async], BlockExpr } |
950 | |||
951 | |||
952 | /// For loop expression. | ||
953 | /// Note: record struct literals are not valid as iterable expression | ||
954 | /// due to ambiguity. | ||
955 | /// | ||
956 | /// ``` | ||
957 | /// ❰ | ||
958 | /// for i in (0..4) { | ||
959 | /// dbg!(i); | ||
960 | /// } | ||
961 | /// ❱ | ||
962 | /// ``` | ||
963 | /// | ||
964 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops) | ||
443 | struct ForExpr: AttrsOwner, LoopBodyOwner { | 965 | struct ForExpr: AttrsOwner, LoopBodyOwner { |
444 | T![for], | 966 | T![for], |
445 | Pat, | 967 | Pat, |
446 | T![in], | 968 | T![in], |
447 | iterable: Expr, | 969 | iterable: Expr, |
448 | } | 970 | } |
971 | |||
972 | /// While loop expression. Includes both regular `while` and `while let` forms. | ||
973 | /// | ||
974 | /// ``` | ||
975 | /// ❰ | ||
976 | /// while bool_cond { | ||
977 | /// 42; | ||
978 | /// } | ||
979 | /// ❱ | ||
980 | /// ❰ | ||
981 | /// while let Pattern(foo) = bar { | ||
982 | /// bar += 1; | ||
983 | /// } | ||
984 | /// ❱ | ||
985 | /// ``` | ||
986 | /// | ||
987 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
449 | struct WhileExpr: AttrsOwner, LoopBodyOwner { T![while], Condition } | 988 | struct WhileExpr: AttrsOwner, LoopBodyOwner { T![while], Condition } |
989 | |||
990 | /// Continue expression. | ||
991 | /// | ||
992 | /// ``` | ||
993 | /// while bool_cond { | ||
994 | /// ❰ continue ❱; | ||
995 | /// } | ||
996 | /// | ||
997 | /// 'outer: loop { | ||
998 | /// loop { | ||
999 | /// ❰ continue 'outer ❱; | ||
1000 | /// } | ||
1001 | /// } | ||
1002 | /// | ||
1003 | /// ``` | ||
1004 | /// | ||
1005 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions) | ||
450 | struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } | 1006 | struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } |
1007 | |||
1008 | /// Break expression. | ||
1009 | /// | ||
1010 | /// ``` | ||
1011 | /// while bool_cond { | ||
1012 | /// ❰ break ❱; | ||
1013 | /// } | ||
1014 | /// 'outer: loop { | ||
1015 | /// for foo in bar { | ||
1016 | /// ❰ break 'outer ❱; | ||
1017 | /// } | ||
1018 | /// } | ||
1019 | /// 'outer: loop { | ||
1020 | /// loop { | ||
1021 | /// ❰ break 'outer 42 ❱; | ||
1022 | /// } | ||
1023 | /// } | ||
1024 | /// ``` | ||
1025 | /// | ||
1026 | /// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions) | ||
451 | struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } | 1027 | struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } |
1028 | |||
1029 | /// Label. | ||
1030 | /// | ||
1031 | /// ``` | ||
1032 | /// ❰ 'outer: ❱ loop {} | ||
1033 | /// | ||
1034 | /// let foo = ❰ 'bar: ❱ loop {} | ||
1035 | /// | ||
1036 | /// ❰ 'baz: ❱ { | ||
1037 | /// break 'baz; | ||
1038 | /// } | ||
1039 | /// ``` | ||
1040 | /// | ||
1041 | /// [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) | ||
452 | struct Label { T![lifetime] } | 1043 | struct Label { T![lifetime] } |
1044 | |||
1045 | /// Block expression. Includes unsafe blocks and block labels. | ||
1046 | /// | ||
1047 | /// ``` | ||
1048 | /// let foo = ❰ | ||
1049 | /// { | ||
1050 | /// #![inner_attr] | ||
1051 | /// ❰ { } ❱ | ||
1052 | /// | ||
1053 | /// ❰ 'label: { break 'label } ❱ | ||
1054 | /// } | ||
1055 | /// ❱; | ||
1056 | /// ``` | ||
1057 | /// | ||
1058 | /// [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) | ||
453 | struct BlockExpr: AttrsOwner, ModuleItemOwner { | 1060 | struct BlockExpr: AttrsOwner, ModuleItemOwner { |
454 | T!['{'], statements: [Stmt], Expr, T!['}'], | 1061 | T!['{'], statements: [Stmt], Expr, T!['}'], |
455 | } | 1062 | } |
1063 | |||
1064 | /// Return expression. | ||
1065 | /// | ||
1066 | /// ``` | ||
1067 | /// || ❰ return 42 ❱; | ||
1068 | /// | ||
1069 | /// fn bar() { | ||
1070 | /// ❰ return ❱; | ||
1071 | /// } | ||
1072 | /// ``` | ||
1073 | /// | ||
1074 | /// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html) | ||
456 | struct ReturnExpr: AttrsOwner { Expr } | 1075 | struct ReturnExpr: AttrsOwner { Expr } |
1076 | |||
1077 | /// Call expression (not to be confused with method call expression, it is | ||
1078 | /// a separate ast node). | ||
1079 | /// | ||
1080 | /// ``` | ||
1081 | /// ❰ foo() ❱; | ||
1082 | /// ❰ &str::len("bar") ❱; | ||
1083 | /// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱; | ||
1084 | /// ``` | ||
1085 | /// | ||
1086 | /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) | ||
457 | struct CallExpr: ArgListOwner { Expr } | 1087 | struct CallExpr: ArgListOwner { Expr } |
1088 | |||
1089 | /// Method call expression. | ||
1090 | /// | ||
1091 | /// ``` | ||
1092 | /// ❰ receiver_expr.method() ❱; | ||
1093 | /// ❰ receiver_expr.method::<T>(42, true) ❱; | ||
1094 | /// | ||
1095 | /// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱; | ||
1096 | /// ``` | ||
1097 | /// | ||
1098 | /// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html) | ||
458 | struct MethodCallExpr: AttrsOwner, ArgListOwner { | 1099 | struct MethodCallExpr: AttrsOwner, ArgListOwner { |
459 | Expr, T![.], NameRef, TypeArgList, | 1100 | Expr, T![.], NameRef, TypeArgList, |
460 | } | 1101 | } |
1102 | |||
1103 | /// Index expression a.k.a. subscript operator call. | ||
1104 | /// | ||
1105 | /// ``` | ||
1106 | /// ❰ foo[42] ❱; | ||
1107 | /// ``` | ||
1108 | /// | ||
1109 | /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) | ||
461 | struct IndexExpr: AttrsOwner { T!['['], T![']'] } | 1110 | struct IndexExpr: AttrsOwner { T!['['], T![']'] } |
1111 | |||
1112 | /// Field access expression. | ||
1113 | /// | ||
1114 | /// ``` | ||
1115 | /// ❰ expr.bar ❱; | ||
1116 | /// | ||
1117 | /// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱; | ||
1118 | /// ``` | ||
1119 | /// | ||
1120 | /// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html) | ||
462 | struct FieldExpr: AttrsOwner { Expr, T![.], NameRef } | 1121 | struct FieldExpr: AttrsOwner { Expr, T![.], NameRef } |
1122 | |||
1123 | /// Await operator call expression. | ||
1124 | /// | ||
1125 | /// ``` | ||
1126 | /// ❰ expr.await ❱; | ||
1127 | /// ``` | ||
1128 | /// | ||
1129 | /// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html) | ||
463 | struct AwaitExpr: AttrsOwner { Expr, T![.], T![await] } | 1130 | struct AwaitExpr: AttrsOwner { Expr, T![.], T![await] } |
1131 | |||
1132 | /// The question mark operator call. | ||
1133 | /// | ||
1134 | /// ``` | ||
1135 | /// ❰ expr? ❱; | ||
1136 | /// ``` | ||
1137 | /// | ||
1138 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator) | ||
464 | struct TryExpr: AttrsOwner { Expr, T![?] } | 1139 | struct TryExpr: AttrsOwner { Expr, T![?] } |
1140 | |||
1141 | /// Type cast expression. | ||
1142 | /// | ||
1143 | /// ``` | ||
1144 | /// ❰ expr as T ❱; | ||
1145 | /// ``` | ||
1146 | /// | ||
1147 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions) | ||
465 | struct CastExpr: AttrsOwner { Expr, T![as], TypeRef } | 1148 | struct CastExpr: AttrsOwner { Expr, T![as], TypeRef } |
1149 | |||
1150 | |||
1151 | /// Borrow operator call. | ||
1152 | /// | ||
1153 | /// ``` | ||
1154 | /// ❰ &foo ❱; | ||
1155 | /// ❰ &mut bar ❱; | ||
1156 | /// ``` | ||
1157 | /// | ||
1158 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators) | ||
466 | struct RefExpr: AttrsOwner { T![&], T![raw], T![mut], Expr } | 1159 | struct RefExpr: AttrsOwner { T![&], T![raw], T![mut], Expr } |
1160 | |||
1161 | /// Prefix operator call. This is either `!` or `*` or `-`. | ||
1162 | /// | ||
1163 | /// ``` | ||
1164 | /// ❰ !foo ❱; | ||
1165 | /// ❰ *bar ❱; | ||
1166 | /// ❰ -42 ❱; | ||
1167 | /// ``` | ||
1168 | /// | ||
1169 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html) | ||
467 | struct PrefixExpr: AttrsOwner { /*PrefixOp,*/ Expr } | 1170 | struct PrefixExpr: AttrsOwner { /*PrefixOp,*/ Expr } |
1171 | |||
1172 | /// Box operator call. | ||
1173 | /// | ||
1174 | /// ``` | ||
1175 | /// ❰ box 42 ❱; | ||
1176 | /// ``` | ||
1177 | /// | ||
1178 | /// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md) | ||
468 | struct BoxExpr: AttrsOwner { T![box], Expr } | 1179 | struct BoxExpr: AttrsOwner { T![box], Expr } |
1180 | |||
1181 | /// Range operator call. | ||
1182 | /// | ||
1183 | /// ``` | ||
1184 | /// ❰ 0..42 ❱; | ||
1185 | /// ❰ ..42 ❱; | ||
1186 | /// ❰ 0.. ❱; | ||
1187 | /// ❰ .. ❱; | ||
1188 | /// ❰ 0..=42 ❱; | ||
1189 | /// ❰ ..=42 ❱; | ||
1190 | /// ``` | ||
1191 | /// | ||
1192 | /// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html) | ||
469 | struct RangeExpr: AttrsOwner { /*RangeOp*/ } | 1193 | struct RangeExpr: AttrsOwner { /*RangeOp*/ } |
1194 | |||
1195 | |||
1196 | /// Binary operator call. | ||
1197 | /// Includes all arithmetic, logic, bitwise and assignment operators. | ||
1198 | /// | ||
1199 | /// ``` | ||
1200 | /// ❰ 2 + ❰ 2 * 2 ❱ ❱; | ||
1201 | /// ❰ ❰ true && false ❱ || true ❱; | ||
1202 | /// ``` | ||
1203 | /// | ||
1204 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators) | ||
470 | struct BinExpr: AttrsOwner { /*BinOp*/ } | 1205 | struct BinExpr: AttrsOwner { /*BinOp*/ } |
1206 | |||
1207 | |||
1208 | /// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal. | ||
1209 | /// | ||
1210 | /// ``` | ||
1211 | /// ❰ "str" ❱; | ||
1212 | /// ❰ br##"raw byte str"## ❱; | ||
1213 | /// ❰ 'c' ❱; | ||
1214 | /// ❰ b'c' ❱; | ||
1215 | /// ❰ 42 ❱; | ||
1216 | /// ❰ 1e9 ❱; | ||
1217 | /// ❰ true ❱; | ||
1218 | /// ``` | ||
1219 | /// | ||
1220 | /// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html) | ||
471 | struct Literal { /*LiteralToken*/ } | 1221 | struct Literal { /*LiteralToken*/ } |
472 | 1222 | ||
1223 | /// Match expression. | ||
1224 | /// | ||
1225 | /// ``` | ||
1226 | /// ❰ | ||
1227 | /// match expr { | ||
1228 | /// Pat1 => {} | ||
1229 | /// Pat2(_) => 42, | ||
1230 | /// } | ||
1231 | /// ❱ | ||
1232 | /// ``` | ||
1233 | /// | ||
1234 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
473 | struct MatchExpr: AttrsOwner { T![match], Expr, MatchArmList } | 1235 | struct MatchExpr: AttrsOwner { T![match], Expr, MatchArmList } |
1236 | |||
1237 | /// Match arm list part of match expression. Includes its inner attributes. | ||
1238 | /// | ||
1239 | /// ``` | ||
1240 | /// match expr | ||
1241 | /// ❰ | ||
1242 | /// { | ||
1243 | /// #![inner_attr] | ||
1244 | /// Pat1 => {} | ||
1245 | /// Pat2(_) => 42, | ||
1246 | /// } | ||
1247 | /// ❱ | ||
1248 | /// ``` | ||
1249 | /// | ||
1250 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
474 | struct MatchArmList: AttrsOwner { T!['{'], arms: [MatchArm], T!['}'] } | 1251 | struct MatchArmList: AttrsOwner { T!['{'], arms: [MatchArm], T!['}'] } |
1252 | |||
1253 | |||
1254 | /// Match arm. | ||
1255 | /// Note: record struct literals are not valid as target match expression | ||
1256 | /// due to ambiguity. | ||
1257 | /// ``` | ||
1258 | /// match expr { | ||
1259 | /// ❰ #[attr] Pattern(it) if bool_cond => it ❱, | ||
1260 | /// } | ||
1261 | /// ``` | ||
1262 | /// | ||
1263 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
475 | struct MatchArm: AttrsOwner { | 1264 | struct MatchArm: AttrsOwner { |
476 | pat: Pat, | 1265 | pat: Pat, |
477 | guard: MatchGuard, | 1266 | guard: MatchGuard, |
478 | T![=>], | 1267 | T![=>], |
479 | Expr, | 1268 | Expr, |
480 | } | 1269 | } |
1270 | |||
1271 | /// Match guard. | ||
1272 | /// | ||
1273 | /// ``` | ||
1274 | /// match expr { | ||
1275 | /// Pattern(it) ❰ if bool_cond ❱ => it, | ||
1276 | /// } | ||
1277 | /// ``` | ||
1278 | /// | ||
1279 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards) | ||
481 | struct MatchGuard { T![if], Expr } | 1280 | struct MatchGuard { T![if], Expr } |
482 | 1281 | ||
1282 | /// Record literal expression. The same syntax is used for structs, | ||
1283 | /// unions and record enum variants. | ||
1284 | /// | ||
1285 | /// ``` | ||
1286 | /// ❰ | ||
1287 | /// foo::Bar { | ||
1288 | /// #![inner_attr] | ||
1289 | /// baz: 42, | ||
1290 | /// bruh: true, | ||
1291 | /// ..spread | ||
1292 | /// } | ||
1293 | /// ❱ | ||
1294 | /// ``` | ||
1295 | /// | ||
1296 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
483 | struct RecordLit { Path, RecordFieldList} | 1297 | struct RecordLit { Path, RecordFieldList} |
1298 | |||
1299 | /// Record field list including enclosing curly braces. | ||
1300 | /// | ||
1301 | /// foo::Bar ❰ | ||
1302 | /// { | ||
1303 | /// baz: 42, | ||
1304 | /// ..spread | ||
1305 | /// } | ||
1306 | /// ❱ | ||
1307 | /// | ||
1308 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
484 | struct RecordFieldList { | 1309 | struct RecordFieldList { |
485 | T!['{'], | 1310 | T!['{'], |
486 | fields: [RecordField], | 1311 | fields: [RecordField], |
@@ -488,22 +1313,162 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
488 | spread: Expr, | 1313 | spread: Expr, |
489 | T!['}'] | 1314 | T!['}'] |
490 | } | 1315 | } |
1316 | |||
1317 | /// Record field. | ||
1318 | /// | ||
1319 | /// ``` | ||
1320 | /// foo::Bar { | ||
1321 | /// ❰ #[attr] baz: 42 ❱ | ||
1322 | /// } | ||
1323 | /// ``` | ||
1324 | /// | ||
1325 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
491 | struct RecordField: AttrsOwner { NameRef, T![:], Expr } | 1326 | struct RecordField: AttrsOwner { NameRef, T![:], Expr } |
492 | 1327 | ||
1328 | /// Disjunction of patterns. | ||
1329 | /// | ||
1330 | /// ``` | ||
1331 | /// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh; | ||
1332 | /// ``` | ||
1333 | /// | ||
1334 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html) | ||
493 | struct OrPat { pats: [Pat] } | 1335 | struct OrPat { pats: [Pat] } |
1336 | |||
1337 | /// Parenthesized pattern. | ||
1338 | /// Note: parens are only used for grouping, this is not a tuple pattern. | ||
1339 | /// | ||
1340 | /// ``` | ||
1341 | /// if let ❰ &(0..=42) ❱ = foo {} | ||
1342 | /// ``` | ||
1343 | /// | ||
1344 | /// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns | ||
494 | struct ParenPat { T!['('], Pat, T![')'] } | 1345 | struct ParenPat { T!['('], Pat, T![')'] } |
1346 | |||
1347 | /// Reference pattern. | ||
1348 | /// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns. | ||
1349 | /// | ||
1350 | /// ``` | ||
1351 | /// let ❰ &mut foo ❱ = bar; | ||
1352 | /// | ||
1353 | /// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz; | ||
1354 | /// ``` | ||
1355 | /// | ||
1356 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns) | ||
495 | struct RefPat { T![&], T![mut], Pat } | 1357 | struct RefPat { T![&], T![mut], Pat } |
1358 | |||
1359 | /// Box pattern. | ||
1360 | /// | ||
1361 | /// ``` | ||
1362 | /// let ❰ box foo ❱ = box 42; | ||
1363 | /// ``` | ||
1364 | /// | ||
1365 | /// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html) | ||
496 | struct BoxPat { T![box], Pat } | 1366 | struct BoxPat { T![box], Pat } |
1367 | |||
1368 | /// Bind pattern. | ||
1369 | /// | ||
1370 | /// ``` | ||
1371 | /// match foo { | ||
1372 | /// Some(❰ ref mut bar ❱) => {} | ||
1373 | /// ❰ baz @ None ❱ => {} | ||
1374 | /// } | ||
1375 | /// ``` | ||
1376 | /// | ||
1377 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns) | ||
497 | struct BindPat: AttrsOwner, NameOwner { T![ref], T![mut], T![@], Pat } | 1378 | struct BindPat: AttrsOwner, NameOwner { T![ref], T![mut], T![@], Pat } |
1379 | |||
1380 | /// Placeholder pattern a.k.a. the wildcard pattern or the underscore. | ||
1381 | /// | ||
1382 | /// ``` | ||
1383 | /// let ❰ _ ❱ = foo; | ||
1384 | /// ``` | ||
1385 | /// | ||
1386 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern) | ||
498 | struct PlaceholderPat { T![_] } | 1387 | struct PlaceholderPat { T![_] } |
1388 | |||
1389 | /// Rest-of-the record/tuple pattern. | ||
1390 | /// Note: this is not the unbonded range pattern (even more: it doesn't exist). | ||
1391 | /// | ||
1392 | /// ``` | ||
1393 | /// let Foo { bar, ❰ .. ❱ } = baz; | ||
1394 | /// let (❰ .. ❱, bruh) = (42, 24, 42); | ||
1395 | /// let Bruuh(❰ .. ❱) = bruuuh; | ||
1396 | /// ``` | ||
1397 | /// | ||
1398 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
499 | struct DotDotPat { T![..] } | 1399 | struct DotDotPat { T![..] } |
1400 | |||
1401 | /// Path pattern. | ||
1402 | /// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`). | ||
1403 | /// | ||
1404 | /// ``` | ||
1405 | /// let ❰ foo::bar::Baz ❱ { .. } = bruh; | ||
1406 | /// if let ❰ CONST ❱ = 42 {} | ||
1407 | /// ``` | ||
1408 | /// | ||
1409 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns) | ||
500 | struct PathPat { Path } | 1410 | struct PathPat { Path } |
1411 | |||
1412 | /// Slice pattern. | ||
1413 | /// | ||
1414 | /// ``` | ||
1415 | /// let ❰ [foo, bar, baz] ❱ = [1, 2, 3]; | ||
1416 | /// ``` | ||
1417 | /// | ||
1418 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns) | ||
501 | struct SlicePat { T!['['], args: [Pat], T![']'] } | 1419 | struct SlicePat { T!['['], args: [Pat], T![']'] } |
502 | struct RangePat { /*RangeSeparator*/ } | 1420 | |
1421 | /// Range pattern. | ||
1422 | /// | ||
1423 | /// ``` | ||
1424 | /// match foo { | ||
1425 | /// ❰ 0..42 ❱ => {} | ||
1426 | /// ❰ 0..=42 ❱ => {} | ||
1427 | /// } | ||
1428 | /// ``` | ||
1429 | /// | ||
1430 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns) | ||
1431 | struct RangePat { } // FIXME(@matklad): here should be T![..], T![..=] I think, if we don't already have an accessor in expresions_ext | ||
1432 | |||
1433 | /// Literal pattern. | ||
1434 | /// Includes only bool, number, char, and string literals. | ||
1435 | /// | ||
1436 | /// ``` | ||
1437 | /// match foo { | ||
1438 | /// Number(❰ 42 ❱) => {} | ||
1439 | /// String(❰ "42" ❱) => {} | ||
1440 | /// Bool(❰ true ❱) => {} | ||
1441 | /// } | ||
1442 | /// ``` | ||
1443 | /// | ||
1444 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns) | ||
503 | struct LiteralPat { Literal } | 1445 | struct LiteralPat { Literal } |
1446 | |||
1447 | /// Macro invocation in pattern position. | ||
1448 | /// | ||
1449 | /// ``` | ||
1450 | /// let ❰ foo!(my custom syntax) ❱ = baz; | ||
1451 | /// | ||
1452 | /// ``` | ||
1453 | /// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation) | ||
504 | struct MacroPat { MacroCall } | 1454 | struct MacroPat { MacroCall } |
505 | 1455 | ||
1456 | /// Record literal pattern. | ||
1457 | /// | ||
1458 | /// ``` | ||
1459 | /// let ❰ foo::Bar { baz, .. } ❱ = bruh; | ||
1460 | /// ``` | ||
1461 | /// | ||
1462 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
506 | struct RecordPat { RecordFieldPatList, Path } | 1463 | struct RecordPat { RecordFieldPatList, Path } |
1464 | |||
1465 | /// Record literal's field patterns list including enclosing curly braces. | ||
1466 | /// | ||
1467 | /// ``` | ||
1468 | /// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh; | ||
1469 | /// `` | ||
1470 | /// | ||
1471 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
507 | struct RecordFieldPatList { | 1472 | struct RecordFieldPatList { |
508 | T!['{'], | 1473 | T!['{'], |
509 | pats: [RecordInnerPat], | 1474 | pats: [RecordInnerPat], |
@@ -512,20 +1477,148 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
512 | T![..], | 1477 | T![..], |
513 | T!['}'] | 1478 | T!['}'] |
514 | } | 1479 | } |
1480 | |||
1481 | /// Record literal's field pattern. | ||
1482 | /// Note: record literal can also match tuple structs. | ||
1483 | /// | ||
1484 | /// ``` | ||
1485 | /// let Foo { ❰ bar: _ ❱ } = baz; | ||
1486 | /// let TupleStruct { ❰ 0: _ ❱ } = bruh; | ||
1487 | /// ``` | ||
1488 | /// | ||
1489 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
515 | struct RecordFieldPat: AttrsOwner { NameRef, T![:], Pat } | 1490 | struct RecordFieldPat: AttrsOwner { NameRef, T![:], Pat } |
516 | 1491 | ||
1492 | /// Tuple struct literal pattern. | ||
1493 | /// | ||
1494 | /// ``` | ||
1495 | /// let ❰ foo::Bar(baz, bruh) ❱ = bruuh; | ||
1496 | /// ``` | ||
1497 | /// | ||
1498 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns) | ||
517 | struct TupleStructPat { Path, T!['('], args: [Pat], T![')'] } | 1499 | struct TupleStructPat { Path, T!['('], args: [Pat], T![')'] } |
1500 | |||
1501 | /// Tuple pattern. | ||
1502 | /// Note: this doesn't include tuple structs (see `TupleStructPat`) | ||
1503 | /// | ||
1504 | /// ``` | ||
1505 | /// let ❰ (foo, bar, .., baz) ❱ = bruh; | ||
1506 | /// ``` | ||
1507 | /// | ||
1508 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns) | ||
518 | struct TuplePat { T!['('], args: [Pat], T![')'] } | 1509 | struct TuplePat { T!['('], args: [Pat], T![')'] } |
519 | 1510 | ||
1511 | /// Visibility. | ||
1512 | /// | ||
1513 | /// ``` | ||
1514 | /// ❰ pub mod ❱ foo; | ||
1515 | /// ❰ pub(crate) ❱ struct Bar; | ||
1516 | /// ❰ pub(self) ❱ enum Baz {} | ||
1517 | /// ❰ pub(super) ❱ fn bruh() {} | ||
1518 | /// ❰ pub(in bruuh::bruuuh) ❱ type T = u64; | ||
1519 | /// ``` | ||
1520 | /// | ||
1521 | /// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html) | ||
520 | struct Visibility { T![pub], T![super], T![self], T![crate] } | 1522 | struct Visibility { T![pub], T![super], T![self], T![crate] } |
1523 | |||
1524 | /// Single identifier. | ||
1525 | /// Note(@matklad): `Name` is for things that install a new name into the scope, | ||
1526 | /// `NameRef` is a usage of a name. Most of the time, this definition/reference | ||
1527 | /// distinction can be determined purely syntactically, ie in | ||
1528 | /// ``` | ||
1529 | /// fn foo() { foo() } | ||
1530 | /// ``` | ||
1531 | /// the first foo is `Name`, the second one is `NameRef`. | ||
1532 | /// The notable exception are patterns, where in | ||
1533 | /// `` | ||
1534 | /// let x = 92 | ||
1535 | /// ``` | ||
1536 | /// `x` can be semantically either a name or a name ref, depeding on | ||
1537 | /// wether there's an `x` constant in scope. | ||
1538 | /// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db). | ||
1539 | /// | ||
1540 | /// ``` | ||
1541 | /// let ❰ foo ❱ = bar; | ||
1542 | /// struct ❰ Baz ❱; | ||
1543 | /// fn ❰ bruh ❱() {} | ||
1544 | /// ``` | ||
1545 | /// | ||
1546 | /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) | ||
521 | struct Name { T![ident] } | 1547 | struct Name { T![ident] } |
522 | struct NameRef { /*NameRefToken*/ } | ||
523 | 1548 | ||
524 | struct MacroCall: NameOwner, AttrsOwner,DocCommentsOwner { | 1549 | /// Reference to a name. |
1550 | /// See the explanation on the difference between `Name` and `NameRef` | ||
1551 | /// in `Name` ast node docs. | ||
1552 | /// | ||
1553 | /// ``` | ||
1554 | /// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱; | ||
1555 | /// ``` | ||
1556 | /// | ||
1557 | /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) | ||
1558 | struct NameRef { } | ||
1559 | |||
1560 | /// Macro call. | ||
1561 | /// Includes all of its attributes and doc comments. | ||
1562 | /// | ||
1563 | /// ``` | ||
1564 | /// ❰ | ||
1565 | /// /// Docs | ||
1566 | /// #[attr] | ||
1567 | /// macro_rules! foo { // macro rules is also a macro call | ||
1568 | /// ($bar: tt) => {} | ||
1569 | /// } | ||
1570 | /// ❱ | ||
1571 | /// | ||
1572 | /// // semicolon is a part of `MacroCall` when it is used in item positions | ||
1573 | /// ❰ foo!(); ❱ | ||
1574 | /// | ||
1575 | /// fn main() { | ||
1576 | /// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi | ||
1577 | /// } | ||
1578 | /// ``` | ||
1579 | /// | ||
1580 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
1581 | struct MacroCall: NameOwner, AttrsOwner, DocCommentsOwner { | ||
525 | Path, T![!], TokenTree, T![;] | 1582 | Path, T![!], TokenTree, T![;] |
526 | } | 1583 | } |
1584 | |||
1585 | /// Attribute. | ||
1586 | /// | ||
1587 | /// ``` | ||
1588 | /// ❰ #![inner_attr] ❱ | ||
1589 | /// | ||
1590 | /// ❰ #[attr] ❱ | ||
1591 | /// ❰ #[foo = "bar"] ❱ | ||
1592 | /// ❰ #[baz(bruh::bruuh = "42")] ❱ | ||
1593 | /// struct Foo; | ||
1594 | /// ``` | ||
1595 | /// | ||
1596 | /// [Reference](https://doc.rust-lang.org/reference/attributes.html) | ||
527 | struct Attr { T![#], T![!], T!['['], Path, T![=], input: AttrInput, T![']'] } | 1597 | struct Attr { T![#], T![!], T!['['], Path, T![=], input: AttrInput, T![']'] } |
1598 | |||
1599 | /// Stores a list of lexer tokens and other `TokenTree`s. | ||
1600 | /// It appears in attributes, macro_rules and macro call (foo!) | ||
1601 | /// | ||
1602 | /// ``` | ||
1603 | /// macro_call! ❰ { my syntax here } ❱; | ||
1604 | /// ``` | ||
1605 | /// | ||
1606 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
528 | struct TokenTree {} | 1607 | struct TokenTree {} |
1608 | |||
1609 | /// Generic lifetime, type and constants parameters list **declaration**. | ||
1610 | /// | ||
1611 | /// ``` | ||
1612 | /// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {} | ||
1613 | /// | ||
1614 | /// struct Baz❰ <T> ❱(T); | ||
1615 | /// | ||
1616 | /// impl❰ <T> ❱ Bruh<T> {} | ||
1617 | /// | ||
1618 | /// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str; | ||
1619 | /// ``` | ||
1620 | /// | ||
1621 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
529 | struct TypeParamList { | 1622 | struct TypeParamList { |
530 | T![<], | 1623 | T![<], |
531 | generic_params: [GenericParam], | 1624 | generic_params: [GenericParam], |
@@ -534,21 +1627,141 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
534 | const_params: [ConstParam], | 1627 | const_params: [ConstParam], |
535 | T![>] | 1628 | T![>] |
536 | } | 1629 | } |
1630 | |||
1631 | /// Single type parameter **declaration**. | ||
1632 | /// | ||
1633 | /// ``` | ||
1634 | /// fn foo<❰ K ❱, ❰ I ❱, ❰ E: Debug ❱, ❰ V = DefaultType ❱>() {} | ||
1635 | /// ``` | ||
1636 | /// | ||
1637 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
537 | struct TypeParam: NameOwner, AttrsOwner, TypeBoundsOwner { | 1638 | struct TypeParam: NameOwner, AttrsOwner, TypeBoundsOwner { |
538 | T![=], | 1639 | T![=], |
539 | default_type: TypeRef, | 1640 | default_type: TypeRef, |
540 | } | 1641 | } |
1642 | |||
1643 | /// Const generic parameter **declaration**. | ||
1644 | /// ``` | ||
1645 | /// fn foo<T, U, ❰ const BAR: usize ❱, ❰ const BAZ: bool ❱>() {} | ||
1646 | /// ``` | ||
1647 | /// | ||
1648 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) | ||
541 | struct ConstParam: NameOwner, AttrsOwner, TypeAscriptionOwner { | 1649 | struct ConstParam: NameOwner, AttrsOwner, TypeAscriptionOwner { |
542 | T![=], | 1650 | T![=], |
543 | default_val: Expr, | 1651 | default_val: Expr, |
544 | } | 1652 | } |
1653 | |||
1654 | /// Lifetime parameter **declaration**. | ||
1655 | /// | ||
1656 | /// ``` | ||
1657 | /// fn foo<❰ 'a ❱, ❰ 'b ❱, V, G, D>(bar: &'a str, baz: &'b mut str) {} | ||
1658 | /// ``` | ||
1659 | /// | ||
1660 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
545 | struct LifetimeParam: AttrsOwner { T![lifetime] } | 1661 | struct LifetimeParam: AttrsOwner { T![lifetime] } |
546 | struct TypeBound { T![lifetime], /* Question, */ T![const], /* Question, */ TypeRef} | 1662 | |
1663 | /// Type bound declaration clause. | ||
1664 | /// | ||
1665 | /// ``` | ||
1666 | /// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {} | ||
1667 | /// | ||
1668 | /// trait Bar<T> | ||
1669 | /// where | ||
1670 | /// T: ❰ Send ❱ + ❰ Sync ❱ | ||
1671 | /// { | ||
1672 | /// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱; | ||
1673 | /// } | ||
1674 | /// ``` | ||
1675 | /// | ||
1676 | /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) | ||
1677 | struct TypeBound { T![lifetime], /* Question, */ T![const], /* Question, */ TypeRef } | ||
1678 | |||
1679 | /// Type bounds list. | ||
1680 | /// | ||
1681 | /// ``` | ||
1682 | /// | ||
1683 | /// fn foo<T: ❰ ?Sized + Debug ❱>() {} | ||
1684 | /// | ||
1685 | /// trait Bar<T> | ||
1686 | /// where | ||
1687 | /// T: ❰ Send + Sync ❱ | ||
1688 | /// { | ||
1689 | /// type Baz: ❰ !Sync + Debug ❱; | ||
1690 | /// } | ||
1691 | /// ``` | ||
1692 | /// | ||
1693 | /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) | ||
547 | struct TypeBoundList { bounds: [TypeBound] } | 1694 | struct TypeBoundList { bounds: [TypeBound] } |
1695 | |||
1696 | /// Single where predicate. | ||
1697 | /// | ||
1698 | /// ``` | ||
1699 | /// trait Foo<'a, 'b, T> | ||
1700 | /// where | ||
1701 | /// ❰ 'a: 'b ❱, | ||
1702 | /// ❰ T: IntoIterator ❱, | ||
1703 | /// ❰ for<'c> <T as IntoIterator>::Item: Bar<'c> ❱ | ||
1704 | /// {} | ||
1705 | /// ``` | ||
1706 | /// | ||
1707 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) | ||
548 | struct WherePred: TypeBoundsOwner { T![lifetime], TypeRef } | 1708 | struct WherePred: TypeBoundsOwner { T![lifetime], TypeRef } |
1709 | |||
1710 | /// Where clause. | ||
1711 | /// | ||
1712 | /// ``` | ||
1713 | /// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {} | ||
1714 | /// | ||
1715 | /// ``` | ||
1716 | /// | ||
1717 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) | ||
549 | struct WhereClause { T![where], predicates: [WherePred] } | 1718 | struct WhereClause { T![where], predicates: [WherePred] } |
1719 | |||
1720 | /// Abi declaration. | ||
1721 | /// Note: the abi string is optional. | ||
1722 | /// | ||
1723 | /// ``` | ||
1724 | /// ❰ extern "C" ❱ { | ||
1725 | /// fn foo() {} | ||
1726 | /// } | ||
1727 | /// | ||
1728 | /// type Bar = ❰ extern ❱ fn() -> u32; | ||
1729 | /// | ||
1730 | /// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool; | ||
1731 | /// ``` | ||
1732 | /// | ||
1733 | /// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
1734 | /// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions) | ||
550 | struct Abi { /*String*/ } | 1735 | struct Abi { /*String*/ } |
1736 | |||
1737 | /// Expression statement. | ||
1738 | /// | ||
1739 | /// ``` | ||
1740 | /// ❰ 42; ❱ | ||
1741 | /// ❰ foo(); ❱ | ||
1742 | /// ❰ (); ❱ | ||
1743 | /// ❰ {}; ❱ | ||
1744 | /// | ||
1745 | /// // constructions with trailing curly brace can omit the semicolon | ||
1746 | /// // but only when there are satements immediately after them (this is important!) | ||
1747 | /// ❰ if bool_cond { } ❱ | ||
1748 | /// ❰ loop {} ❱ | ||
1749 | /// ❰ somestatment; ❱ | ||
1750 | /// ``` | ||
1751 | /// | ||
1752 | /// [Reference](https://doc.rust-lang.org/reference/statements.html) | ||
551 | struct ExprStmt: AttrsOwner { Expr, T![;] } | 1753 | struct ExprStmt: AttrsOwner { Expr, T![;] } |
1754 | |||
1755 | /// Let statement. | ||
1756 | /// | ||
1757 | /// ``` | ||
1758 | /// ❰ #[attr] let foo; ❱ | ||
1759 | /// ❰ let bar: u64; ❱ | ||
1760 | /// ❰ let baz = 42; ❱ | ||
1761 | /// ❰ let bruh: bool = true; ❱ | ||
1762 | /// ``` | ||
1763 | /// | ||
1764 | /// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements) | ||
552 | struct LetStmt: AttrsOwner, TypeAscriptionOwner { | 1765 | struct LetStmt: AttrsOwner, TypeAscriptionOwner { |
553 | T![let], | 1766 | T![let], |
554 | Pat, | 1767 | Pat, |
@@ -556,42 +1769,192 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
556 | initializer: Expr, | 1769 | initializer: Expr, |
557 | T![;], | 1770 | T![;], |
558 | } | 1771 | } |
1772 | |||
1773 | /// Condition of `if` or `while` expression. | ||
1774 | /// | ||
1775 | /// ``` | ||
1776 | /// if ❰ true ❱ {} | ||
1777 | /// if ❰ let Pat(foo) = bar ❱ {} | ||
1778 | /// | ||
1779 | /// while ❰ true ❱ {} | ||
1780 | /// while ❰ let Pat(baz) = bruh ❱ {} | ||
1781 | /// ``` | ||
1782 | /// | ||
1783 | /// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
1784 | /// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
559 | struct Condition { T![let], Pat, T![=], Expr } | 1785 | struct Condition { T![let], Pat, T![=], Expr } |
560 | struct ParamList { | 1786 | |
1787 | /// Parameter list **declaration**. | ||
1788 | /// | ||
1789 | /// ``` | ||
1790 | /// fn foo❰ (a: u32, b: bool) ❱ -> u32 {} | ||
1791 | /// let bar = ❰ |a, b| ❱ {}; | ||
1792 | /// | ||
1793 | /// impl Baz { | ||
1794 | /// fn bruh❰ (&self, a: u32) ❱ {} | ||
1795 | /// } | ||
1796 | /// ``` | ||
1797 | /// | ||
1798 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script | ||
1799 | struct ParamList { // FIXME: this node is used by closure expressions too, but hey use pipes instead of parens... | ||
561 | T!['('], | 1800 | T!['('], |
562 | SelfParam, | 1801 | SelfParam, |
563 | params: [Param], | 1802 | params: [Param], |
564 | T![')'] | 1803 | T![')'] |
565 | } | 1804 | } |
1805 | |||
1806 | /// Self parameter **declaration**. | ||
1807 | /// | ||
1808 | /// ``` | ||
1809 | /// impl Bruh { | ||
1810 | /// fn foo(❰ self ❱) {} | ||
1811 | /// fn bar(❰ &self ❱) {} | ||
1812 | /// fn baz(❰ &mut self ❱) {} | ||
1813 | /// fn blah<'a>(❰ &'a self ❱) {} | ||
1814 | /// fn blin(❰ self: Box<Self> ❱) {} | ||
1815 | /// } | ||
1816 | /// ``` | ||
1817 | /// | ||
1818 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
566 | struct SelfParam: TypeAscriptionOwner, AttrsOwner { T![&], T![mut], T![lifetime], T![self] } | 1819 | struct SelfParam: TypeAscriptionOwner, AttrsOwner { T![&], T![mut], T![lifetime], T![self] } |
1820 | |||
1821 | /// Parameter **declaration**. | ||
1822 | /// | ||
1823 | /// ``` | ||
1824 | /// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {} | ||
1825 | /// | ||
1826 | /// extern "C" { | ||
1827 | /// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32; | ||
1828 | /// } | ||
1829 | /// ``` | ||
1830 | /// | ||
1831 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
567 | struct Param: TypeAscriptionOwner, AttrsOwner { | 1832 | struct Param: TypeAscriptionOwner, AttrsOwner { |
568 | Pat, | 1833 | Pat, |
569 | T![...] | 1834 | T![...] |
570 | } | 1835 | } |
1836 | |||
1837 | /// Use declaration. | ||
1838 | /// | ||
1839 | /// ``` | ||
1840 | /// ❰ #[attr] pub use foo; ❱ | ||
1841 | /// ❰ use bar as baz; ❱ | ||
1842 | /// ❰ use bruh::{self, bruuh}; ❱ | ||
1843 | /// ❰ use { blin::blen, blah::* }; | ||
1844 | /// ``` | ||
1845 | /// | ||
1846 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
571 | struct UseItem: AttrsOwner, VisibilityOwner { | 1847 | struct UseItem: AttrsOwner, VisibilityOwner { |
572 | T![use], | 1848 | T![use], |
573 | UseTree, | 1849 | UseTree, |
574 | } | 1850 | } |
1851 | |||
1852 | /// Use tree. | ||
1853 | /// | ||
1854 | /// ``` | ||
1855 | /// pub use ❰ foo::❰ * ❱ ❱; | ||
1856 | /// use ❰ bar as baz ❱; | ||
1857 | /// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱; | ||
1858 | /// use ❰ { ❰ blin::blen ❱ } ❱ | ||
1859 | /// ``` | ||
1860 | /// | ||
1861 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
575 | struct UseTree { | 1862 | struct UseTree { |
576 | Path, T![*], UseTreeList, Alias | 1863 | Path, T![*], UseTreeList, Alias |
577 | } | 1864 | } |
1865 | |||
1866 | /// Item alias. | ||
1867 | /// Note: this is not the type alias. | ||
1868 | /// | ||
1869 | /// ``` | ||
1870 | /// use foo ❰ as bar ❱; | ||
1871 | /// use baz::{bruh ❰ as _ ❱}; | ||
1872 | /// extern crate bruuh ❰ as blin ❱; | ||
1873 | /// ``` | ||
1874 | /// | ||
1875 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
578 | struct Alias: NameOwner { T![as] } | 1876 | struct Alias: NameOwner { T![as] } |
1877 | |||
1878 | /// Sublist of use trees. | ||
1879 | /// | ||
1880 | /// ``` | ||
1881 | /// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱; | ||
1882 | /// use ❰ { blin::blen::❰ {} ❱ } ❱ | ||
1883 | /// ``` | ||
1884 | /// | ||
1885 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
579 | struct UseTreeList { T!['{'], use_trees: [UseTree], T!['}'] } | 1886 | struct UseTreeList { T!['{'], use_trees: [UseTree], T!['}'] } |
1887 | |||
1888 | /// Extern crate item. | ||
1889 | /// | ||
1890 | /// ``` | ||
1891 | /// ❰ #[attr] pub extern crate foo; ❱ | ||
1892 | /// ❰ extern crate self as bar; ❱ | ||
1893 | /// ``` | ||
1894 | /// | ||
1895 | /// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html) | ||
580 | struct ExternCrateItem: AttrsOwner, VisibilityOwner { | 1896 | struct ExternCrateItem: AttrsOwner, VisibilityOwner { |
581 | T![extern], T![crate], NameRef, Alias, | 1897 | T![extern], T![crate], NameRef, Alias, |
582 | } | 1898 | } |
1899 | |||
1900 | /// Call site arguments list. | ||
1901 | /// | ||
1902 | /// ``` | ||
1903 | /// foo::<T, U>❰ (42, true) ❱; | ||
1904 | /// ``` | ||
1905 | /// | ||
1906 | /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) | ||
583 | struct ArgList { | 1907 | struct ArgList { |
584 | T!['('], | 1908 | T!['('], |
585 | args: [Expr], | 1909 | args: [Expr], |
586 | T![')'] | 1910 | T![')'] |
587 | } | 1911 | } |
1912 | |||
1913 | /// Path to a symbol. Includes single identifier names and elaborate paths with | ||
1914 | /// generic parameters. | ||
1915 | /// | ||
1916 | /// ``` | ||
1917 | /// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱(); | ||
1918 | /// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024); | ||
1919 | /// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱(); | ||
1920 | /// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱(); | ||
1921 | /// ``` | ||
1922 | /// | ||
1923 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
588 | struct Path { | 1924 | struct Path { |
589 | segment: PathSegment, | 1925 | segment: PathSegment, |
1926 | T![::], | ||
590 | qualifier: Path, | 1927 | qualifier: Path, |
591 | } | 1928 | } |
1929 | |||
1930 | /// Segment of the path to a symbol. | ||
1931 | /// Only path segment of an absolute path holds the `::` token, | ||
1932 | /// all other `::` tokens that connect path segments reside under `Path` itself.` | ||
1933 | /// | ||
1934 | /// ``` | ||
1935 | /// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱(); | ||
1936 | /// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024); | ||
1937 | /// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱(); | ||
1938 | /// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱(); | ||
1939 | /// | ||
1940 | /// // Note that only in this case `::` token is inlcuded: | ||
1941 | /// ❰ ::foo ❱; | ||
1942 | /// ``` | ||
1943 | /// | ||
1944 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
592 | struct PathSegment { | 1945 | struct PathSegment { |
593 | T![::], T![crate], T![self], T![super], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>] | 1946 | T![::], T![crate], T![self], T![super], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>] |
594 | } | 1947 | } |
1948 | |||
1949 | /// List of type arguments that are passed at generic instantiation site. | ||
1950 | /// | ||
1951 | /// ``` | ||
1952 | /// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar; | ||
1953 | /// | ||
1954 | /// Vec❰ ::<bool> ❱::(); | ||
1955 | /// ``` | ||
1956 | /// | ||
1957 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
595 | struct TypeArgList { | 1958 | struct TypeArgList { |
596 | T![::], | 1959 | T![::], |
597 | T![<], | 1960 | T![<], |
@@ -602,48 +1965,142 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
602 | const_args: [ConstArg], | 1965 | const_args: [ConstArg], |
603 | T![>] | 1966 | T![>] |
604 | } | 1967 | } |
1968 | |||
1969 | /// Type argument that is passed at generic instantiation site. | ||
1970 | /// | ||
1971 | /// ``` | ||
1972 | /// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz; | ||
1973 | /// ``` | ||
1974 | /// | ||
1975 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
605 | struct TypeArg { TypeRef } | 1976 | struct TypeArg { TypeRef } |
1977 | |||
1978 | /// Associated type argument that is passed at generic instantiation site. | ||
1979 | /// ``` | ||
1980 | /// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh; | ||
1981 | /// | ||
1982 | /// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {} | ||
1983 | /// ``` | ||
1984 | /// | ||
606 | struct AssocTypeArg : TypeBoundsOwner { NameRef, T![=], TypeRef } | 1985 | struct AssocTypeArg : TypeBoundsOwner { NameRef, T![=], TypeRef } |
1986 | |||
1987 | /// Lifetime argument that is passed at generic instantiation site. | ||
1988 | /// | ||
1989 | /// ``` | ||
1990 | /// fn foo<'a>(s: &'a str) { | ||
1991 | /// bar::<❰ 'a ❱>(s); | ||
1992 | /// } | ||
1993 | /// ``` | ||
1994 | /// | ||
1995 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
607 | struct LifetimeArg { T![lifetime] } | 1996 | struct LifetimeArg { T![lifetime] } |
608 | struct ConstArg { Literal, T![=], BlockExpr } | ||
609 | 1997 | ||
610 | struct MacroItems: ModuleItemOwner{ } | 1998 | /// Constant value argument that is passed at generic instantiation site. |
1999 | /// | ||
2000 | /// ``` | ||
2001 | /// foo::<u32, ❰ { true } ❱>(); | ||
2002 | /// | ||
2003 | /// bar::<❰ { 2 + 2} ❱>(); | ||
2004 | /// ``` | ||
2005 | /// | ||
2006 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) | ||
2007 | struct ConstArg { Literal, BlockExpr } | ||
2008 | |||
2009 | |||
2010 | /// FIXME: (@edwin0cheng) Remove it to use ItemList instead | ||
2011 | /// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243 | ||
2012 | /// | ||
2013 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
2014 | struct MacroItems: ModuleItemOwner { } | ||
611 | 2015 | ||
2016 | /// FIXME: (@edwin0cheng) add some documentation here. As per the writing | ||
2017 | /// of this comment this ast node is not used. | ||
2018 | /// | ||
2019 | /// ``` | ||
2020 | /// // FIXME: example here | ||
2021 | /// ``` | ||
2022 | /// | ||
2023 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
612 | struct MacroStmts { | 2024 | struct MacroStmts { |
613 | statements: [Stmt], | 2025 | statements: [Stmt], |
614 | Expr, | 2026 | Expr, |
615 | } | 2027 | } |
616 | 2028 | ||
2029 | /// List of items in an extern block. | ||
2030 | /// | ||
2031 | /// ``` | ||
2032 | /// extern "C" ❰ | ||
2033 | /// { | ||
2034 | /// fn foo(); | ||
2035 | /// static var: u32; | ||
2036 | /// } | ||
2037 | /// ❱ | ||
2038 | /// ``` | ||
2039 | /// | ||
2040 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
617 | struct ExternItemList: ModuleItemOwner { | 2041 | struct ExternItemList: ModuleItemOwner { |
618 | T!['{'], | 2042 | T!['{'], |
619 | extern_items: [ExternItem], | 2043 | extern_items: [ExternItem], |
620 | T!['}'] | 2044 | T!['}'] |
621 | } | 2045 | } |
622 | 2046 | ||
2047 | /// Extern block. | ||
2048 | /// | ||
2049 | /// ``` | ||
2050 | /// ❰ | ||
2051 | /// extern "C" { | ||
2052 | /// fn foo(); | ||
2053 | /// } | ||
2054 | /// ❱ | ||
2055 | /// | ||
2056 | /// ``` | ||
2057 | /// | ||
2058 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
623 | struct ExternBlock { | 2059 | struct ExternBlock { |
624 | Abi, | 2060 | Abi, |
625 | ExternItemList | 2061 | ExternItemList |
626 | } | 2062 | } |
627 | 2063 | ||
2064 | /// Meta item in an attribute. | ||
2065 | /// | ||
2066 | /// ``` | ||
2067 | /// #[❰ bar::baz = "42" ❱] | ||
2068 | /// #[❰ bruh(bruuh("true")) ❱] | ||
2069 | /// struct Foo; | ||
2070 | /// ``` | ||
2071 | /// | ||
2072 | /// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax) | ||
628 | struct MetaItem { | 2073 | struct MetaItem { |
629 | Path, T![=], AttrInput, nested_meta_items: [MetaItem] | 2074 | Path, T![=], AttrInput, nested_meta_items: [MetaItem] |
630 | } | 2075 | } |
631 | 2076 | ||
2077 | /// Macro 2.0 definition. | ||
2078 | /// Their syntax is still WIP by rustc team... | ||
2079 | /// ``` | ||
2080 | /// ❰ | ||
2081 | /// macro foo { } | ||
2082 | /// ❱ | ||
2083 | /// ``` | ||
2084 | /// | ||
2085 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md) | ||
632 | struct MacroDef { | 2086 | struct MacroDef { |
633 | Name, TokenTree | 2087 | Name, TokenTree |
634 | } | 2088 | } |
635 | }, | 2089 | }, |
636 | enums: &ast_enums! { | 2090 | enums: &ast_enums! { |
2091 | /// Any kind of nominal type definition. | ||
637 | enum NominalDef: NameOwner, TypeParamsOwner, AttrsOwner { | 2092 | enum NominalDef: NameOwner, TypeParamsOwner, AttrsOwner { |
638 | StructDef, EnumDef, UnionDef, | 2093 | StructDef, EnumDef, UnionDef, |
639 | } | 2094 | } |
640 | 2095 | ||
2096 | /// Any kind of **declared** generic parameter | ||
641 | enum GenericParam { | 2097 | enum GenericParam { |
642 | LifetimeParam, | 2098 | LifetimeParam, |
643 | TypeParam, | 2099 | TypeParam, |
644 | ConstParam | 2100 | ConstParam |
645 | } | 2101 | } |
646 | 2102 | ||
2103 | /// Any kind of generic argument passed at instantiation site | ||
647 | enum GenericArg { | 2104 | enum GenericArg { |
648 | LifetimeArg, | 2105 | LifetimeArg, |
649 | TypeArg, | 2106 | TypeArg, |
@@ -651,6 +2108,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
651 | AssocTypeArg | 2108 | AssocTypeArg |
652 | } | 2109 | } |
653 | 2110 | ||
2111 | /// Any kind of construct valid in type context | ||
654 | enum TypeRef { | 2112 | enum TypeRef { |
655 | ParenType, | 2113 | ParenType, |
656 | TupleType, | 2114 | TupleType, |
@@ -667,6 +2125,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
667 | DynTraitType, | 2125 | DynTraitType, |
668 | } | 2126 | } |
669 | 2127 | ||
2128 | /// Any kind of top-level item that may appear in a module | ||
670 | enum ModuleItem: NameOwner, AttrsOwner, VisibilityOwner { | 2129 | enum ModuleItem: NameOwner, AttrsOwner, VisibilityOwner { |
671 | StructDef, | 2130 | StructDef, |
672 | UnionDef, | 2131 | UnionDef, |
@@ -684,16 +2143,23 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
684 | ExternBlock | 2143 | ExternBlock |
685 | } | 2144 | } |
686 | 2145 | ||
687 | /* impl blocks can also contain MacroCall */ | 2146 | |
2147 | |||
2148 | /// Any kind of item that may appear in an impl block | ||
2149 | /// | ||
2150 | /// // FIXME: impl blocks can also contain MacroCall | ||
688 | enum AssocItem: NameOwner, AttrsOwner { | 2151 | enum AssocItem: NameOwner, AttrsOwner { |
689 | FnDef, TypeAliasDef, ConstDef | 2152 | FnDef, TypeAliasDef, ConstDef |
690 | } | 2153 | } |
691 | 2154 | ||
692 | /* extern blocks can also contain MacroCall */ | 2155 | /// Any kind of item that may appear in an extern block |
2156 | /// | ||
2157 | /// // FIXME: extern blocks can also contain MacroCall | ||
693 | enum ExternItem: NameOwner, AttrsOwner, VisibilityOwner { | 2158 | enum ExternItem: NameOwner, AttrsOwner, VisibilityOwner { |
694 | FnDef, StaticDef | 2159 | FnDef, StaticDef |
695 | } | 2160 | } |
696 | 2161 | ||
2162 | /// Any kind of expression | ||
697 | enum Expr: AttrsOwner { | 2163 | enum Expr: AttrsOwner { |
698 | TupleExpr, | 2164 | TupleExpr, |
699 | ArrayExpr, | 2165 | ArrayExpr, |
@@ -728,6 +2194,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
728 | BoxExpr, | 2194 | BoxExpr, |
729 | } | 2195 | } |
730 | 2196 | ||
2197 | /// Any kind of pattern | ||
731 | enum Pat { | 2198 | enum Pat { |
732 | OrPat, | 2199 | OrPat, |
733 | ParenPat, | 2200 | ParenPat, |
@@ -746,18 +2213,26 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
746 | MacroPat, | 2213 | MacroPat, |
747 | } | 2214 | } |
748 | 2215 | ||
2216 | /// Any kind of pattern that appears directly inside of the curly | ||
2217 | /// braces of a record pattern | ||
749 | enum RecordInnerPat { | 2218 | enum RecordInnerPat { |
750 | RecordFieldPat, | 2219 | RecordFieldPat, |
751 | BindPat | 2220 | BindPat |
752 | } | 2221 | } |
753 | 2222 | ||
2223 | /// Any kind of input to an attribute | ||
754 | enum AttrInput { Literal, TokenTree } | 2224 | enum AttrInput { Literal, TokenTree } |
2225 | |||
2226 | /// Any kind of statement | ||
2227 | /// Note: there are no empty statements, these are just represented as | ||
2228 | /// bare semicolons without a dedicated statement ast node. | ||
755 | enum Stmt { | 2229 | enum Stmt { |
756 | LetStmt, | 2230 | LetStmt, |
757 | ExprStmt, | 2231 | ExprStmt, |
758 | // macro calls are parsed as expression statements */ | 2232 | // macro calls are parsed as expression statements |
759 | } | 2233 | } |
760 | 2234 | ||
2235 | /// Any kind of fields list (record or tuple field lists) | ||
761 | enum FieldDefList { | 2236 | enum FieldDefList { |
762 | RecordFieldDefList, | 2237 | RecordFieldDefList, |
763 | TupleFieldDefList, | 2238 | TupleFieldDefList, |
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 8028575c5..19d5594f5 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | //! Specifically, it generates the `SyntaxKind` enum and a number of newtype | 3 | //! Specifically, it generates the `SyntaxKind` enum and a number of newtype |
4 | //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. | 4 | //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. |
5 | 5 | ||
6 | use std::collections::HashSet; | 6 | use std::{collections::HashSet, fmt::Write}; |
7 | 7 | ||
8 | use proc_macro2::{Punct, Spacing}; | 8 | use proc_macro2::{Punct, Spacing}; |
9 | use quote::{format_ident, quote}; | 9 | use quote::{format_ident, quote}; |
@@ -102,6 +102,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> { | |||
102 | }); | 102 | }); |
103 | ( | 103 | ( |
104 | quote! { | 104 | quote! { |
105 | #[pretty_doc_comment_placeholder_workaround] | ||
105 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 106 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
106 | pub struct #name { | 107 | pub struct #name { |
107 | pub(crate) syntax: SyntaxNode, | 108 | pub(crate) syntax: SyntaxNode, |
@@ -145,6 +146,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> { | |||
145 | 146 | ||
146 | ( | 147 | ( |
147 | quote! { | 148 | quote! { |
149 | #[pretty_doc_comment_placeholder_workaround] | ||
148 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 150 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
149 | pub enum #name { | 151 | pub enum #name { |
150 | #(#variants(#variants),)* | 152 | #(#variants(#variants),)* |
@@ -230,10 +232,29 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> { | |||
230 | }; | 232 | }; |
231 | 233 | ||
232 | let ast = ast.to_string().replace("T ! [ ", "T![").replace(" ] )", "])"); | 234 | let ast = ast.to_string().replace("T ! [ ", "T![").replace(" ] )", "])"); |
233 | let pretty = crate::reformat(ast)?.replace("#[derive", "\n#[derive"); | 235 | |
236 | let mut res = String::with_capacity(ast.len() * 2); | ||
237 | |||
238 | let mut docs = | ||
239 | grammar.nodes.iter().map(|it| it.doc).chain(grammar.enums.iter().map(|it| it.doc)); | ||
240 | |||
241 | for chunk in ast.split("# [ pretty_doc_comment_placeholder_workaround ]") { | ||
242 | res.push_str(chunk); | ||
243 | if let Some(doc) = docs.next() { | ||
244 | write_doc_comment(doc, &mut res); | ||
245 | } | ||
246 | } | ||
247 | |||
248 | let pretty = crate::reformat(res)?; | ||
234 | Ok(pretty) | 249 | Ok(pretty) |
235 | } | 250 | } |
236 | 251 | ||
252 | fn write_doc_comment(contents: &[&str], dest: &mut String) { | ||
253 | for line in contents { | ||
254 | writeln!(dest, "///{}", line).unwrap(); | ||
255 | } | ||
256 | } | ||
257 | |||
237 | fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result<String> { | 258 | fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result<String> { |
238 | let (single_byte_tokens_values, single_byte_tokens): (Vec<_>, Vec<_>) = grammar | 259 | let (single_byte_tokens_values, single_byte_tokens): (Vec<_>, Vec<_>) = grammar |
239 | .punct | 260 | .punct |