]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_parse/src/parser/stmt.rs
Detect bare blocks with type ascription that were meant to be a `struct` literal
[rust.git] / compiler / rustc_parse / src / parser / stmt.rs
1 use super::attr::DEFAULT_INNER_ATTR_FORBIDDEN;
2 use super::diagnostics::{AttemptLocalParseRecovery, Error};
3 use super::expr::LhsExpr;
4 use super::pat::RecoverComma;
5 use super::path::PathStyle;
6 use super::TrailingToken;
7 use super::{AttrWrapper, BlockMode, ForceCollect, Parser, Restrictions, SemiColonMode};
8 use crate::maybe_whole;
9
10 use rustc_ast as ast;
11 use rustc_ast::ptr::P;
12 use rustc_ast::token::{self, TokenKind};
13 use rustc_ast::util::classify;
14 use rustc_ast::{
15     AstLike, AttrStyle, AttrVec, Attribute, LocalKind, MacCall, MacCallStmt, MacStmtStyle,
16 };
17 use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt};
18 use rustc_ast::{StmtKind, DUMMY_NODE_ID};
19 use rustc_errors::{Applicability, PResult};
20 use rustc_span::source_map::{BytePos, Span};
21 use rustc_span::symbol::{kw, sym};
22
23 use std::mem;
24
25 impl<'a> Parser<'a> {
26     /// Parses a statement. This stops just before trailing semicolons on everything but items.
27     /// e.g., a `StmtKind::Semi` parses to a `StmtKind::Expr`, leaving the trailing `;` unconsumed.
28     // Public for rustfmt usage.
29     pub fn parse_stmt(&mut self, force_collect: ForceCollect) -> PResult<'a, Option<Stmt>> {
30         Ok(self.parse_stmt_without_recovery(false, force_collect).unwrap_or_else(|mut e| {
31             e.emit();
32             self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
33             None
34         }))
35     }
36
37     /// If `force_capture` is true, forces collection of tokens regardless of whether
38     /// or not we have attributes
39     crate fn parse_stmt_without_recovery(
40         &mut self,
41         capture_semi: bool,
42         force_collect: ForceCollect,
43     ) -> PResult<'a, Option<Stmt>> {
44         let attrs = self.parse_outer_attributes()?;
45         let lo = self.token.span;
46
47         // Don't use `maybe_whole` so that we have precise control
48         // over when we bump the parser
49         if let token::Interpolated(nt) = &self.token.kind {
50             if let token::NtStmt(stmt) = &**nt {
51                 let mut stmt = stmt.clone();
52                 self.bump();
53                 stmt.visit_attrs(|stmt_attrs| {
54                     attrs.prepend_to_nt_inner(stmt_attrs);
55                 });
56                 return Ok(Some(stmt));
57             }
58         }
59
60         Ok(Some(if self.token.is_keyword(kw::Let) {
61             self.parse_local_mk(lo, attrs, capture_semi, force_collect)?
62         } else if self.is_kw_followed_by_ident(kw::Mut) {
63             self.recover_stmt_local(lo, attrs, "missing keyword", "let mut")?
64         } else if self.is_kw_followed_by_ident(kw::Auto) {
65             self.bump(); // `auto`
66             let msg = "write `let` instead of `auto` to introduce a new variable";
67             self.recover_stmt_local(lo, attrs, msg, "let")?
68         } else if self.is_kw_followed_by_ident(sym::var) {
69             self.bump(); // `var`
70             let msg = "write `let` instead of `var` to introduce a new variable";
71             self.recover_stmt_local(lo, attrs, msg, "let")?
72         } else if self.check_path() && !self.token.is_qpath_start() && !self.is_path_start_item() {
73             // We have avoided contextual keywords like `union`, items with `crate` visibility,
74             // or `auto trait` items. We aim to parse an arbitrary path `a::b` but not something
75             // that starts like a path (1 token), but it fact not a path.
76             // Also, we avoid stealing syntax from `parse_item_`.
77             if force_collect == ForceCollect::Yes {
78                 self.collect_tokens_no_attrs(|this| this.parse_stmt_path_start(lo, attrs))
79             } else {
80                 self.parse_stmt_path_start(lo, attrs)
81             }?
82         } else if let Some(item) =
83             self.parse_item_common(attrs.clone(), false, true, |_| true, force_collect)?
84         {
85             // FIXME: Bad copy of attrs
86             self.mk_stmt(lo.to(item.span), StmtKind::Item(P(item)))
87         } else if self.eat(&token::Semi) {
88             // Do not attempt to parse an expression if we're done here.
89             self.error_outer_attrs(&attrs.take_for_recovery());
90             self.mk_stmt(lo, StmtKind::Empty)
91         } else if self.token != token::CloseDelim(token::Brace) {
92             // Remainder are line-expr stmts.
93             let e = if force_collect == ForceCollect::Yes {
94                 self.collect_tokens_no_attrs(|this| {
95                     this.parse_expr_res(Restrictions::STMT_EXPR, Some(attrs))
96                 })
97             } else {
98                 self.parse_expr_res(Restrictions::STMT_EXPR, Some(attrs))
99             }?;
100             self.mk_stmt(lo.to(e.span), StmtKind::Expr(e))
101         } else {
102             self.error_outer_attrs(&attrs.take_for_recovery());
103             return Ok(None);
104         }))
105     }
106
107     fn parse_stmt_path_start(&mut self, lo: Span, attrs: AttrWrapper) -> PResult<'a, Stmt> {
108         let stmt = self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
109             let path = this.parse_path(PathStyle::Expr)?;
110
111             if this.eat(&token::Not) {
112                 let stmt_mac = this.parse_stmt_mac(lo, attrs.into(), path)?;
113                 if this.token == token::Semi {
114                     return Ok((stmt_mac, TrailingToken::Semi));
115                 } else {
116                     return Ok((stmt_mac, TrailingToken::None));
117                 }
118             }
119
120             let expr = if this.eat(&token::OpenDelim(token::Brace)) {
121                 this.parse_struct_expr(None, path, AttrVec::new(), true)?
122             } else {
123                 let hi = this.prev_token.span;
124                 this.mk_expr(lo.to(hi), ExprKind::Path(None, path), AttrVec::new())
125             };
126
127             let expr = this.with_res(Restrictions::STMT_EXPR, |this| {
128                 this.parse_dot_or_call_expr_with(expr, lo, attrs)
129             })?;
130             // `DUMMY_SP` will get overwritten later in this function
131             Ok((this.mk_stmt(rustc_span::DUMMY_SP, StmtKind::Expr(expr)), TrailingToken::None))
132         })?;
133
134         if let StmtKind::Expr(expr) = stmt.kind {
135             // Perform this outside of the `collect_tokens_trailing_token` closure,
136             // since our outer attributes do not apply to this part of the expression
137             let expr = self.with_res(Restrictions::STMT_EXPR, |this| {
138                 this.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(expr))
139             })?;
140             Ok(self.mk_stmt(lo.to(self.prev_token.span), StmtKind::Expr(expr)))
141         } else {
142             Ok(stmt)
143         }
144     }
145
146     /// Parses a statement macro `mac!(args)` provided a `path` representing `mac`.
147     /// At this point, the `!` token after the path has already been eaten.
148     fn parse_stmt_mac(&mut self, lo: Span, attrs: AttrVec, path: ast::Path) -> PResult<'a, Stmt> {
149         let args = self.parse_mac_args()?;
150         let delim = args.delim();
151         let hi = self.prev_token.span;
152
153         let style =
154             if delim == token::Brace { MacStmtStyle::Braces } else { MacStmtStyle::NoBraces };
155
156         let mac = MacCall { path, args, prior_type_ascription: self.last_type_ascription };
157
158         let kind = if delim == token::Brace || self.token == token::Semi || self.token == token::Eof
159         {
160             StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None }))
161         } else {
162             // Since none of the above applied, this is an expression statement macro.
163             let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new());
164             let e = self.maybe_recover_from_bad_qpath(e, true)?;
165             let e = self.parse_dot_or_call_expr_with(e, lo, attrs.into())?;
166             let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?;
167             StmtKind::Expr(e)
168         };
169         Ok(self.mk_stmt(lo.to(hi), kind))
170     }
171
172     /// Error on outer attributes in this context.
173     /// Also error if the previous token was a doc comment.
174     fn error_outer_attrs(&self, attrs: &[Attribute]) {
175         if let [.., last] = attrs {
176             if last.is_doc_comment() {
177                 self.span_err(last.span, Error::UselessDocComment).emit();
178             } else if attrs.iter().any(|a| a.style == AttrStyle::Outer) {
179                 self.struct_span_err(last.span, "expected statement after outer attribute").emit();
180             }
181         }
182     }
183
184     fn recover_stmt_local(
185         &mut self,
186         lo: Span,
187         attrs: AttrWrapper,
188         msg: &str,
189         sugg: &str,
190     ) -> PResult<'a, Stmt> {
191         let stmt = self.recover_local_after_let(lo, attrs)?;
192         self.struct_span_err(lo, "invalid variable declaration")
193             .span_suggestion(lo, msg, sugg.to_string(), Applicability::MachineApplicable)
194             .emit();
195         Ok(stmt)
196     }
197
198     fn parse_local_mk(
199         &mut self,
200         lo: Span,
201         attrs: AttrWrapper,
202         capture_semi: bool,
203         force_collect: ForceCollect,
204     ) -> PResult<'a, Stmt> {
205         self.collect_tokens_trailing_token(attrs, force_collect, |this, attrs| {
206             this.expect_keyword(kw::Let)?;
207             let local = this.parse_local(attrs.into())?;
208             let trailing = if capture_semi && this.token.kind == token::Semi {
209                 TrailingToken::Semi
210             } else {
211                 TrailingToken::None
212             };
213             Ok((this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Local(local)), trailing))
214         })
215     }
216
217     fn recover_local_after_let(&mut self, lo: Span, attrs: AttrWrapper) -> PResult<'a, Stmt> {
218         self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
219             let local = this.parse_local(attrs.into())?;
220             // FIXME - maybe capture semicolon in recovery?
221             Ok((
222                 this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Local(local)),
223                 TrailingToken::None,
224             ))
225         })
226     }
227
228     /// Parses a local variable declaration.
229     fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>> {
230         let lo = self.prev_token.span;
231         let (pat, colon) = self.parse_pat_before_ty(None, RecoverComma::Yes, "`let` bindings")?;
232
233         let (err, ty) = if colon {
234             // Save the state of the parser before parsing type normally, in case there is a `:`
235             // instead of an `=` typo.
236             let parser_snapshot_before_type = self.clone();
237             let colon_sp = self.prev_token.span;
238             match self.parse_ty() {
239                 Ok(ty) => (None, Some(ty)),
240                 Err(mut err) => {
241                     if let Ok(snip) = self.span_to_snippet(pat.span) {
242                         err.span_label(pat.span, format!("while parsing the type for `{}`", snip));
243                     }
244                     let err = if self.check(&token::Eq) {
245                         err.emit();
246                         None
247                     } else {
248                         // Rewind to before attempting to parse the type and continue parsing.
249                         let parser_snapshot_after_type =
250                             mem::replace(self, parser_snapshot_before_type);
251                         Some((parser_snapshot_after_type, colon_sp, err))
252                     };
253                     (err, None)
254                 }
255             }
256         } else {
257             (None, None)
258         };
259         let init = match (self.parse_initializer(err.is_some()), err) {
260             (Ok(init), None) => {
261                 // init parsed, ty parsed
262                 init
263             }
264             (Ok(init), Some((_, colon_sp, mut err))) => {
265                 // init parsed, ty error
266                 // Could parse the type as if it were the initializer, it is likely there was a
267                 // typo in the code: `:` instead of `=`. Add suggestion and emit the error.
268                 err.span_suggestion_short(
269                     colon_sp,
270                     "use `=` if you meant to assign",
271                     " =".to_string(),
272                     Applicability::MachineApplicable,
273                 );
274                 err.emit();
275                 // As this was parsed successfully, continue as if the code has been fixed for the
276                 // rest of the file. It will still fail due to the emitted error, but we avoid
277                 // extra noise.
278                 init
279             }
280             (Err(mut init_err), Some((snapshot, _, ty_err))) => {
281                 // init error, ty error
282                 init_err.cancel();
283                 // Couldn't parse the type nor the initializer, only raise the type error and
284                 // return to the parser state before parsing the type as the initializer.
285                 // let x: <parse_error>;
286                 *self = snapshot;
287                 return Err(ty_err);
288             }
289             (Err(err), None) => {
290                 // init error, ty parsed
291                 // Couldn't parse the initializer and we're not attempting to recover a failed
292                 // parse of the type, return the error.
293                 return Err(err);
294             }
295         };
296         let kind = match init {
297             None => LocalKind::Decl,
298             Some(init) => {
299                 if self.eat_keyword(kw::Else) {
300                     let els = self.parse_block()?;
301                     self.check_let_else_init_bool_expr(&init);
302                     self.check_let_else_init_trailing_brace(&init);
303                     LocalKind::InitElse(init, els)
304                 } else {
305                     LocalKind::Init(init)
306                 }
307             }
308         };
309         let hi = if self.token == token::Semi { self.token.span } else { self.prev_token.span };
310         Ok(P(ast::Local { ty, pat, kind, id: DUMMY_NODE_ID, span: lo.to(hi), attrs, tokens: None }))
311     }
312
313     fn check_let_else_init_bool_expr(&self, init: &ast::Expr) {
314         if let ast::ExprKind::Binary(op, ..) = init.kind {
315             if op.node.lazy() {
316                 let suggs = vec![
317                     (init.span.shrink_to_lo(), "(".to_string()),
318                     (init.span.shrink_to_hi(), ")".to_string()),
319                 ];
320                 self.struct_span_err(
321                     init.span,
322                     &format!(
323                         "a `{}` expression cannot be directly assigned in `let...else`",
324                         op.node.to_string()
325                     ),
326                 )
327                 .multipart_suggestion(
328                     "wrap the expression in parenthesis",
329                     suggs,
330                     Applicability::MachineApplicable,
331                 )
332                 .emit();
333             }
334         }
335     }
336
337     fn check_let_else_init_trailing_brace(&self, init: &ast::Expr) {
338         if let Some(trailing) = classify::expr_trailing_brace(init) {
339             let err_span = trailing.span.with_lo(trailing.span.hi() - BytePos(1));
340             let suggs = vec![
341                 (trailing.span.shrink_to_lo(), "(".to_string()),
342                 (trailing.span.shrink_to_hi(), ")".to_string()),
343             ];
344             self.struct_span_err(
345                 err_span,
346                 "right curly brace `}` before `else` in a `let...else` statement not allowed",
347             )
348             .multipart_suggestion(
349                 "try wrapping the expression in parenthesis",
350                 suggs,
351                 Applicability::MachineApplicable,
352             )
353             .emit();
354         }
355     }
356
357     /// Parses the RHS of a local variable declaration (e.g., `= 14;`).
358     fn parse_initializer(&mut self, eq_optional: bool) -> PResult<'a, Option<P<Expr>>> {
359         let eq_consumed = match self.token.kind {
360             token::BinOpEq(..) => {
361                 // Recover `let x <op>= 1` as `let x = 1`
362                 self.struct_span_err(
363                     self.token.span,
364                     "can't reassign to an uninitialized variable",
365                 )
366                 .span_suggestion_short(
367                     self.token.span,
368                     "initialize the variable",
369                     "=".to_string(),
370                     Applicability::MaybeIncorrect,
371                 )
372                 .help("if you meant to overwrite, remove the `let` binding")
373                 .emit();
374                 self.bump();
375                 true
376             }
377             _ => self.eat(&token::Eq),
378         };
379
380         Ok(if eq_consumed || eq_optional { Some(self.parse_expr()?) } else { None })
381     }
382
383     /// Parses a block. No inner attributes are allowed.
384     pub(super) fn parse_block(&mut self) -> PResult<'a, P<Block>> {
385         let (attrs, block) = self.parse_inner_attrs_and_block()?;
386         if let [.., last] = &*attrs {
387             self.error_on_forbidden_inner_attr(last.span, DEFAULT_INNER_ATTR_FORBIDDEN);
388         }
389         Ok(block)
390     }
391
392     fn error_block_no_opening_brace<T>(&mut self) -> PResult<'a, T> {
393         let sp = self.token.span;
394         let tok = super::token_descr(&self.token);
395         let mut e = self.struct_span_err(sp, &format!("expected `{{`, found {}", tok));
396         let do_not_suggest_help = self.token.is_keyword(kw::In) || self.token == token::Colon;
397
398         // Check to see if the user has written something like
399         //
400         //    if (cond)
401         //      bar;
402         //
403         // which is valid in other languages, but not Rust.
404         match self.parse_stmt_without_recovery(false, ForceCollect::No) {
405             // If the next token is an open brace (e.g., `if a b {`), the place-
406             // inside-a-block suggestion would be more likely wrong than right.
407             Ok(Some(_))
408                 if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace))
409                     || do_not_suggest_help => {}
410             Ok(Some(stmt)) => {
411                 let stmt_own_line = self.sess.source_map().is_line_before_span_empty(sp);
412                 let stmt_span = if stmt_own_line && self.eat(&token::Semi) {
413                     // Expand the span to include the semicolon.
414                     stmt.span.with_hi(self.prev_token.span.hi())
415                 } else {
416                     stmt.span
417                 };
418                 if let Ok(snippet) = self.span_to_snippet(stmt_span) {
419                     e.span_suggestion(
420                         stmt_span,
421                         "try placing this code inside a block",
422                         format!("{{ {} }}", snippet),
423                         // Speculative; has been misleading in the past (#46836).
424                         Applicability::MaybeIncorrect,
425                     );
426                 }
427             }
428             Err(mut e) => {
429                 self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
430                 e.cancel();
431             }
432             _ => {}
433         }
434         e.span_label(sp, "expected `{`");
435         Err(e)
436     }
437
438     /// Parses a block. Inner attributes are allowed.
439     pub(super) fn parse_inner_attrs_and_block(
440         &mut self,
441     ) -> PResult<'a, (Vec<Attribute>, P<Block>)> {
442         self.parse_block_common(self.token.span, BlockCheckMode::Default)
443     }
444
445     /// Parses a block. Inner attributes are allowed.
446     pub(super) fn parse_block_common(
447         &mut self,
448         lo: Span,
449         blk_mode: BlockCheckMode,
450     ) -> PResult<'a, (Vec<Attribute>, P<Block>)> {
451         maybe_whole!(self, NtBlock, |x| (Vec::new(), x));
452
453         if !self.eat(&token::OpenDelim(token::Brace)) {
454             return self.error_block_no_opening_brace();
455         }
456
457         let attrs = self.parse_inner_attributes()?;
458         let tail = if let Some(tail) = self.maybe_suggest_struct_literal(lo, blk_mode) {
459             tail?
460         } else {
461             self.parse_block_tail(lo, blk_mode, AttemptLocalParseRecovery::Yes)?
462         };
463         Ok((attrs, tail))
464     }
465
466     /// Parses the rest of a block expression or function body.
467     /// Precondition: already parsed the '{'.
468     crate fn parse_block_tail(
469         &mut self,
470         lo: Span,
471         s: BlockCheckMode,
472         recover: AttemptLocalParseRecovery,
473     ) -> PResult<'a, P<Block>> {
474         let mut stmts = vec![];
475         while !self.eat(&token::CloseDelim(token::Brace)) {
476             if self.token == token::Eof {
477                 break;
478             }
479             let stmt = match self.parse_full_stmt(recover) {
480                 Err(mut err) if recover.yes() => {
481                     self.maybe_annotate_with_ascription(&mut err, false);
482                     err.emit();
483                     self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
484                     Some(self.mk_stmt_err(self.token.span))
485                 }
486                 Ok(stmt) => stmt,
487                 Err(err) => return Err(err),
488             };
489             if let Some(stmt) = stmt {
490                 stmts.push(stmt);
491             } else {
492                 // Found only `;` or `}`.
493                 continue;
494             };
495         }
496         Ok(self.mk_block(stmts, s, lo.to(self.prev_token.span)))
497     }
498
499     /// Parses a statement, including the trailing semicolon.
500     pub fn parse_full_stmt(
501         &mut self,
502         recover: AttemptLocalParseRecovery,
503     ) -> PResult<'a, Option<Stmt>> {
504         // Skip looking for a trailing semicolon when we have an interpolated statement.
505         maybe_whole!(self, NtStmt, |x| Some(x));
506
507         let mut stmt = match self.parse_stmt_without_recovery(true, ForceCollect::No)? {
508             Some(stmt) => stmt,
509             None => return Ok(None),
510         };
511
512         let mut eat_semi = true;
513         match stmt.kind {
514             // Expression without semicolon.
515             StmtKind::Expr(ref mut expr)
516                 if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) =>
517             {
518                 // Just check for errors and recover; do not eat semicolon yet.
519                 if let Err(mut e) =
520                     self.expect_one_of(&[], &[token::Semi, token::CloseDelim(token::Brace)])
521                 {
522                     if let TokenKind::DocComment(..) = self.token.kind {
523                         if let Ok(snippet) = self.span_to_snippet(self.token.span) {
524                             let sp = self.token.span;
525                             let marker = &snippet[..3];
526                             let (comment_marker, doc_comment_marker) = marker.split_at(2);
527
528                             e.span_suggestion(
529                                 sp.with_hi(sp.lo() + BytePos(marker.len() as u32)),
530                                 &format!(
531                                     "add a space before `{}` to use a regular comment",
532                                     doc_comment_marker,
533                                 ),
534                                 format!("{} {}", comment_marker, doc_comment_marker),
535                                 Applicability::MaybeIncorrect,
536                             );
537                         }
538                     }
539                     if let Err(mut e) =
540                         self.check_mistyped_turbofish_with_multiple_type_params(e, expr)
541                     {
542                         if recover.no() {
543                             return Err(e);
544                         }
545                         e.emit();
546                         self.recover_stmt();
547                     }
548                     // Don't complain about type errors in body tail after parse error (#57383).
549                     let sp = expr.span.to(self.prev_token.span);
550                     *expr = self.mk_expr_err(sp);
551                 }
552             }
553             StmtKind::Expr(_) | StmtKind::MacCall(_) => {}
554             StmtKind::Local(ref mut local) if let Err(e) = self.expect_semi() => {
555                 // We might be at the `,` in `let x = foo<bar, baz>;`. Try to recover.
556                 match &mut local.kind {
557                     LocalKind::Init(expr) | LocalKind::InitElse(expr, _) => {
558                             self.check_mistyped_turbofish_with_multiple_type_params(e, expr)?;
559                             // We found `foo<bar, baz>`, have we fully recovered?
560                             self.expect_semi()?;
561                         }
562                         LocalKind::Decl => return Err(e),
563                 }
564                 eat_semi = false;
565             }
566             StmtKind::Empty | StmtKind::Item(_) | StmtKind::Local(_) | StmtKind::Semi(_) => eat_semi = false,
567         }
568
569         if eat_semi && self.eat(&token::Semi) {
570             stmt = stmt.add_trailing_semicolon();
571         }
572         stmt.span = stmt.span.to(self.prev_token.span);
573         Ok(Some(stmt))
574     }
575
576     pub(super) fn mk_block(&self, stmts: Vec<Stmt>, rules: BlockCheckMode, span: Span) -> P<Block> {
577         P(Block {
578             stmts,
579             id: DUMMY_NODE_ID,
580             rules,
581             span,
582             tokens: None,
583             could_be_bare_literal: false,
584         })
585     }
586
587     pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt {
588         Stmt { id: DUMMY_NODE_ID, kind, span }
589     }
590
591     pub(super) fn mk_stmt_err(&self, span: Span) -> Stmt {
592         self.mk_stmt(span, StmtKind::Expr(self.mk_expr_err(span)))
593     }
594
595     pub(super) fn mk_block_err(&self, span: Span) -> P<Block> {
596         self.mk_block(vec![self.mk_stmt_err(span)], BlockCheckMode::Default, span)
597     }
598 }