Parses a Let or a LetRec with the new order: CTEs first in ascending order, and then Return.
(ctx: CtxRef, input: ParseStream)
| 219 | |
| 220 | /// Parses a Let or a LetRec with the new order: CTEs first in ascending order, and then Return. |
| 221 | fn parse_let_or_letrec(ctx: CtxRef, input: ParseStream) -> Result { |
| 222 | let with = input.parse::<kw::With>()?; |
| 223 | let recursive = input.eat2(kw::Mutually, kw::Recursive); |
| 224 | let parse_ctes = ParseChildren::new(input, with.span().start()); |
| 225 | let ctes = parse_ctes.parse_many(ctx, parse_cte)?; |
| 226 | |
| 227 | let return_ = input.parse::<kw::Return>()?; |
| 228 | let parse_body = ParseChildren::new(input, return_.span().start()); |
| 229 | let body = parse_body.parse_one(ctx, parse_expr)?; |
| 230 | |
| 231 | if ctes.is_empty() { |
| 232 | let msg = "At least one `let cte` binding expected"; |
| 233 | Err(Error::new(input.span(), msg))? |
| 234 | } |
| 235 | |
| 236 | let cte_ids = ctes.iter().map(|(id, _, _)| id); |
| 237 | if !cte_ids.clone().is_sorted() { |
| 238 | let msg = format!( |
| 239 | "Error parsing Let/LetRec: seen With before Return, but cte ids are not ordered ascending: {:?}", |
| 240 | cte_ids.collect::<Vec<_>>() |
| 241 | ); |
| 242 | Err(Error::new(input.span(), msg))? |
| 243 | } |
| 244 | build_let_or_let_rec(ctes, body, recursive, with) |
| 245 | } |
| 246 | |
| 247 | fn build_let_or_let_rec( |
| 248 | ctes: Vec<(LocalId, Analyses, MirRelationExpr)>, |
no test coverage detected