(&self)
| 35 | // Parse `let a;` let or `let a = 1;` let assign declaration |
| 36 | impl ParseBody for syn::Local { |
| 37 | fn parse_body(&self) -> Vec<StmtOrExpr> { |
| 38 | let mut mutable = false; |
| 39 | // Parse the binding value |
| 40 | let binding = match &self.pat { |
| 41 | syn::Pat::Ident(pat_ident) => { |
| 42 | mutable = pat_ident.mutability.is_some(); |
| 43 | Binding::Var(pat_ident.ident.to_string()) |
| 44 | } |
| 45 | _ => Binding::Other(self.pat.to_token_stream().to_string()), |
| 46 | }; |
| 47 | // Determine if it's a |
| 48 | // - let: `let a;` |
| 49 | // - let assign: `let a = 1;` |
| 50 | let ty = match self.init { |
| 51 | Some(_) => StatementType::LetAssign { binding, mutable }, |
| 52 | None => StatementType::Let { binding, mutable }, |
| 53 | }; |
| 54 | let mut body = vec![Statement { |
| 55 | ty, |
| 56 | loc: self.span().end().into_loc(), |
| 57 | } |
| 58 | .into()]; |
| 59 | // Parse the right side of "let assign" if any |
| 60 | if let Some(local_init) = &self.init { |
| 61 | // Parse `= Some(1)` in `let a = Some(1);` |
| 62 | match local_init.expr.as_ref() { |
| 63 | syn::Expr::Block(_) |
| 64 | | syn::Expr::ForLoop(_) |
| 65 | | syn::Expr::If(_) |
| 66 | | syn::Expr::Match(_) |
| 67 | | syn::Expr::While(_) |
| 68 | | syn::Expr::Loop(_) => { |
| 69 | body.extend(local_init.expr.parse_body()); |
| 70 | } |
| 71 | _ => {} |
| 72 | }; |
| 73 | // Parse `else { return }` in `let Ok(x) = r else { return };` |
| 74 | if let Some((_, expr)) = &local_init.diverge { |
| 75 | body.extend(expr.parse_body()); |
| 76 | } |
| 77 | } |
| 78 | body |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Parse statements or expressions |
no test coverage detected