Skip to content

Commit 41a74ac

Browse files
Nadrierilmark-i-mvarkor
committed
Apply suggestions from code review
Co-authored-by: Who? Me?! <[email protected]> Co-authored-by: varkor <[email protected]>
1 parent 766ab78 commit 41a74ac

File tree

1 file changed

+20
-23
lines changed
  • compiler/rustc_mir_build/src/thir/pattern

1 file changed

+20
-23
lines changed

compiler/rustc_mir_build/src/thir/pattern/_match.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
//! before.
204204
//! That's almost correct, but only works if there were no wildcards in those first
205205
//! components. So we need to check that `p` is useful with respect to the rows that
206-
//! start with a wildcard, if there are any. This is where `D` comes in:
206+
//! start with a wildcard, if there are any. This is where `S(_, x)` comes in:
207207
//! `U(P, p) := U(S(_, P), S(_, p))`
208208
//!
209209
//! For example, if `P` is:
@@ -634,8 +634,8 @@ impl Slice {
634634
}
635635

636636
/// The exhaustiveness-checking paper does not include any details on
637-
/// checking variable-length slice patterns. However, they are matched
638-
/// by an infinite collection of fixed-length array patterns.
637+
/// checking variable-length slice patterns. However, they may be
638+
/// matched by an infinite collection of fixed-length array patterns.
639639
///
640640
/// Checking the infinite set directly would take an infinite amount
641641
/// of time. However, it turns out that for each finite set of
@@ -646,11 +646,11 @@ impl Slice {
646646
/// `sₘ` for each sufficiently-large length `m` that applies to exactly
647647
/// the same subset of `P`.
648648
///
649-
/// Because of that, each witness for reachability-checking from one
649+
/// Because of that, each witness for reachability-checking of one
650650
/// of the sufficiently-large lengths can be transformed to an
651-
/// equally-valid witness from any other length, so we only have
652-
/// to check slice lengths from the "minimal sufficiently-large length"
653-
/// and below.
651+
/// equally-valid witness of any other length, so we only have
652+
/// to check slices of the "minimal sufficiently-large length"
653+
/// and less.
654654
///
655655
/// Note that the fact that there is a *single* `sₘ` for each `m`
656656
/// not depending on the specific pattern in `P` is important: if
@@ -659,8 +659,8 @@ impl Slice {
659659
/// `[.., false]`
660660
/// Then any slice of length ≥1 that matches one of these two
661661
/// patterns can be trivially turned to a slice of any
662-
/// other length ≥1 that matches them and vice-versa - for
663-
/// but the slice from length 2 `[false, true]` that matches neither
662+
/// other length ≥1 that matches them and vice-versa,
663+
/// but the slice of length 2 `[false, true]` that matches neither
664664
/// of these patterns can't be turned to a slice from length 1 that
665665
/// matches neither of these patterns, so we have to consider
666666
/// slices from length 2 there.
@@ -787,7 +787,7 @@ enum Constructor<'tcx> {
787787
Opaque,
788788
/// Fake extra constructor for enums that aren't allowed to be matched exhaustively.
789789
NonExhaustive,
790-
/// Fake constructor for those types for which we can't list constructors explicitely, like
790+
/// Fake constructor for those types for which we can't list constructors explicitly, like
791791
/// `f64` and `&str`.
792792
Unlistable,
793793
/// Wildcard pattern.
@@ -796,13 +796,10 @@ enum Constructor<'tcx> {
796796

797797
impl<'tcx> Constructor<'tcx> {
798798
fn is_wildcard(&self) -> bool {
799-
match self {
800-
Wildcard => true,
801-
_ => false,
802-
}
799+
matches!(self, Wildcard)
803800
}
804801

805-
fn as_intrange(&self) -> Option<&IntRange<'tcx>> {
802+
fn as_int_range(&self) -> Option<&IntRange<'tcx>> {
806803
match self {
807804
IntRange(range) => Some(range),
808805
_ => None,
@@ -827,7 +824,7 @@ impl<'tcx> Constructor<'tcx> {
827824
}
828825
}
829826

830-
/// Some constructors (namely Wildcard, IntRange and Slice) actually stand for a set of actual
827+
/// Some constructors (namely `Wildcard`, `IntRange` and `Slice`) actually stand for a set of actual
831828
/// constructors (like variants, integers or fixed-sized slices). When specializing for these
832829
/// constructors, we want to be specialising for the actual underlying constructors.
833830
/// Naively, we would simply return the list of constructors they correspond to. We instead are
@@ -863,8 +860,8 @@ impl<'tcx> Constructor<'tcx> {
863860

864861
/// For wildcards, there are two groups of constructors: there are the constructors actually
865862
/// present in the matrix (`head_ctors`), and the constructors not present (`missing_ctors`).
866-
/// Two constructors that are not in the matrix will either both be catched (by a wildcard), or
867-
/// both not be catched. Therefore we can keep the missing constructors grouped together.
863+
/// Two constructors that are not in the matrix will either both be caught (by a wildcard), or
864+
/// both not be caught. Therefore we can keep the missing constructors grouped together.
868865
fn split_wildcard<'p>(pcx: PatCtxt<'_, 'p, 'tcx>) -> SmallVec<[Self; 1]> {
869866
// Missing constructors are those that are not matched by any non-wildcard patterns in the
870867
// current column. We only fully construct them on-demand, because they're rarely used and
@@ -882,8 +879,8 @@ impl<'tcx> Constructor<'tcx> {
882879
}
883880
}
884881

885-
/// Returns whether `self` is covered by `other`, ie whether `self` is a subset of `other`. For
886-
/// the simple cases, this is simply checking for equality. For the "grouped" constructors,
882+
/// Returns whether `self` is covered by `other`, i.e. whether `self` is a subset of `other`.
883+
/// For the simple cases, this is simply checking for equality. For the "grouped" constructors,
887884
/// this checks for inclusion.
888885
fn is_covered_by<'p>(&self, pcx: PatCtxt<'_, 'p, 'tcx>, other: &Self) -> bool {
889886
match (self, other) {
@@ -955,7 +952,7 @@ impl<'tcx> Constructor<'tcx> {
955952
Variant(_) => used_ctors.iter().any(|c| c == self),
956953
IntRange(range) => used_ctors
957954
.iter()
958-
.filter_map(|c| c.as_intrange())
955+
.filter_map(|c| c.as_int_range())
959956
.any(|other| range.is_covered_by(pcx, other)),
960957
Slice(slice) => used_ctors
961958
.iter()
@@ -1601,7 +1598,7 @@ fn all_constructors<'p, 'tcx>(pcx: PatCtxt<'_, 'p, 'tcx>) -> Vec<Constructor<'tc
16011598
_ if cx.is_uninhabited(pcx.ty) => vec![],
16021599
ty::Adt(..) | ty::Tuple(..) => vec![Single],
16031600
ty::Ref(_, t, _) if !t.is_str() => vec![Single],
1604-
// This type is one for which we don't know how to list constructors, like &str of f64.
1601+
// This type is one for which we don't know how to list constructors, like `&str` or `f64`.
16051602
_ => vec![Unlistable],
16061603
}
16071604
}
@@ -1851,7 +1848,7 @@ impl<'tcx> IntRange<'tcx> {
18511848
let row_borders = pcx
18521849
.matrix
18531850
.head_ctors(pcx.cx)
1854-
.filter_map(|ctor| ctor.as_intrange())
1851+
.filter_map(|ctor| ctor.as_int_range())
18551852
.filter_map(|range| {
18561853
let intersection = self.intersection(pcx.cx.tcx, &range);
18571854
let should_lint = self.suspicious_intersection(&range);

0 commit comments

Comments
 (0)