diff options
-rw-r--r-- | Cargo.lock | 4 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests.rs | 2 | ||||
-rw-r--r-- | crates/syntax/src/ast/generated/nodes.rs | 8 | ||||
-rw-r--r-- | xtask/Cargo.toml | 2 | ||||
-rw-r--r-- | xtask/src/codegen/rust.ungram | 587 |
6 files changed, 16 insertions, 591 deletions
diff --git a/Cargo.lock b/Cargo.lock index 46d9469c0..69affa0ea 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1688,9 +1688,9 @@ dependencies = [ | |||
1688 | 1688 | ||
1689 | [[package]] | 1689 | [[package]] |
1690 | name = "ungrammar" | 1690 | name = "ungrammar" |
1691 | version = "1.1.2" | 1691 | version = "1.1.3" |
1692 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1692 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1693 | checksum = "bab6142ac77be714b1ea78faca6efaed5478c50724786b0fe80d8528d10692b3" | 1693 | checksum = "ca4d39065b45f658d33013f7cc93ee050708cd543f6e07dd15b4293fcf217e12" |
1694 | 1694 | ||
1695 | [[package]] | 1695 | [[package]] |
1696 | name = "unicode-bidi" | 1696 | name = "unicode-bidi" |
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 391ab5d39..6a503d785 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -557,6 +557,10 @@ impl Ctx { | |||
557 | let statik = self.lower_static(&ast)?; | 557 | let statik = self.lower_static(&ast)?; |
558 | statik.into() | 558 | statik.into() |
559 | } | 559 | } |
560 | ast::ExternItem::TypeAlias(ty) => { | ||
561 | let id = self.lower_type_alias(&ty)?; | ||
562 | id.into() | ||
563 | } | ||
560 | ast::ExternItem::MacroCall(_) => return None, | 564 | ast::ExternItem::MacroCall(_) => return None, |
561 | }; | 565 | }; |
562 | self.add_attrs(id.into(), attrs); | 566 | self.add_attrs(id.into(), attrs); |
diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs index 8aaf7a158..5ca30dac9 100644 --- a/crates/hir_def/src/nameres/tests.rs +++ b/crates/hir_def/src/nameres/tests.rs | |||
@@ -46,6 +46,7 @@ union U { to_be: bool, not_to_be: u8 } | |||
46 | enum E { V } | 46 | enum E { V } |
47 | 47 | ||
48 | extern { | 48 | extern { |
49 | type Ext; | ||
49 | static EXT: u8; | 50 | static EXT: u8; |
50 | fn ext(); | 51 | fn ext(); |
51 | } | 52 | } |
@@ -65,6 +66,7 @@ extern { | |||
65 | Baz: t v | 66 | Baz: t v |
66 | E: t | 67 | E: t |
67 | EXT: v | 68 | EXT: v |
69 | Ext: t | ||
68 | U: t | 70 | U: t |
69 | ext: v | 71 | ext: v |
70 | "#]], | 72 | "#]], |
diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 6317407c6..d6af5755c 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs | |||
@@ -1380,6 +1380,7 @@ pub enum ExternItem { | |||
1380 | Fn(Fn), | 1380 | Fn(Fn), |
1381 | MacroCall(MacroCall), | 1381 | MacroCall(MacroCall), |
1382 | Static(Static), | 1382 | Static(Static), |
1383 | TypeAlias(TypeAlias), | ||
1383 | } | 1384 | } |
1384 | impl ast::AttrsOwner for ExternItem {} | 1385 | impl ast::AttrsOwner for ExternItem {} |
1385 | impl ast::NameOwner for ExternItem {} | 1386 | impl ast::NameOwner for ExternItem {} |
@@ -3339,10 +3340,13 @@ impl From<MacroCall> for ExternItem { | |||
3339 | impl From<Static> for ExternItem { | 3340 | impl From<Static> for ExternItem { |
3340 | fn from(node: Static) -> ExternItem { ExternItem::Static(node) } | 3341 | fn from(node: Static) -> ExternItem { ExternItem::Static(node) } |
3341 | } | 3342 | } |
3343 | impl From<TypeAlias> for ExternItem { | ||
3344 | fn from(node: TypeAlias) -> ExternItem { ExternItem::TypeAlias(node) } | ||
3345 | } | ||
3342 | impl AstNode for ExternItem { | 3346 | impl AstNode for ExternItem { |
3343 | fn can_cast(kind: SyntaxKind) -> bool { | 3347 | fn can_cast(kind: SyntaxKind) -> bool { |
3344 | match kind { | 3348 | match kind { |
3345 | FN | MACRO_CALL | STATIC => true, | 3349 | FN | MACRO_CALL | STATIC | TYPE_ALIAS => true, |
3346 | _ => false, | 3350 | _ => false, |
3347 | } | 3351 | } |
3348 | } | 3352 | } |
@@ -3351,6 +3355,7 @@ impl AstNode for ExternItem { | |||
3351 | FN => ExternItem::Fn(Fn { syntax }), | 3355 | FN => ExternItem::Fn(Fn { syntax }), |
3352 | MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }), | 3356 | MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }), |
3353 | STATIC => ExternItem::Static(Static { syntax }), | 3357 | STATIC => ExternItem::Static(Static { syntax }), |
3358 | TYPE_ALIAS => ExternItem::TypeAlias(TypeAlias { syntax }), | ||
3354 | _ => return None, | 3359 | _ => return None, |
3355 | }; | 3360 | }; |
3356 | Some(res) | 3361 | Some(res) |
@@ -3360,6 +3365,7 @@ impl AstNode for ExternItem { | |||
3360 | ExternItem::Fn(it) => &it.syntax, | 3365 | ExternItem::Fn(it) => &it.syntax, |
3361 | ExternItem::MacroCall(it) => &it.syntax, | 3366 | ExternItem::MacroCall(it) => &it.syntax, |
3362 | ExternItem::Static(it) => &it.syntax, | 3367 | ExternItem::Static(it) => &it.syntax, |
3368 | ExternItem::TypeAlias(it) => &it.syntax, | ||
3363 | } | 3369 | } |
3364 | } | 3370 | } |
3365 | } | 3371 | } |
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index e9edbdd10..0750b5657 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml | |||
@@ -15,7 +15,7 @@ flate2 = "1.0" | |||
15 | pico-args = "0.3.1" | 15 | pico-args = "0.3.1" |
16 | proc-macro2 = "1.0.8" | 16 | proc-macro2 = "1.0.8" |
17 | quote = "1.0.2" | 17 | quote = "1.0.2" |
18 | ungrammar = "1.1.1" | 18 | ungrammar = "1.1.3" |
19 | walkdir = "2.3.1" | 19 | walkdir = "2.3.1" |
20 | write-json = "0.1.0" | 20 | write-json = "0.1.0" |
21 | # Avoid adding more dependencies to this crate | 21 | # Avoid adding more dependencies to this crate |
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram deleted file mode 100644 index aca23890c..000000000 --- a/xtask/src/codegen/rust.ungram +++ /dev/null | |||
@@ -1,587 +0,0 @@ | |||
1 | //*************************// | ||
2 | // Names, Paths and Macros // | ||
3 | //*************************// | ||
4 | |||
5 | Name = | ||
6 | 'ident' | ||
7 | |||
8 | NameRef = | ||
9 | 'ident' | 'int_number' | ||
10 | |||
11 | Path = | ||
12 | (qualifier:Path '::')? segment:PathSegment | ||
13 | |||
14 | PathSegment = | ||
15 | 'crate' | 'self' | 'super' | ||
16 | | '::' NameRef | ||
17 | | NameRef GenericArgList? | ||
18 | | NameRef ParamList RetType? | ||
19 | | '<' PathType ('as' PathType)? '>' | ||
20 | |||
21 | GenericArgList = | ||
22 | '::'? '<' (GenericArg (',' GenericArg)* ','?)? '>' | ||
23 | |||
24 | GenericArg = | ||
25 | TypeArg | ||
26 | | AssocTypeArg | ||
27 | | LifetimeArg | ||
28 | | ConstArg | ||
29 | |||
30 | TypeArg = | ||
31 | Type | ||
32 | |||
33 | AssocTypeArg = | ||
34 | NameRef (':' TypeBoundList | '=' Type) | ||
35 | |||
36 | LifetimeArg = | ||
37 | 'lifetime' | ||
38 | |||
39 | ConstArg = | ||
40 | Expr | ||
41 | |||
42 | MacroCall = | ||
43 | Attr* Path '!' Name? TokenTree ';'? | ||
44 | |||
45 | TokenTree = | ||
46 | '(' ')' | ||
47 | | '{' '}' | ||
48 | | '[' ']' | ||
49 | |||
50 | MacroItems = | ||
51 | Item* | ||
52 | |||
53 | MacroStmts = | ||
54 | statements:Stmt* | ||
55 | Expr? | ||
56 | |||
57 | //*************************// | ||
58 | // Items // | ||
59 | //*************************// | ||
60 | |||
61 | SourceFile = | ||
62 | 'shebang'? | ||
63 | Attr* | ||
64 | Item* | ||
65 | |||
66 | Item = | ||
67 | Const | ||
68 | | Enum | ||
69 | | ExternBlock | ||
70 | | ExternCrate | ||
71 | | Fn | ||
72 | | Impl | ||
73 | | MacroCall | ||
74 | | Module | ||
75 | | Static | ||
76 | | Struct | ||
77 | | Trait | ||
78 | | TypeAlias | ||
79 | | Union | ||
80 | | Use | ||
81 | |||
82 | Module = | ||
83 | Attr* Visibility? 'mod' Name | ||
84 | (ItemList | ';') | ||
85 | |||
86 | ItemList = | ||
87 | '{' Attr* Item* '}' | ||
88 | |||
89 | ExternCrate = | ||
90 | Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Rename? ';' | ||
91 | |||
92 | Rename = | ||
93 | 'as' (Name | '_') | ||
94 | |||
95 | Use = | ||
96 | Attr* Visibility? 'use' UseTree ';' | ||
97 | |||
98 | UseTree = | ||
99 | (Path? '::')? ('*' | UseTreeList ) | ||
100 | | Path Rename? | ||
101 | |||
102 | UseTreeList = | ||
103 | '{' (UseTree (',' UseTree)* ','?)? '}' | ||
104 | |||
105 | Fn = | ||
106 | Attr* Visibility? | ||
107 | 'default'? ('async' | 'const')? 'unsafe'? Abi? | ||
108 | 'fn' Name GenericParamList? ParamList RetType? | ||
109 | WhereClause? | ||
110 | (body:BlockExpr | ';') | ||
111 | |||
112 | Abi = | ||
113 | 'extern' 'string'? | ||
114 | |||
115 | ParamList = | ||
116 | '('( | ||
117 | SelfParam | ||
118 | | (SelfParam ',')? (Param (',' Param)* ','?)? | ||
119 | )')' | ||
120 | |||
121 | SelfParam = | ||
122 | Attr* ( | ||
123 | ('&' 'lifetime'?)? 'mut'? 'self' | ||
124 | | 'mut'? 'self' ':' Type | ||
125 | ) | ||
126 | |||
127 | Param = | ||
128 | Attr* ( | ||
129 | Pat (':' Type) | ||
130 | | Type | ||
131 | | '...' | ||
132 | ) | ||
133 | |||
134 | RetType = | ||
135 | '->' Type | ||
136 | |||
137 | TypeAlias = | ||
138 | Attr* Visibility? 'default'? 'type' Name GenericParamList? (':' TypeBoundList?)? WhereClause? | ||
139 | '=' Type ';' | ||
140 | |||
141 | Struct = | ||
142 | Attr* Visibility? 'struct' Name GenericParamList? ( | ||
143 | WhereClause? (RecordFieldList | ';') | ||
144 | | TupleFieldList WhereClause? ';' | ||
145 | ) | ||
146 | |||
147 | RecordFieldList = | ||
148 | '{' fields:(RecordField (',' RecordField)* ','?)? '}' | ||
149 | |||
150 | RecordField = | ||
151 | Attr* Visibility? Name ':' Type | ||
152 | |||
153 | TupleFieldList = | ||
154 | '(' fields:(TupleField (',' TupleField)* ','?)? ')' | ||
155 | |||
156 | TupleField = | ||
157 | Attr* Visibility? Type | ||
158 | |||
159 | FieldList = | ||
160 | RecordFieldList | ||
161 | | TupleFieldList | ||
162 | |||
163 | Enum = | ||
164 | Attr* Visibility? 'enum' Name GenericParamList? WhereClause? | ||
165 | VariantList | ||
166 | |||
167 | VariantList = | ||
168 | '{' (Variant (',' Variant)* ','?)? '}' | ||
169 | |||
170 | Variant = | ||
171 | Attr* Visibility? Name FieldList ('=' Expr)? | ||
172 | |||
173 | Union = | ||
174 | Attr* Visibility? 'union' Name GenericParamList? WhereClause? | ||
175 | RecordFieldList | ||
176 | |||
177 | AdtDef = | ||
178 | Enum | ||
179 | | Struct | ||
180 | | Union | ||
181 | |||
182 | Const = | ||
183 | Attr* Visibility? 'default'? 'const' (Name | '_') ':' Type | ||
184 | '=' body:Expr ';' | ||
185 | |||
186 | Static = | ||
187 | Attr* Visibility? 'static'? 'mut'? Name ':' Type | ||
188 | '=' body:Expr ';' | ||
189 | |||
190 | Trait = | ||
191 | Attr* Visibility? 'unsafe'? 'auto'? 'trait' Name GenericParamList | ||
192 | (':' TypeBoundList?)? WhereClause | ||
193 | AssocItemList | ||
194 | |||
195 | AssocItemList = | ||
196 | '{' Attr* AssocItem* '}' | ||
197 | |||
198 | AssocItem = | ||
199 | Const | ||
200 | | Fn | ||
201 | | MacroCall | ||
202 | | TypeAlias | ||
203 | |||
204 | Impl = | ||
205 | Attr* Visibility? | ||
206 | 'default'? 'unsafe'? 'impl' 'const'? GenericParamList? | ||
207 | ('!'? target_trait:Type 'for')? target_type:Type | ||
208 | WhereClause? | ||
209 | AssocItemList | ||
210 | |||
211 | ExternBlock = | ||
212 | Attr* Abi ExternItemList | ||
213 | |||
214 | ExternItemList = | ||
215 | '{' Attr* ExternItem* '}' | ||
216 | |||
217 | ExternItem = | ||
218 | Fn | Static | MacroCall | ||
219 | |||
220 | GenericParamList = | ||
221 | '<' (GenericParam (',' GenericParam)* ','?)? '>' | ||
222 | |||
223 | GenericParam = | ||
224 | ConstParam | ||
225 | | LifetimeParam | ||
226 | | TypeParam | ||
227 | |||
228 | TypeParam = | ||
229 | Attr* Name (':' TypeBoundList?)? | ||
230 | ('=' default_type:Type)? | ||
231 | |||
232 | ConstParam = | ||
233 | Attr* 'const' Name ':' Type | ||
234 | ('=' default_val:Expr)? | ||
235 | |||
236 | LifetimeParam = | ||
237 | Attr* 'lifetime' (':' TypeBoundList?)? | ||
238 | |||
239 | WhereClause = | ||
240 | 'where' predicates:(WherePred (',' WherePred)* ','?) | ||
241 | |||
242 | WherePred = | ||
243 | ('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList | ||
244 | |||
245 | Visibility = | ||
246 | 'pub' ('(' | ||
247 | 'super' | ||
248 | | 'self' | ||
249 | | 'crate' | ||
250 | | 'in' Path | ||
251 | ')')? | ||
252 | |||
253 | Attr = | ||
254 | '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' | ||
255 | |||
256 | //****************************// | ||
257 | // Statements and Expressions // | ||
258 | //****************************// | ||
259 | |||
260 | Stmt = | ||
261 | ExprStmt | ||
262 | | Item | ||
263 | | LetStmt | ||
264 | |||
265 | LetStmt = | ||
266 | Attr* 'let' Pat (':' Type)? | ||
267 | '=' initializer:Expr ';' | ||
268 | |||
269 | ExprStmt = | ||
270 | Attr* Expr ';'? | ||
271 | |||
272 | Expr = | ||
273 | ArrayExpr | ||
274 | | AwaitExpr | ||
275 | | BinExpr | ||
276 | | BlockExpr | ||
277 | | BoxExpr | ||
278 | | BreakExpr | ||
279 | | CallExpr | ||
280 | | CastExpr | ||
281 | | ClosureExpr | ||
282 | | ContinueExpr | ||
283 | | EffectExpr | ||
284 | | FieldExpr | ||
285 | | ForExpr | ||
286 | | IfExpr | ||
287 | | IndexExpr | ||
288 | | Literal | ||
289 | | LoopExpr | ||
290 | | MacroCall | ||
291 | | MatchExpr | ||
292 | | MethodCallExpr | ||
293 | | ParenExpr | ||
294 | | PathExpr | ||
295 | | PrefixExpr | ||
296 | | RangeExpr | ||
297 | | RecordExpr | ||
298 | | RefExpr | ||
299 | | ReturnExpr | ||
300 | | TryExpr | ||
301 | | TupleExpr | ||
302 | | WhileExpr | ||
303 | |||
304 | Literal = | ||
305 | Attr* value:( | ||
306 | 'int_number' | 'float_number' | ||
307 | | 'string' | 'raw_string' | ||
308 | | 'byte_string' | 'raw_byte_string' | ||
309 | | 'true' | 'false' | ||
310 | | 'char' | 'byte' | ||
311 | ) | ||
312 | |||
313 | PathExpr = | ||
314 | Attr* Path | ||
315 | |||
316 | BlockExpr = | ||
317 | '{' | ||
318 | Attr* | ||
319 | statements:Stmt* | ||
320 | Expr? | ||
321 | '}' | ||
322 | |||
323 | RefExpr = | ||
324 | Attr* '&' ('raw' |'mut' | 'const') Expr | ||
325 | |||
326 | TryExpr = | ||
327 | Attr* Expr '?' | ||
328 | |||
329 | EffectExpr = | ||
330 | Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr | ||
331 | |||
332 | PrefixExpr = | ||
333 | Attr* op:('-' | '!' | '*') Expr | ||
334 | |||
335 | BinExpr = | ||
336 | Attr* | ||
337 | lhs:Expr | ||
338 | op:( | ||
339 | '||' | '&&' | ||
340 | | '==' | '!=' | '<=' | '>=' | '<' | '>' | ||
341 | | '+' | '*' | '-' | '/' | '%' | '<<' | '>>' | '^' | '|' | '&' | ||
342 | | '=' | '+=' | '/=' | '*=' | '%=' | '>>=' | '<<=' | '-=' | '|=' | '&=' | '^=' | ||
343 | ) | ||
344 | rhs:Expr | ||
345 | |||
346 | CastExpr = | ||
347 | Attr* Expr 'as' Type | ||
348 | |||
349 | ParenExpr = | ||
350 | Attr* '(' Attr* Expr ')' | ||
351 | |||
352 | ArrayExpr = | ||
353 | Attr* '[' Attr* ( | ||
354 | (Expr (',' Expr)* ','?)? | ||
355 | | Expr ';' Expr | ||
356 | ) ']' | ||
357 | |||
358 | IndexExpr = | ||
359 | Attr* base:Expr '[' index:Expr ']' | ||
360 | |||
361 | TupleExpr = | ||
362 | Attr* '(' Attr* fields:(Expr (',' Expr)* ','?)? ')' | ||
363 | |||
364 | RecordExpr = | ||
365 | Path RecordExprFieldList | ||
366 | |||
367 | RecordExprFieldList = | ||
368 | '{' | ||
369 | Attr* | ||
370 | fields:(RecordExprField (',' RecordExprField)* ','?) | ||
371 | ('..' spread:Expr)? | ||
372 | '}' | ||
373 | |||
374 | RecordExprField = | ||
375 | Attr* NameRef (':' Expr)? | ||
376 | |||
377 | CallExpr = | ||
378 | Attr* Expr ArgList | ||
379 | |||
380 | ArgList = | ||
381 | '(' args:(Expr (',' Expr)* ','?)? ')' | ||
382 | |||
383 | MethodCallExpr = | ||
384 | Attr* Expr '.' NameRef GenericArgList? ArgList | ||
385 | |||
386 | FieldExpr = | ||
387 | Attr* Expr '.' NameRef | ||
388 | |||
389 | ClosureExpr = | ||
390 | Attr* 'static'? 'async'? 'move'? ParamList RetType? | ||
391 | body:Expr | ||
392 | |||
393 | IfExpr = | ||
394 | Attr* 'if' Condition then_branch:BlockExpr | ||
395 | ('else' else_branch:(IfExpr | BlockExpr))? | ||
396 | |||
397 | Condition = | ||
398 | 'let' Pat '=' Expr | ||
399 | | Expr | ||
400 | |||
401 | LoopExpr = | ||
402 | Attr* Label? 'loop' | ||
403 | loop_body:BlockExpr | ||
404 | |||
405 | ForExpr = | ||
406 | Attr* Label? 'for' Pat 'in' iterable:Expr | ||
407 | loop_body:BlockExpr | ||
408 | |||
409 | WhileExpr = | ||
410 | Attr* Label? 'while' Condition | ||
411 | loop_body:BlockExpr | ||
412 | |||
413 | Label = | ||
414 | 'lifetime' | ||
415 | |||
416 | BreakExpr = | ||
417 | Attr* 'break' 'lifetime'? Expr? | ||
418 | |||
419 | ContinueExpr = | ||
420 | Attr* 'continue' 'lifetime'? | ||
421 | |||
422 | RangeExpr = | ||
423 | Attr* start:Expr? op:('..' | '..=') end:Expr? | ||
424 | |||
425 | MatchExpr = | ||
426 | Attr* 'match' Expr MatchArmList | ||
427 | |||
428 | MatchArmList = | ||
429 | '{' | ||
430 | Attr* | ||
431 | arms:MatchArm* | ||
432 | '}' | ||
433 | |||
434 | MatchArm = | ||
435 | Attr* Pat guard:MatchGuard? '=>' Expr ','? | ||
436 | |||
437 | MatchGuard = | ||
438 | 'if' Expr | ||
439 | |||
440 | ReturnExpr = | ||
441 | Attr* 'return' Expr? | ||
442 | |||
443 | AwaitExpr = | ||
444 | Attr* Expr '.' 'await' | ||
445 | |||
446 | BoxExpr = | ||
447 | Attr* 'box' Expr | ||
448 | |||
449 | //*************************// | ||
450 | // Types // | ||
451 | //*************************// | ||
452 | |||
453 | Type = | ||
454 | ArrayType | ||
455 | | DynTraitType | ||
456 | | FnPointerType | ||
457 | | ForType | ||
458 | | ImplTraitType | ||
459 | | InferType | ||
460 | | NeverType | ||
461 | | ParenType | ||
462 | | PathType | ||
463 | | PointerType | ||
464 | | ReferenceType | ||
465 | | SliceType | ||
466 | | TupleType | ||
467 | |||
468 | ParenType = | ||
469 | '(' Type ')' | ||
470 | |||
471 | NeverType = | ||
472 | '!' | ||
473 | |||
474 | PathType = | ||
475 | Path | ||
476 | |||
477 | TupleType = | ||
478 | '(' fields:(Type (',' Type)* ','?)? ')' | ||
479 | |||
480 | PointerType = | ||
481 | '*' ('const' | 'mut') Type | ||
482 | |||
483 | ReferenceType = | ||
484 | '&' 'lifetime'? 'mut'? Type | ||
485 | |||
486 | ArrayType = | ||
487 | '[' Type ';' Expr ']' | ||
488 | |||
489 | SliceType = | ||
490 | '[' Type ']' | ||
491 | |||
492 | InferType = | ||
493 | '_' | ||
494 | |||
495 | FnPointerType = | ||
496 | 'const'? 'async'? 'unsafe'? Abi? 'fn' ParamList RetType? | ||
497 | |||
498 | ForType = | ||
499 | 'for' GenericParamList Type | ||
500 | |||
501 | ImplTraitType = | ||
502 | 'impl' TypeBoundList | ||
503 | |||
504 | DynTraitType = | ||
505 | 'dyn' TypeBoundList | ||
506 | |||
507 | TypeBoundList = | ||
508 | bounds:(TypeBound ('+' TypeBound)* '+'?) | ||
509 | |||
510 | TypeBound = | ||
511 | 'lifetime' | ||
512 | | '?'? Type | ||
513 | |||
514 | //************************// | ||
515 | // Patterns // | ||
516 | //************************// | ||
517 | |||
518 | Pat = | ||
519 | IdentPat | ||
520 | | BoxPat | ||
521 | | RestPat | ||
522 | | LiteralPat | ||
523 | | MacroPat | ||
524 | | OrPat | ||
525 | | ParenPat | ||
526 | | PathPat | ||
527 | | WildcardPat | ||
528 | | RangePat | ||
529 | | RecordPat | ||
530 | | RefPat | ||
531 | | SlicePat | ||
532 | | TuplePat | ||
533 | | TupleStructPat | ||
534 | |||
535 | LiteralPat = | ||
536 | Literal | ||
537 | |||
538 | IdentPat = | ||
539 | Attr* 'ref'? 'mut'? Name ('@' Pat)? | ||
540 | |||
541 | WildcardPat = | ||
542 | '_' | ||
543 | |||
544 | RangePat = | ||
545 | start:Pat op:('..' | '..=') end:Pat | ||
546 | |||
547 | RefPat = | ||
548 | '&' 'mut'? Pat | ||
549 | |||
550 | RecordPat = | ||
551 | Path RecordPatFieldList | ||
552 | |||
553 | RecordPatFieldList = | ||
554 | '{' | ||
555 | fields:(RecordPatField (',' RecordPatField)* ','?) | ||
556 | '..'? | ||
557 | '}' | ||
558 | |||
559 | RecordPatField = | ||
560 | Attr* (NameRef ':')? Pat | ||
561 | |||
562 | TupleStructPat = | ||
563 | Path '(' fields:(Pat (',' Pat)* ','?)? ')' | ||
564 | |||
565 | TuplePat = | ||
566 | '(' fields:(Pat (',' Pat)* ','?)? ')' | ||
567 | |||
568 | ParenPat = | ||
569 | '(' Pat ')' | ||
570 | |||
571 | SlicePat = | ||
572 | '[' (Pat (',' Pat)* ','?)? ']' | ||
573 | |||
574 | PathPat = | ||
575 | Path | ||
576 | |||
577 | OrPat = | ||
578 | (Pat ('|' Pat)* '|'?) | ||
579 | |||
580 | BoxPat = | ||
581 | 'box' Pat | ||
582 | |||
583 | RestPat = | ||
584 | '..' | ||
585 | |||
586 | MacroPat = | ||
587 | MacroCall | ||