|
3 | 3 | use base_db::{salsa::Cycle, CrateId};
|
4 | 4 | use chalk_ir::{cast::Cast, BoundVar, DebruijnIndex};
|
5 | 5 | use hir_def::{
|
6 |
| - hir::Expr, |
| 6 | + body::Body, |
| 7 | + hir::{Expr, ExprId}, |
7 | 8 | path::Path,
|
8 | 9 | resolver::{Resolver, ValueNs},
|
9 | 10 | type_ref::LiteralConstRef,
|
@@ -280,21 +281,32 @@ pub(crate) fn const_eval_discriminant_variant(
|
280 | 281 | // get an `InferenceResult` instead of an `InferenceContext`. And we should remove `ctx.clone().resolve_all()` here
|
281 | 282 | // and make this function private. See the fixme comment on `InferenceContext::resolve_all`.
|
282 | 283 | pub(crate) fn eval_to_const(
|
283 |
| - expr: Idx<Expr>, |
| 284 | + expr: ExprId, |
284 | 285 | mode: ParamLoweringMode,
|
285 | 286 | ctx: &mut InferenceContext<'_>,
|
286 | 287 | args: impl FnOnce() -> Generics,
|
287 | 288 | debruijn: DebruijnIndex,
|
288 | 289 | ) -> Const {
|
289 | 290 | let db = ctx.db;
|
290 | 291 | let infer = ctx.clone().resolve_all();
|
| 292 | + fn has_closure(body: &Body, expr: ExprId) -> bool { |
| 293 | + if matches!(body[expr], Expr::Closure { .. }) { |
| 294 | + return true; |
| 295 | + } |
| 296 | + let mut r = false; |
| 297 | + body[expr].walk_child_exprs(|idx| r |= has_closure(body, idx)); |
| 298 | + r |
| 299 | + } |
| 300 | + if has_closure(&ctx.body, expr) { |
| 301 | + // Type checking clousres need an isolated body (See the above FIXME). Bail out early to prevent panic. |
| 302 | + return unknown_const(infer[expr].clone()); |
| 303 | + } |
291 | 304 | if let Expr::Path(p) = &ctx.body.exprs[expr] {
|
292 | 305 | let resolver = &ctx.resolver;
|
293 | 306 | if let Some(c) = path_to_const(db, resolver, p, mode, args, debruijn, infer[expr].clone()) {
|
294 | 307 | return c;
|
295 | 308 | }
|
296 | 309 | }
|
297 |
| - let infer = ctx.clone().resolve_all(); |
298 | 310 | if let Ok(mir_body) = lower_to_mir(ctx.db, ctx.owner, &ctx.body, &infer, expr) {
|
299 | 311 | if let Ok(result) = interpret_mir(db, Arc::new(mir_body), true, None).0 {
|
300 | 312 | return result;
|
|
0 commit comments