Skip to content

Commit 7de67a1

Browse files
committed
Flatten the option check in lower_pattern_range_endpoint
1 parent 4a43094 commit 7de67a1

File tree

1 file changed

+28
-31
lines changed
  • compiler/rustc_mir_build/src/thir/pattern

1 file changed

+28
-31
lines changed

Diff for: compiler/rustc_mir_build/src/thir/pattern/mod.rs

+28-31
Original file line numberDiff line numberDiff line change
@@ -159,38 +159,35 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
159159
(Option<PatRangeBoundary<'tcx>>, Option<Ascription<'tcx>>, Option<LocalDefId>),
160160
ErrorGuaranteed,
161161
> {
162-
match expr {
163-
None => Ok((None, None, None)),
164-
Some(expr) => {
165-
let (kind, ascr, inline_const) = match self.lower_lit(expr) {
166-
PatKind::ExpandedConstant { subpattern, def_id, is_inline: true } => {
167-
(subpattern.kind, None, def_id.as_local())
168-
}
169-
PatKind::ExpandedConstant { subpattern, is_inline: false, .. } => {
170-
(subpattern.kind, None, None)
171-
}
172-
PatKind::AscribeUserType { ascription, subpattern: box Pat { kind, .. } } => {
173-
(kind, Some(ascription), None)
174-
}
175-
kind => (kind, None, None),
176-
};
177-
let value = match kind {
178-
PatKind::Constant { value } => value,
179-
PatKind::ExpandedConstant { subpattern, .. }
180-
if let PatKind::Constant { value } = subpattern.kind =>
181-
{
182-
value
183-
}
184-
_ => {
185-
let msg = format!(
186-
"found bad range pattern endpoint `{expr:?}` outside of error recovery"
187-
);
188-
return Err(self.tcx.dcx().span_delayed_bug(expr.span, msg));
189-
}
190-
};
191-
Ok((Some(PatRangeBoundary::Finite(value)), ascr, inline_const))
162+
let Some(expr) = expr else { return Ok((None, None, None)) };
163+
164+
let (kind, ascr, inline_const) = match self.lower_lit(expr) {
165+
PatKind::ExpandedConstant { subpattern, def_id, is_inline: true } => {
166+
(subpattern.kind, None, def_id.as_local())
192167
}
193-
}
168+
PatKind::ExpandedConstant { subpattern, is_inline: false, .. } => {
169+
(subpattern.kind, None, None)
170+
}
171+
PatKind::AscribeUserType { ascription, subpattern: box Pat { kind, .. } } => {
172+
(kind, Some(ascription), None)
173+
}
174+
kind => (kind, None, None),
175+
};
176+
let value = match kind {
177+
PatKind::Constant { value } => value,
178+
PatKind::ExpandedConstant { subpattern, .. }
179+
if let PatKind::Constant { value } = subpattern.kind =>
180+
{
181+
value
182+
}
183+
_ => {
184+
let msg = format!(
185+
"found bad range pattern endpoint `{expr:?}` outside of error recovery"
186+
);
187+
return Err(self.tcx.dcx().span_delayed_bug(expr.span, msg));
188+
}
189+
};
190+
Ok((Some(PatRangeBoundary::Finite(value)), ascr, inline_const))
194191
}
195192

196193
/// Overflowing literals are linted against in a late pass. This is mostly fine, except when we

0 commit comments

Comments
 (0)