Simplify the pattern unpeeling in lower_pattern_range_endpoint
This commit is contained in:
parent
85f4cdc626
commit
2fb1261c21
1 changed files with 25 additions and 26 deletions
|
@ -161,35 +161,34 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
||||||
) -> Result<Option<PatRangeBoundary<'tcx>>, ErrorGuaranteed> {
|
) -> Result<Option<PatRangeBoundary<'tcx>>, ErrorGuaranteed> {
|
||||||
let Some(expr) = expr else { return Ok(None) };
|
let Some(expr) = expr else { return Ok(None) };
|
||||||
|
|
||||||
let (kind, ascr, inline_const) = match self.lower_lit(expr) {
|
// Lower the endpoint into a temporary `PatKind` that will then be
|
||||||
PatKind::ExpandedConstant { subpattern, def_id, is_inline: true } => {
|
// deconstructed to obtain the constant value and other data.
|
||||||
(subpattern.kind, None, def_id.as_local())
|
let mut kind: PatKind<'tcx> = self.lower_lit(expr);
|
||||||
}
|
|
||||||
PatKind::ExpandedConstant { subpattern, is_inline: false, .. } => {
|
// Unpeel any ascription or inline-const wrapper nodes.
|
||||||
(subpattern.kind, None, None)
|
loop {
|
||||||
}
|
match kind {
|
||||||
PatKind::AscribeUserType { ascription, subpattern: box Pat { kind, .. } } => {
|
PatKind::AscribeUserType { ascription, subpattern } => {
|
||||||
(kind, Some(ascription), None)
|
ascriptions.push(ascription);
|
||||||
}
|
kind = subpattern.kind;
|
||||||
kind => (kind, None, None),
|
}
|
||||||
};
|
PatKind::ExpandedConstant { is_inline, def_id, subpattern } => {
|
||||||
let value = match kind {
|
if is_inline {
|
||||||
PatKind::Constant { value } => value,
|
inline_consts.extend(def_id.as_local());
|
||||||
PatKind::ExpandedConstant { subpattern, .. }
|
}
|
||||||
if let PatKind::Constant { value } = subpattern.kind =>
|
kind = subpattern.kind;
|
||||||
{
|
}
|
||||||
value
|
_ => break,
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let msg = format!(
|
|
||||||
"found bad range pattern endpoint `{expr:?}` outside of error recovery"
|
|
||||||
);
|
|
||||||
return Err(self.tcx.dcx().span_delayed_bug(expr.span, msg));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The unpeeled kind should now be a constant, giving us the endpoint value.
|
||||||
|
let PatKind::Constant { value } = kind else {
|
||||||
|
let msg =
|
||||||
|
format!("found bad range pattern endpoint `{expr:?}` outside of error recovery");
|
||||||
|
return Err(self.tcx.dcx().span_delayed_bug(expr.span, msg));
|
||||||
};
|
};
|
||||||
|
|
||||||
ascriptions.extend(ascr);
|
|
||||||
inline_consts.extend(inline_const);
|
|
||||||
Ok(Some(PatRangeBoundary::Finite(value)))
|
Ok(Some(PatRangeBoundary::Finite(value)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue