diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index aa899ddeb5..4922d07424 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -294,12 +294,18 @@ pub struct WhenBranch { } impl WhenBranch { - pub fn region(&self) -> Region { - Region::across_all( - self.patterns - .iter() - .map(|p| &p.region) - .chain([self.value.region].iter()), + pub fn pattern_region(&self) -> Region { + Region::span_across( + &self + .patterns + .first() + .expect("when branch has no pattern?") + .region, + &self + .patterns + .last() + .expect("when branch has no pattern?") + .region, ) } } diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index df3806a872..0833f9b914 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -596,7 +596,7 @@ pub fn constrain_expr( Region::span_across( &loc_cond.region, // &branches.first().unwrap().region(), - &branches.last().unwrap().region(), + &branches.last().unwrap().pattern_region(), ) };