Flatten the option check in lower_pattern_range_endpoint
This commit is contained in:
parent
4a43094662
commit
7de67a16c5
1 changed files with 28 additions and 31 deletions
|
@ -159,38 +159,35 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
||||||
(Option<PatRangeBoundary<'tcx>>, Option<Ascription<'tcx>>, Option<LocalDefId>),
|
(Option<PatRangeBoundary<'tcx>>, Option<Ascription<'tcx>>, Option<LocalDefId>),
|
||||||
ErrorGuaranteed,
|
ErrorGuaranteed,
|
||||||
> {
|
> {
|
||||||
match expr {
|
let Some(expr) = expr else { return Ok((None, None, None)) };
|
||||||
None => Ok((None, None, None)),
|
|
||||||
Some(expr) => {
|
let (kind, ascr, inline_const) = match self.lower_lit(expr) {
|
||||||
let (kind, ascr, inline_const) = match self.lower_lit(expr) {
|
PatKind::ExpandedConstant { subpattern, def_id, is_inline: true } => {
|
||||||
PatKind::ExpandedConstant { subpattern, def_id, is_inline: true } => {
|
(subpattern.kind, None, def_id.as_local())
|
||||||
(subpattern.kind, None, def_id.as_local())
|
|
||||||
}
|
|
||||||
PatKind::ExpandedConstant { subpattern, is_inline: false, .. } => {
|
|
||||||
(subpattern.kind, None, None)
|
|
||||||
}
|
|
||||||
PatKind::AscribeUserType { ascription, subpattern: box Pat { kind, .. } } => {
|
|
||||||
(kind, Some(ascription), None)
|
|
||||||
}
|
|
||||||
kind => (kind, None, None),
|
|
||||||
};
|
|
||||||
let value = match kind {
|
|
||||||
PatKind::Constant { value } => value,
|
|
||||||
PatKind::ExpandedConstant { subpattern, .. }
|
|
||||||
if let PatKind::Constant { value } = subpattern.kind =>
|
|
||||||
{
|
|
||||||
value
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let msg = format!(
|
|
||||||
"found bad range pattern endpoint `{expr:?}` outside of error recovery"
|
|
||||||
);
|
|
||||||
return Err(self.tcx.dcx().span_delayed_bug(expr.span, msg));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok((Some(PatRangeBoundary::Finite(value)), ascr, inline_const))
|
|
||||||
}
|
}
|
||||||
}
|
PatKind::ExpandedConstant { subpattern, is_inline: false, .. } => {
|
||||||
|
(subpattern.kind, None, None)
|
||||||
|
}
|
||||||
|
PatKind::AscribeUserType { ascription, subpattern: box Pat { kind, .. } } => {
|
||||||
|
(kind, Some(ascription), None)
|
||||||
|
}
|
||||||
|
kind => (kind, None, None),
|
||||||
|
};
|
||||||
|
let value = match kind {
|
||||||
|
PatKind::Constant { value } => value,
|
||||||
|
PatKind::ExpandedConstant { subpattern, .. }
|
||||||
|
if let PatKind::Constant { value } = subpattern.kind =>
|
||||||
|
{
|
||||||
|
value
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let msg = format!(
|
||||||
|
"found bad range pattern endpoint `{expr:?}` outside of error recovery"
|
||||||
|
);
|
||||||
|
return Err(self.tcx.dcx().span_delayed_bug(expr.span, msg));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok((Some(PatRangeBoundary::Finite(value)), ascr, inline_const))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Overflowing literals are linted against in a late pass. This is mostly fine, except when we
|
/// Overflowing literals are linted against in a late pass. This is mostly fine, except when we
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue