Skip to content

Commit f94c50e

Browse files
committed
Apply suggestions from code review
1 parent 1d442e7 commit f94c50e

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/librustc_mir/hair/pattern/_match.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,9 @@ impl<'tcx> IntRange<'tcx> {
11801180
(*self.range.start(), *self.range.end())
11811181
}
11821182

1183+
/// Don't treat `usize`/`isize` exhaustively unless the `precise_pointer_size_matching` feature
1184+
/// is enabled.
11831185
fn treat_exhaustively(&self, tcx: TyCtxt<'tcx>) -> bool {
1184-
// Don't treat `usize`/`isize` exhaustively unless the `precise_pointer_size_matching`
1185-
// feature is enabled.
11861186
!self.ty.is_ptr_sized_integral() || tcx.features().precise_pointer_size_matching
11871187
}
11881188

@@ -1363,7 +1363,7 @@ impl<'tcx> IntRange<'tcx> {
13631363
}
13641364
}
13651365

1366-
// Ignore spans when comparing, they don't carry semantic information as they are only for lints.
1366+
/// Ignore spans when comparing, they don't carry semantic information as they are only for lints.
13671367
impl<'tcx> std::cmp::PartialEq for IntRange<'tcx> {
13681368
fn eq(&self, other: &Self) -> bool {
13691369
self.range == other.range && self.ty == other.ty
@@ -2056,9 +2056,9 @@ fn constructor_covered_by_range<'tcx>(
20562056
param_env: ty::ParamEnv<'tcx>,
20572057
ctor: &Constructor<'tcx>,
20582058
pat: &Pat<'tcx>,
2059-
) -> bool {
2059+
) -> Option<()> {
20602060
if let Single = ctor {
2061-
return true;
2061+
return Some(());
20622062
}
20632063

20642064
let (pat_from, pat_to, pat_end, ty) = match *pat.kind {
@@ -2073,16 +2073,11 @@ fn constructor_covered_by_range<'tcx>(
20732073
};
20742074
trace!("constructor_covered_by_range {:#?}, {:#?}, {:#?}, {}", ctor, pat_from, pat_to, ty);
20752075

2076-
let to = match compare_const_vals(tcx, ctor_to, pat_to, param_env, ty) {
2077-
Some(to) => to,
2078-
None => return false,
2079-
};
2080-
let from = match compare_const_vals(tcx, ctor_from, pat_from, param_env, ty) {
2081-
Some(from) => from,
2082-
None => return false,
2083-
};
2084-
(from == Ordering::Greater || from == Ordering::Equal)
2085-
&& (to == Ordering::Less || (pat_end == ctor_end && to == Ordering::Equal))
2076+
let to = compare_const_vals(tcx, ctor_to, pat_to, param_env, ty)?;
2077+
let from = compare_const_vals(tcx, ctor_from, pat_from, param_env, ty)?;
2078+
let intersects = (from == Ordering::Greater || from == Ordering::Equal)
2079+
&& (to == Ordering::Less || (pat_end == ctor_end && to == Ordering::Equal));
2080+
if intersects { Some(()) } else { None }
20862081
}
20872082

20882083
fn patterns_for_variant<'p, 'a: 'p, 'tcx>(
@@ -2221,11 +2216,8 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
22212216
// by `IntRange`. For these cases, the constructor may not be a
22222217
// range so intersection actually devolves into being covered
22232218
// by the pattern.
2224-
if constructor_covered_by_range(cx.tcx, cx.param_env, constructor, pat) {
2225-
Some(PatStack::default())
2226-
} else {
2227-
None
2228-
}
2219+
constructor_covered_by_range(cx.tcx, cx.param_env, constructor, pat)
2220+
.map(|()| PatStack::default())
22292221
}
22302222
}
22312223

0 commit comments

Comments
 (0)