aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock48
-rw-r--r--crates/assists/src/handlers/inline_local_variable.rs45
-rw-r--r--crates/hir_def/src/body/lower.rs4
-rw-r--r--crates/hir_def/src/expr.rs5
-rw-r--r--crates/hir_ty/src/infer/expr.rs7
-rw-r--r--crates/parser/src/grammar/expressions/atom.rs16
-rw-r--r--crates/parser/src/syntax_kind/generated.rs8
-rw-r--r--crates/syntax/src/ast/generated/nodes.rs34
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0159_yield_expr.rast28
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0159_yield_expr.rs4
-rw-r--r--xtask/Cargo.toml2
-rw-r--r--xtask/src/ast_src.rs3
12 files changed, 152 insertions, 52 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0d23bcc9e..9498d8bf3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -26,9 +26,9 @@ dependencies = [
26 26
27[[package]] 27[[package]]
28name = "anyhow" 28name = "anyhow"
29version = "1.0.38" 29version = "1.0.37"
30source = "registry+https://github.com/rust-lang/crates.io-index" 30source = "registry+https://github.com/rust-lang/crates.io-index"
31checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" 31checksum = "ee67c11feeac938fae061b232e38e0b6d94f97a9df10e6271319325ac4c56a86"
32 32
33[[package]] 33[[package]]
34name = "anymap" 34name = "anymap"
@@ -118,9 +118,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
118 118
119[[package]] 119[[package]]
120name = "byteorder" 120name = "byteorder"
121version = "1.4.2" 121version = "1.3.4"
122source = "registry+https://github.com/rust-lang/crates.io-index" 122source = "registry+https://github.com/rust-lang/crates.io-index"
123checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" 123checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
124 124
125[[package]] 125[[package]]
126name = "cargo-platform" 126name = "cargo-platform"
@@ -269,9 +269,9 @@ dependencies = [
269 269
270[[package]] 270[[package]]
271name = "const_fn" 271name = "const_fn"
272version = "0.4.5" 272version = "0.4.4"
273source = "registry+https://github.com/rust-lang/crates.io-index" 273source = "registry+https://github.com/rust-lang/crates.io-index"
274checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" 274checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826"
275 275
276[[package]] 276[[package]]
277name = "crc32fast" 277name = "crc32fast"
@@ -791,9 +791,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
791 791
792[[package]] 792[[package]]
793name = "libc" 793name = "libc"
794version = "0.2.82" 794version = "0.2.81"
795source = "registry+https://github.com/rust-lang/crates.io-index" 795source = "registry+https://github.com/rust-lang/crates.io-index"
796checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" 796checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
797 797
798[[package]] 798[[package]]
799name = "libloading" 799name = "libloading"
@@ -825,9 +825,9 @@ dependencies = [
825 825
826[[package]] 826[[package]]
827name = "log" 827name = "log"
828version = "0.4.13" 828version = "0.4.11"
829source = "registry+https://github.com/rust-lang/crates.io-index" 829source = "registry+https://github.com/rust-lang/crates.io-index"
830checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2" 830checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
831dependencies = [ 831dependencies = [
832 "cfg-if 0.1.10", 832 "cfg-if 0.1.10",
833] 833]
@@ -1151,9 +1151,9 @@ checksum = "28b9b4df73455c861d7cbf8be42f01d3b373ed7f02e378d55fa84eafc6f638b1"
1151 1151
1152[[package]] 1152[[package]]
1153name = "pin-project-lite" 1153name = "pin-project-lite"
1154version = "0.2.4" 1154version = "0.2.0"
1155source = "registry+https://github.com/rust-lang/crates.io-index" 1155source = "registry+https://github.com/rust-lang/crates.io-index"
1156checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" 1156checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c"
1157 1157
1158[[package]] 1158[[package]]
1159name = "proc-macro2" 1159name = "proc-macro2"
@@ -1291,9 +1291,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
1291 1291
1292[[package]] 1292[[package]]
1293name = "regex" 1293name = "regex"
1294version = "1.4.3" 1294version = "1.4.2"
1295source = "registry+https://github.com/rust-lang/crates.io-index" 1295source = "registry+https://github.com/rust-lang/crates.io-index"
1296checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" 1296checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
1297dependencies = [ 1297dependencies = [
1298 "regex-syntax", 1298 "regex-syntax",
1299] 1299]
@@ -1310,9 +1310,9 @@ dependencies = [
1310 1310
1311[[package]] 1311[[package]]
1312name = "regex-syntax" 1312name = "regex-syntax"
1313version = "0.6.22" 1313version = "0.6.21"
1314source = "registry+https://github.com/rust-lang/crates.io-index" 1314source = "registry+https://github.com/rust-lang/crates.io-index"
1315checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" 1315checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
1316 1316
1317[[package]] 1317[[package]]
1318name = "rowan" 1318name = "rowan"
@@ -1541,9 +1541,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
1541 1541
1542[[package]] 1542[[package]]
1543name = "smallvec" 1543name = "smallvec"
1544version = "1.6.1" 1544version = "1.6.0"
1545source = "registry+https://github.com/rust-lang/crates.io-index" 1545source = "registry+https://github.com/rust-lang/crates.io-index"
1546checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" 1546checksum = "1a55ca5f3b68e41c979bf8c46a6f1da892ca4db8f94023ce0bd32407573b1ac0"
1547 1547
1548[[package]] 1548[[package]]
1549name = "smol_str" 1549name = "smol_str"
@@ -1577,9 +1577,9 @@ dependencies = [
1577 1577
1578[[package]] 1578[[package]]
1579name = "syn" 1579name = "syn"
1580version = "1.0.58" 1580version = "1.0.57"
1581source = "registry+https://github.com/rust-lang/crates.io-index" 1581source = "registry+https://github.com/rust-lang/crates.io-index"
1582checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" 1582checksum = "4211ce9909eb971f111059df92c45640aad50a619cf55cd76476be803c4c68e6"
1583dependencies = [ 1583dependencies = [
1584 "proc-macro2", 1584 "proc-macro2",
1585 "quote", 1585 "quote",
@@ -1662,9 +1662,9 @@ checksum = "db3c46be180f1af9673ebb27bc1235396f61ef6965b3fe0dbb2e624deb604f0e"
1662 1662
1663[[package]] 1663[[package]]
1664name = "thread_local" 1664name = "thread_local"
1665version = "1.1.0" 1665version = "1.0.1"
1666source = "registry+https://github.com/rust-lang/crates.io-index" 1666source = "registry+https://github.com/rust-lang/crates.io-index"
1667checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447" 1667checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
1668dependencies = [ 1668dependencies = [
1669 "lazy_static", 1669 "lazy_static",
1670] 1670]
@@ -1817,9 +1817,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
1817 1817
1818[[package]] 1818[[package]]
1819name = "ungrammar" 1819name = "ungrammar"
1820version = "1.6.0" 1820version = "1.7.0"
1821source = "registry+https://github.com/rust-lang/crates.io-index" 1821source = "registry+https://github.com/rust-lang/crates.io-index"
1822checksum = "f96cc1b6938f7c548fbcc630bac5c896ae77a130909829ab18b8eab78c51b7ee" 1822checksum = "7758fccf6038d5c368a17c7224abc85d6508d5ae266d5a3de25faac3cc168509"
1823 1823
1824[[package]] 1824[[package]]
1825name = "unicase" 1825name = "unicase"
diff --git a/crates/assists/src/handlers/inline_local_variable.rs b/crates/assists/src/handlers/inline_local_variable.rs
index dc798daaa..0e63a60e8 100644
--- a/crates/assists/src/handlers/inline_local_variable.rs
+++ b/crates/assists/src/handlers/inline_local_variable.rs
@@ -79,29 +79,30 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
79 None => return Ok(false), 79 None => return Ok(false),
80 }; 80 };
81 81
82 Ok(!matches!((&initializer_expr, usage_parent), 82 Ok(!matches!(
83 (&initializer_expr, usage_parent),
83 (ast::Expr::CallExpr(_), _) 84 (ast::Expr::CallExpr(_), _)
84 | (ast::Expr::IndexExpr(_), _) 85 | (ast::Expr::IndexExpr(_), _)
85 | (ast::Expr::MethodCallExpr(_), _) 86 | (ast::Expr::MethodCallExpr(_), _)
86 | (ast::Expr::FieldExpr(_), _) 87 | (ast::Expr::FieldExpr(_), _)
87 | (ast::Expr::TryExpr(_), _) 88 | (ast::Expr::TryExpr(_), _)
88 | (ast::Expr::RefExpr(_), _) 89 | (ast::Expr::RefExpr(_), _)
89 | (ast::Expr::Literal(_), _) 90 | (ast::Expr::Literal(_), _)
90 | (ast::Expr::TupleExpr(_), _) 91 | (ast::Expr::TupleExpr(_), _)
91 | (ast::Expr::ArrayExpr(_), _) 92 | (ast::Expr::ArrayExpr(_), _)
92 | (ast::Expr::ParenExpr(_), _) 93 | (ast::Expr::ParenExpr(_), _)
93 | (ast::Expr::PathExpr(_), _) 94 | (ast::Expr::PathExpr(_), _)
94 | (ast::Expr::BlockExpr(_), _) 95 | (ast::Expr::BlockExpr(_), _)
95 | (ast::Expr::EffectExpr(_), _) 96 | (ast::Expr::EffectExpr(_), _)
96 | (_, ast::Expr::CallExpr(_)) 97 | (_, ast::Expr::CallExpr(_))
97 | (_, ast::Expr::TupleExpr(_)) 98 | (_, ast::Expr::TupleExpr(_))
98 | (_, ast::Expr::ArrayExpr(_)) 99 | (_, ast::Expr::ArrayExpr(_))
99 | (_, ast::Expr::ParenExpr(_)) 100 | (_, ast::Expr::ParenExpr(_))
100 | (_, ast::Expr::ForExpr(_)) 101 | (_, ast::Expr::ForExpr(_))
101 | (_, ast::Expr::WhileExpr(_)) 102 | (_, ast::Expr::WhileExpr(_))
102 | (_, ast::Expr::BreakExpr(_)) 103 | (_, ast::Expr::BreakExpr(_))
103 | (_, ast::Expr::ReturnExpr(_)) 104 | (_, ast::Expr::ReturnExpr(_))
104 | (_, ast::Expr::MatchExpr(_)) 105 | (_, ast::Expr::MatchExpr(_))
105 )) 106 ))
106 }) 107 })
107 .collect::<Result<Vec<_>, _>>()?; 108 .collect::<Result<Vec<_>, _>>()?;
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index 27575c537..4ce5e5b72 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -386,6 +386,10 @@ impl ExprCollector<'_> {
386 let expr = e.expr().map(|e| self.collect_expr(e)); 386 let expr = e.expr().map(|e| self.collect_expr(e));
387 self.alloc_expr(Expr::Return { expr }, syntax_ptr) 387 self.alloc_expr(Expr::Return { expr }, syntax_ptr)
388 } 388 }
389 ast::Expr::YieldExpr(e) => {
390 let expr = e.expr().map(|e| self.collect_expr(e));
391 self.alloc_expr(Expr::Yield { expr }, syntax_ptr)
392 }
389 ast::Expr::RecordExpr(e) => { 393 ast::Expr::RecordExpr(e) => {
390 let path = e.path().and_then(|path| self.expander.parse_path(path)); 394 let path = e.path().and_then(|path| self.expander.parse_path(path));
391 let mut field_ptrs = Vec::new(); 395 let mut field_ptrs = Vec::new();
diff --git a/crates/hir_def/src/expr.rs b/crates/hir_def/src/expr.rs
index af01d32dc..a293df9f1 100644
--- a/crates/hir_def/src/expr.rs
+++ b/crates/hir_def/src/expr.rs
@@ -99,6 +99,9 @@ pub enum Expr {
99 Return { 99 Return {
100 expr: Option<ExprId>, 100 expr: Option<ExprId>,
101 }, 101 },
102 Yield {
103 expr: Option<ExprId>,
104 },
102 RecordLit { 105 RecordLit {
103 path: Option<Path>, 106 path: Option<Path>,
104 fields: Vec<RecordLitField>, 107 fields: Vec<RecordLitField>,
@@ -294,7 +297,7 @@ impl Expr {
294 } 297 }
295 } 298 }
296 Expr::Continue { .. } => {} 299 Expr::Continue { .. } => {}
297 Expr::Break { expr, .. } | Expr::Return { expr } => { 300 Expr::Break { expr, .. } | Expr::Return { expr } | Expr::Yield { expr } => {
298 if let Some(expr) = expr { 301 if let Some(expr) = expr {
299 f(*expr); 302 f(*expr);
300 } 303 }
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index f2fc69b2f..9bf3b51b0 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -367,6 +367,13 @@ impl<'a> InferenceContext<'a> {
367 } 367 }
368 Ty::simple(TypeCtor::Never) 368 Ty::simple(TypeCtor::Never)
369 } 369 }
370 Expr::Yield { expr } => {
371 // FIXME: track yield type for coercion
372 if let Some(expr) = expr {
373 self.infer_expr(*expr, &Expectation::none());
374 }
375 Ty::simple(TypeCtor::Never)
376 }
370 Expr::RecordLit { path, fields, spread } => { 377 Expr::RecordLit { path, fields, spread } => {
371 let (ty, def_id) = self.resolve_variant(path.as_ref()); 378 let (ty, def_id) = self.resolve_variant(path.as_ref());
372 if let Some(variant) = def_id { 379 if let Some(variant) = def_id {
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs
index d61950b96..093a9890d 100644
--- a/crates/parser/src/grammar/expressions/atom.rs
+++ b/crates/parser/src/grammar/expressions/atom.rs
@@ -50,6 +50,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
50 T![match], 50 T![match],
51 T![unsafe], 51 T![unsafe],
52 T![return], 52 T![return],
53 T![yield],
53 T![break], 54 T![break],
54 T![continue], 55 T![continue],
55 T![async], 56 T![async],
@@ -142,6 +143,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
142 block_expr_unchecked(p) 143 block_expr_unchecked(p)
143 } 144 }
144 T![return] => return_expr(p), 145 T![return] => return_expr(p),
146 T![yield] => yield_expr(p),
145 T![continue] => continue_expr(p), 147 T![continue] => continue_expr(p),
146 T![break] => break_expr(p, r), 148 T![break] => break_expr(p, r),
147 _ => { 149 _ => {
@@ -508,6 +510,20 @@ fn return_expr(p: &mut Parser) -> CompletedMarker {
508 } 510 }
509 m.complete(p, RETURN_EXPR) 511 m.complete(p, RETURN_EXPR)
510} 512}
513// test yield_expr
514// fn foo() {
515// yield;
516// yield 1;
517// }
518fn yield_expr(p: &mut Parser) -> CompletedMarker {
519 assert!(p.at(T![yield]));
520 let m = p.start();
521 p.bump(T![yield]);
522 if p.at_ts(EXPR_FIRST) {
523 expr(p);
524 }
525 m.complete(p, YIELD_EXPR)
526}
511 527
512// test continue_expr 528// test continue_expr
513// fn foo() { 529// fn foo() {
diff --git a/crates/parser/src/syntax_kind/generated.rs b/crates/parser/src/syntax_kind/generated.rs
index f69e71bdb..7d53cc4cd 100644
--- a/crates/parser/src/syntax_kind/generated.rs
+++ b/crates/parser/src/syntax_kind/generated.rs
@@ -101,6 +101,7 @@ pub enum SyntaxKind {
101 USE_KW, 101 USE_KW,
102 WHERE_KW, 102 WHERE_KW,
103 WHILE_KW, 103 WHILE_KW,
104 YIELD_KW,
104 AUTO_KW, 105 AUTO_KW,
105 DEFAULT_KW, 106 DEFAULT_KW,
106 EXISTENTIAL_KW, 107 EXISTENTIAL_KW,
@@ -186,6 +187,7 @@ pub enum SyntaxKind {
186 LABEL, 187 LABEL,
187 BLOCK_EXPR, 188 BLOCK_EXPR,
188 RETURN_EXPR, 189 RETURN_EXPR,
190 YIELD_EXPR,
189 MATCH_EXPR, 191 MATCH_EXPR,
190 MATCH_ARM_LIST, 192 MATCH_ARM_LIST,
191 MATCH_ARM, 193 MATCH_ARM,
@@ -263,7 +265,8 @@ impl SyntaxKind {
263 | IMPL_KW | IN_KW | LET_KW | LOOP_KW | MACRO_KW | MATCH_KW | MOD_KW | MOVE_KW 265 | IMPL_KW | IN_KW | LET_KW | LOOP_KW | MACRO_KW | MATCH_KW | MOD_KW | MOVE_KW
264 | MUT_KW | PUB_KW | REF_KW | RETURN_KW | SELF_KW | STATIC_KW | STRUCT_KW | SUPER_KW 266 | MUT_KW | PUB_KW | REF_KW | RETURN_KW | SELF_KW | STATIC_KW | STRUCT_KW | SUPER_KW
265 | TRAIT_KW | TRUE_KW | TRY_KW | TYPE_KW | UNSAFE_KW | USE_KW | WHERE_KW | WHILE_KW 267 | TRAIT_KW | TRUE_KW | TRY_KW | TYPE_KW | UNSAFE_KW | USE_KW | WHERE_KW | WHILE_KW
266 | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW | RAW_KW | MACRO_RULES_KW => true, 268 | YIELD_KW | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW | RAW_KW
269 | MACRO_RULES_KW => true,
267 _ => false, 270 _ => false,
268 } 271 }
269 } 272 }
@@ -326,6 +329,7 @@ impl SyntaxKind {
326 "use" => USE_KW, 329 "use" => USE_KW,
327 "where" => WHERE_KW, 330 "where" => WHERE_KW,
328 "while" => WHILE_KW, 331 "while" => WHILE_KW,
332 "yield" => YIELD_KW,
329 _ => return None, 333 _ => return None,
330 }; 334 };
331 Some(kw) 335 Some(kw)
@@ -366,4 +370,4 @@ impl SyntaxKind {
366 } 370 }
367} 371}
368#[macro_export] 372#[macro_export]
369macro_rules ! T { [;] => { $ crate :: SyntaxKind :: SEMICOLON } ; [,] => { $ crate :: SyntaxKind :: COMMA } ; ['('] => { $ crate :: SyntaxKind :: L_PAREN } ; [')'] => { $ crate :: SyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: SyntaxKind :: L_CURLY } ; ['}'] => { $ crate :: SyntaxKind :: R_CURLY } ; ['['] => { $ crate :: SyntaxKind :: L_BRACK } ; [']'] => { $ crate :: SyntaxKind :: R_BRACK } ; [<] => { $ crate :: SyntaxKind :: L_ANGLE } ; [>] => { $ crate :: SyntaxKind :: R_ANGLE } ; [@] => { $ crate :: SyntaxKind :: AT } ; [#] => { $ crate :: SyntaxKind :: POUND } ; [~] => { $ crate :: SyntaxKind :: TILDE } ; [?] => { $ crate :: SyntaxKind :: QUESTION } ; [$] => { $ crate :: SyntaxKind :: DOLLAR } ; [&] => { $ crate :: SyntaxKind :: AMP } ; [|] => { $ crate :: SyntaxKind :: PIPE } ; [+] => { $ crate :: SyntaxKind :: PLUS } ; [*] => { $ crate :: SyntaxKind :: STAR } ; [/] => { $ crate :: SyntaxKind :: SLASH } ; [^] => { $ crate :: SyntaxKind :: CARET } ; [%] => { $ crate :: SyntaxKind :: PERCENT } ; [_] => { $ crate :: SyntaxKind :: UNDERSCORE } ; [.] => { $ crate :: SyntaxKind :: DOT } ; [..] => { $ crate :: SyntaxKind :: DOT2 } ; [...] => { $ crate :: SyntaxKind :: DOT3 } ; [..=] => { $ crate :: SyntaxKind :: DOT2EQ } ; [:] => { $ crate :: SyntaxKind :: COLON } ; [::] => { $ crate :: SyntaxKind :: COLON2 } ; [=] => { $ crate :: SyntaxKind :: EQ } ; [==] => { $ crate :: SyntaxKind :: EQ2 } ; [=>] => { $ crate :: SyntaxKind :: FAT_ARROW } ; [!] => { $ crate :: SyntaxKind :: BANG } ; [!=] => { $ crate :: SyntaxKind :: NEQ } ; [-] => { $ crate :: SyntaxKind :: MINUS } ; [->] => { $ crate :: SyntaxKind :: THIN_ARROW } ; [<=] => { $ crate :: SyntaxKind :: LTEQ } ; [>=] => { $ crate :: SyntaxKind :: GTEQ } ; [+=] => { $ crate :: SyntaxKind :: PLUSEQ } ; [-=] => { $ crate :: SyntaxKind :: MINUSEQ } ; [|=] => { $ crate :: SyntaxKind :: PIPEEQ } ; [&=] => { $ crate :: SyntaxKind :: AMPEQ } ; [^=] => { $ crate :: SyntaxKind :: CARETEQ } ; [/=] => { $ crate :: SyntaxKind :: SLASHEQ } ; [*=] => { $ crate :: SyntaxKind :: STAREQ } ; [%=] => { $ crate :: SyntaxKind :: PERCENTEQ } ; [&&] => { $ crate :: SyntaxKind :: AMP2 } ; [||] => { $ crate :: SyntaxKind :: PIPE2 } ; [<<] => { $ crate :: SyntaxKind :: SHL } ; [>>] => { $ crate :: SyntaxKind :: SHR } ; [<<=] => { $ crate :: SyntaxKind :: SHLEQ } ; [>>=] => { $ crate :: SyntaxKind :: SHREQ } ; [as] => { $ crate :: SyntaxKind :: AS_KW } ; [async] => { $ crate :: SyntaxKind :: ASYNC_KW } ; [await] => { $ crate :: SyntaxKind :: AWAIT_KW } ; [box] => { $ crate :: SyntaxKind :: BOX_KW } ; [break] => { $ crate :: SyntaxKind :: BREAK_KW } ; [const] => { $ crate :: SyntaxKind :: CONST_KW } ; [continue] => { $ crate :: SyntaxKind :: CONTINUE_KW } ; [crate] => { $ crate :: SyntaxKind :: CRATE_KW } ; [dyn] => { $ crate :: SyntaxKind :: DYN_KW } ; [else] => { $ crate :: SyntaxKind :: ELSE_KW } ; [enum] => { $ crate :: SyntaxKind :: ENUM_KW } ; [extern] => { $ crate :: SyntaxKind :: EXTERN_KW } ; [false] => { $ crate :: SyntaxKind :: FALSE_KW } ; [fn] => { $ crate :: SyntaxKind :: FN_KW } ; [for] => { $ crate :: SyntaxKind :: FOR_KW } ; [if] => { $ crate :: SyntaxKind :: IF_KW } ; [impl] => { $ crate :: SyntaxKind :: IMPL_KW } ; [in] => { $ crate :: SyntaxKind :: IN_KW } ; [let] => { $ crate :: SyntaxKind :: LET_KW } ; [loop] => { $ crate :: SyntaxKind :: LOOP_KW } ; [macro] => { $ crate :: SyntaxKind :: MACRO_KW } ; [match] => { $ crate :: SyntaxKind :: MATCH_KW } ; [mod] => { $ crate :: SyntaxKind :: MOD_KW } ; [move] => { $ crate :: SyntaxKind :: MOVE_KW } ; [mut] => { $ crate :: SyntaxKind :: MUT_KW } ; [pub] => { $ crate :: SyntaxKind :: PUB_KW } ; [ref] => { $ crate :: SyntaxKind :: REF_KW } ; [return] => { $ crate :: SyntaxKind :: RETURN_KW } ; [self] => { $ crate :: SyntaxKind :: SELF_KW } ; [static] => { $ crate :: SyntaxKind :: STATIC_KW } ; [struct] => { $ crate :: SyntaxKind :: STRUCT_KW } ; [super] => { $ crate :: SyntaxKind :: SUPER_KW } ; [trait] => { $ crate :: SyntaxKind :: TRAIT_KW } ; [true] => { $ crate :: SyntaxKind :: TRUE_KW } ; [try] => { $ crate :: SyntaxKind :: TRY_KW } ; [type] => { $ crate :: SyntaxKind :: TYPE_KW } ; [unsafe] => { $ crate :: SyntaxKind :: UNSAFE_KW } ; [use] => { $ crate :: SyntaxKind :: USE_KW } ; [where] => { $ crate :: SyntaxKind :: WHERE_KW } ; [while] => { $ crate :: SyntaxKind :: WHILE_KW } ; [auto] => { $ crate :: SyntaxKind :: AUTO_KW } ; [default] => { $ crate :: SyntaxKind :: DEFAULT_KW } ; [existential] => { $ crate :: SyntaxKind :: EXISTENTIAL_KW } ; [union] => { $ crate :: SyntaxKind :: UNION_KW } ; [raw] => { $ crate :: SyntaxKind :: RAW_KW } ; [macro_rules] => { $ crate :: SyntaxKind :: MACRO_RULES_KW } ; [lifetime_ident] => { $ crate :: SyntaxKind :: LIFETIME_IDENT } ; [ident] => { $ crate :: SyntaxKind :: IDENT } ; [shebang] => { $ crate :: SyntaxKind :: SHEBANG } ; } 373macro_rules ! T { [;] => { $ crate :: SyntaxKind :: SEMICOLON } ; [,] => { $ crate :: SyntaxKind :: COMMA } ; ['('] => { $ crate :: SyntaxKind :: L_PAREN } ; [')'] => { $ crate :: SyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: SyntaxKind :: L_CURLY } ; ['}'] => { $ crate :: SyntaxKind :: R_CURLY } ; ['['] => { $ crate :: SyntaxKind :: L_BRACK } ; [']'] => { $ crate :: SyntaxKind :: R_BRACK } ; [<] => { $ crate :: SyntaxKind :: L_ANGLE } ; [>] => { $ crate :: SyntaxKind :: R_ANGLE } ; [@] => { $ crate :: SyntaxKind :: AT } ; [#] => { $ crate :: SyntaxKind :: POUND } ; [~] => { $ crate :: SyntaxKind :: TILDE } ; [?] => { $ crate :: SyntaxKind :: QUESTION } ; [$] => { $ crate :: SyntaxKind :: DOLLAR } ; [&] => { $ crate :: SyntaxKind :: AMP } ; [|] => { $ crate :: SyntaxKind :: PIPE } ; [+] => { $ crate :: SyntaxKind :: PLUS } ; [*] => { $ crate :: SyntaxKind :: STAR } ; [/] => { $ crate :: SyntaxKind :: SLASH } ; [^] => { $ crate :: SyntaxKind :: CARET } ; [%] => { $ crate :: SyntaxKind :: PERCENT } ; [_] => { $ crate :: SyntaxKind :: UNDERSCORE } ; [.] => { $ crate :: SyntaxKind :: DOT } ; [..] => { $ crate :: SyntaxKind :: DOT2 } ; [...] => { $ crate :: SyntaxKind :: DOT3 } ; [..=] => { $ crate :: SyntaxKind :: DOT2EQ } ; [:] => { $ crate :: SyntaxKind :: COLON } ; [::] => { $ crate :: SyntaxKind :: COLON2 } ; [=] => { $ crate :: SyntaxKind :: EQ } ; [==] => { $ crate :: SyntaxKind :: EQ2 } ; [=>] => { $ crate :: SyntaxKind :: FAT_ARROW } ; [!] => { $ crate :: SyntaxKind :: BANG } ; [!=] => { $ crate :: SyntaxKind :: NEQ } ; [-] => { $ crate :: SyntaxKind :: MINUS } ; [->] => { $ crate :: SyntaxKind :: THIN_ARROW } ; [<=] => { $ crate :: SyntaxKind :: LTEQ } ; [>=] => { $ crate :: SyntaxKind :: GTEQ } ; [+=] => { $ crate :: SyntaxKind :: PLUSEQ } ; [-=] => { $ crate :: SyntaxKind :: MINUSEQ } ; [|=] => { $ crate :: SyntaxKind :: PIPEEQ } ; [&=] => { $ crate :: SyntaxKind :: AMPEQ } ; [^=] => { $ crate :: SyntaxKind :: CARETEQ } ; [/=] => { $ crate :: SyntaxKind :: SLASHEQ } ; [*=] => { $ crate :: SyntaxKind :: STAREQ } ; [%=] => { $ crate :: SyntaxKind :: PERCENTEQ } ; [&&] => { $ crate :: SyntaxKind :: AMP2 } ; [||] => { $ crate :: SyntaxKind :: PIPE2 } ; [<<] => { $ crate :: SyntaxKind :: SHL } ; [>>] => { $ crate :: SyntaxKind :: SHR } ; [<<=] => { $ crate :: SyntaxKind :: SHLEQ } ; [>>=] => { $ crate :: SyntaxKind :: SHREQ } ; [as] => { $ crate :: SyntaxKind :: AS_KW } ; [async] => { $ crate :: SyntaxKind :: ASYNC_KW } ; [await] => { $ crate :: SyntaxKind :: AWAIT_KW } ; [box] => { $ crate :: SyntaxKind :: BOX_KW } ; [break] => { $ crate :: SyntaxKind :: BREAK_KW } ; [const] => { $ crate :: SyntaxKind :: CONST_KW } ; [continue] => { $ crate :: SyntaxKind :: CONTINUE_KW } ; [crate] => { $ crate :: SyntaxKind :: CRATE_KW } ; [dyn] => { $ crate :: SyntaxKind :: DYN_KW } ; [else] => { $ crate :: SyntaxKind :: ELSE_KW } ; [enum] => { $ crate :: SyntaxKind :: ENUM_KW } ; [extern] => { $ crate :: SyntaxKind :: EXTERN_KW } ; [false] => { $ crate :: SyntaxKind :: FALSE_KW } ; [fn] => { $ crate :: SyntaxKind :: FN_KW } ; [for] => { $ crate :: SyntaxKind :: FOR_KW } ; [if] => { $ crate :: SyntaxKind :: IF_KW } ; [impl] => { $ crate :: SyntaxKind :: IMPL_KW } ; [in] => { $ crate :: SyntaxKind :: IN_KW } ; [let] => { $ crate :: SyntaxKind :: LET_KW } ; [loop] => { $ crate :: SyntaxKind :: LOOP_KW } ; [macro] => { $ crate :: SyntaxKind :: MACRO_KW } ; [match] => { $ crate :: SyntaxKind :: MATCH_KW } ; [mod] => { $ crate :: SyntaxKind :: MOD_KW } ; [move] => { $ crate :: SyntaxKind :: MOVE_KW } ; [mut] => { $ crate :: SyntaxKind :: MUT_KW } ; [pub] => { $ crate :: SyntaxKind :: PUB_KW } ; [ref] => { $ crate :: SyntaxKind :: REF_KW } ; [return] => { $ crate :: SyntaxKind :: RETURN_KW } ; [self] => { $ crate :: SyntaxKind :: SELF_KW } ; [static] => { $ crate :: SyntaxKind :: STATIC_KW } ; [struct] => { $ crate :: SyntaxKind :: STRUCT_KW } ; [super] => { $ crate :: SyntaxKind :: SUPER_KW } ; [trait] => { $ crate :: SyntaxKind :: TRAIT_KW } ; [true] => { $ crate :: SyntaxKind :: TRUE_KW } ; [try] => { $ crate :: SyntaxKind :: TRY_KW } ; [type] => { $ crate :: SyntaxKind :: TYPE_KW } ; [unsafe] => { $ crate :: SyntaxKind :: UNSAFE_KW } ; [use] => { $ crate :: SyntaxKind :: USE_KW } ; [where] => { $ crate :: SyntaxKind :: WHERE_KW } ; [while] => { $ crate :: SyntaxKind :: WHILE_KW } ; [yield] => { $ crate :: SyntaxKind :: YIELD_KW } ; [auto] => { $ crate :: SyntaxKind :: AUTO_KW } ; [default] => { $ crate :: SyntaxKind :: DEFAULT_KW } ; [existential] => { $ crate :: SyntaxKind :: EXISTENTIAL_KW } ; [union] => { $ crate :: SyntaxKind :: UNION_KW } ; [raw] => { $ crate :: SyntaxKind :: RAW_KW } ; [macro_rules] => { $ crate :: SyntaxKind :: MACRO_RULES_KW } ; [lifetime_ident] => { $ crate :: SyntaxKind :: LIFETIME_IDENT } ; [ident] => { $ crate :: SyntaxKind :: IDENT } ; [shebang] => { $ crate :: SyntaxKind :: SHEBANG } ; }
diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs
index 92ed2ee9d..9c96d3d07 100644
--- a/crates/syntax/src/ast/generated/nodes.rs
+++ b/crates/syntax/src/ast/generated/nodes.rs
@@ -931,6 +931,15 @@ impl WhileExpr {
931 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 931 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
932} 932}
933#[derive(Debug, Clone, PartialEq, Eq, Hash)] 933#[derive(Debug, Clone, PartialEq, Eq, Hash)]
934pub struct YieldExpr {
935 pub(crate) syntax: SyntaxNode,
936}
937impl ast::AttrsOwner for YieldExpr {}
938impl YieldExpr {
939 pub fn yield_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![yield]) }
940 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
941}
942#[derive(Debug, Clone, PartialEq, Eq, Hash)]
934pub struct Label { 943pub struct Label {
935 pub(crate) syntax: SyntaxNode, 944 pub(crate) syntax: SyntaxNode,
936} 945}
@@ -1334,6 +1343,7 @@ pub enum Expr {
1334 TryExpr(TryExpr), 1343 TryExpr(TryExpr),
1335 TupleExpr(TupleExpr), 1344 TupleExpr(TupleExpr),
1336 WhileExpr(WhileExpr), 1345 WhileExpr(WhileExpr),
1346 YieldExpr(YieldExpr),
1337} 1347}
1338#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1348#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1339pub enum Item { 1349pub enum Item {
@@ -2386,6 +2396,17 @@ impl AstNode for WhileExpr {
2386 } 2396 }
2387 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2397 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2388} 2398}
2399impl AstNode for YieldExpr {
2400 fn can_cast(kind: SyntaxKind) -> bool { kind == YIELD_EXPR }
2401 fn cast(syntax: SyntaxNode) -> Option<Self> {
2402 if Self::can_cast(syntax.kind()) {
2403 Some(Self { syntax })
2404 } else {
2405 None
2406 }
2407 }
2408 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2409}
2389impl AstNode for Label { 2410impl AstNode for Label {
2390 fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL } 2411 fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL }
2391 fn cast(syntax: SyntaxNode) -> Option<Self> { 2412 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3028,6 +3049,9 @@ impl From<TupleExpr> for Expr {
3028impl From<WhileExpr> for Expr { 3049impl From<WhileExpr> for Expr {
3029 fn from(node: WhileExpr) -> Expr { Expr::WhileExpr(node) } 3050 fn from(node: WhileExpr) -> Expr { Expr::WhileExpr(node) }
3030} 3051}
3052impl From<YieldExpr> for Expr {
3053 fn from(node: YieldExpr) -> Expr { Expr::YieldExpr(node) }
3054}
3031impl AstNode for Expr { 3055impl AstNode for Expr {
3032 fn can_cast(kind: SyntaxKind) -> bool { 3056 fn can_cast(kind: SyntaxKind) -> bool {
3033 match kind { 3057 match kind {
@@ -3035,7 +3059,8 @@ impl AstNode for Expr {
3035 | CAST_EXPR | CLOSURE_EXPR | CONTINUE_EXPR | EFFECT_EXPR | FIELD_EXPR | FOR_EXPR 3059 | CAST_EXPR | CLOSURE_EXPR | CONTINUE_EXPR | EFFECT_EXPR | FIELD_EXPR | FOR_EXPR
3036 | IF_EXPR | INDEX_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR 3060 | IF_EXPR | INDEX_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR
3037 | METHOD_CALL_EXPR | PAREN_EXPR | PATH_EXPR | PREFIX_EXPR | RANGE_EXPR 3061 | METHOD_CALL_EXPR | PAREN_EXPR | PATH_EXPR | PREFIX_EXPR | RANGE_EXPR
3038 | RECORD_EXPR | REF_EXPR | RETURN_EXPR | TRY_EXPR | TUPLE_EXPR | WHILE_EXPR => true, 3062 | RECORD_EXPR | REF_EXPR | RETURN_EXPR | TRY_EXPR | TUPLE_EXPR | WHILE_EXPR
3063 | YIELD_EXPR => true,
3039 _ => false, 3064 _ => false,
3040 } 3065 }
3041 } 3066 }
@@ -3071,6 +3096,7 @@ impl AstNode for Expr {
3071 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }), 3096 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
3072 TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }), 3097 TUPLE_EXPR => Expr::TupleExpr(TupleExpr { syntax }),
3073 WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }), 3098 WHILE_EXPR => Expr::WhileExpr(WhileExpr { syntax }),
3099 YIELD_EXPR => Expr::YieldExpr(YieldExpr { syntax }),
3074 _ => return None, 3100 _ => return None,
3075 }; 3101 };
3076 Some(res) 3102 Some(res)
@@ -3107,6 +3133,7 @@ impl AstNode for Expr {
3107 Expr::TryExpr(it) => &it.syntax, 3133 Expr::TryExpr(it) => &it.syntax,
3108 Expr::TupleExpr(it) => &it.syntax, 3134 Expr::TupleExpr(it) => &it.syntax,
3109 Expr::WhileExpr(it) => &it.syntax, 3135 Expr::WhileExpr(it) => &it.syntax,
3136 Expr::YieldExpr(it) => &it.syntax,
3110 } 3137 }
3111 } 3138 }
3112} 3139}
@@ -3983,6 +4010,11 @@ impl std::fmt::Display for WhileExpr {
3983 std::fmt::Display::fmt(self.syntax(), f) 4010 std::fmt::Display::fmt(self.syntax(), f)
3984 } 4011 }
3985} 4012}
4013impl std::fmt::Display for YieldExpr {
4014 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4015 std::fmt::Display::fmt(self.syntax(), f)
4016 }
4017}
3986impl std::fmt::Display for Label { 4018impl std::fmt::Display for Label {
3987 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4019 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3988 std::fmt::Display::fmt(self.syntax(), f) 4020 std::fmt::Display::fmt(self.syntax(), f)
diff --git a/crates/syntax/test_data/parser/inline/ok/0159_yield_expr.rast b/crates/syntax/test_data/parser/inline/ok/0159_yield_expr.rast
new file mode 100644
index 000000000..05fc90743
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0159_yield_expr.rast
@@ -0,0 +1,28 @@
1[email protected]
2 [email protected]
3 [email protected] "fn"
4 [email protected] " "
5 [email protected]
6 [email protected] "foo"
7 [email protected]
8 [email protected] "("
9 [email protected] ")"
10 [email protected] " "
11 [email protected]
12 [email protected] "{"
13 [email protected] "\n "
14 [email protected]
15 [email protected]
16 [email protected] "yield"
17 [email protected] ";"
18 [email protected] "\n "
19 [email protected]
20 [email protected]
21 [email protected] "yield"
22 [email protected] " "
23 [email protected]
24 [email protected] "1"
25 [email protected] ";"
26 [email protected] "\n"
27 [email protected] "}"
28 [email protected] "\n"
diff --git a/crates/syntax/test_data/parser/inline/ok/0159_yield_expr.rs b/crates/syntax/test_data/parser/inline/ok/0159_yield_expr.rs
new file mode 100644
index 000000000..596e221f7
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0159_yield_expr.rs
@@ -0,0 +1,4 @@
1fn foo() {
2 yield;
3 yield 1;
4}
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index 7a2937f0e..61a944c13 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -15,7 +15,7 @@ flate2 = "1.0"
15pico-args = "0.3.1" 15pico-args = "0.3.1"
16proc-macro2 = "1.0.8" 16proc-macro2 = "1.0.8"
17quote = "1.0.2" 17quote = "1.0.2"
18ungrammar = "1.6" 18ungrammar = "1.7"
19walkdir = "2.3.1" 19walkdir = "2.3.1"
20write-json = "0.1.0" 20write-json = "0.1.0"
21xshell = "0.1" 21xshell = "0.1"
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs
index 2b8012bdd..046d68f52 100644
--- a/xtask/src/ast_src.rs
+++ b/xtask/src/ast_src.rs
@@ -68,7 +68,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
68 "as", "async", "await", "box", "break", "const", "continue", "crate", "dyn", "else", 68 "as", "async", "await", "box", "break", "const", "continue", "crate", "dyn", "else",
69 "enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "macro", 69 "enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "macro",
70 "match", "mod", "move", "mut", "pub", "ref", "return", "self", "static", "struct", "super", 70 "match", "mod", "move", "mut", "pub", "ref", "return", "self", "static", "struct", "super",
71 "trait", "true", "try", "type", "unsafe", "use", "where", "while", 71 "trait", "true", "try", "type", "unsafe", "use", "where", "while", "yield",
72 ], 72 ],
73 contextual_keywords: &["auto", "default", "existential", "union", "raw", "macro_rules"], 73 contextual_keywords: &["auto", "default", "existential", "union", "raw", "macro_rules"],
74 literals: &["INT_NUMBER", "FLOAT_NUMBER", "CHAR", "BYTE", "STRING", "BYTE_STRING"], 74 literals: &["INT_NUMBER", "FLOAT_NUMBER", "CHAR", "BYTE", "STRING", "BYTE_STRING"],
@@ -149,6 +149,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
149 "LABEL", 149 "LABEL",
150 "BLOCK_EXPR", 150 "BLOCK_EXPR",
151 "RETURN_EXPR", 151 "RETURN_EXPR",
152 "YIELD_EXPR",
152 "MATCH_EXPR", 153 "MATCH_EXPR",
153 "MATCH_ARM_LIST", 154 "MATCH_ARM_LIST",
154 "MATCH_ARM", 155 "MATCH_ARM",