Skip to content

Commit 85fdb34

Browse files
Nadrierilvarkor
andcommitted
Apply suggestions from code review
Co-authored-by: varkor <[email protected]>
1 parent 1c176d1 commit 85fdb34

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl Slice {
451451
///
452452
/// A slice pattern `[x, .., y]` behaves like the infinite or-pattern `[x, y] | [x, _, y] | [x, _,
453453
/// _, y] | ...`. The corresponding value constructors are fixed-length array constructors above a
454-
/// given minimum length. We obviously can't list all of this infinity of constructors. Thankfully,
454+
/// given minimum length. We obviously can't list this infinitude of constructors. Thankfully,
455455
/// it turns out that for each finite set of slice patterns, all sufficiently large array lengths
456456
/// are equivalent.
457457
///
@@ -491,7 +491,7 @@ impl Slice {
491491
/// middle. This means that the set of witnesses for length `l >= 5` if equivalent to the set for
492492
/// any other `l' >= 5`: simply add or remove wildcards in the middle to convert between them.
493493
///
494-
/// This applies to any set of slice patterns: there will be a length `L` above which all length
494+
/// This applies to any set of slice patterns: there will be a length `L` above which all lengths
495495
/// behave the same. This is exactly what we need for constructor splitting. Therefore a
496496
/// variable-length slice can be split into a variable-length slice of minimal length `L`, and many
497497
/// fixed-length slices of lengths `< L`.
@@ -736,8 +736,8 @@ impl<'tcx> Constructor<'tcx> {
736736
// ranges check.
737737
IntRange(ctor_range) if !ctor_range.is_singleton() => {
738738
let mut split_range = SplitIntRange::new(ctor_range.clone());
739-
let intranges = ctors.filter_map(|ctor| ctor.as_int_range());
740-
split_range.split(intranges.cloned());
739+
let int_ranges = ctors.filter_map(|ctor| ctor.as_int_range());
740+
split_range.split(int_ranges.cloned());
741741
split_range.iter().map(IntRange).collect()
742742
}
743743
&Slice(Slice { kind: VarLen(self_prefix, self_suffix), array_len }) => {
@@ -1080,7 +1080,7 @@ impl<'p, 'tcx> FilteredField<'p, 'tcx> {
10801080
///
10811081
/// If a private or `non_exhaustive` field is uninhabited, the code mustn't observe that it is
10821082
/// uninhabited. For that, we filter these fields out of the matrix. This is handled automatically
1083-
/// in `Fields`. This filtering is uncommon in practice, because uninhabited fields are rare used,
1083+
/// in `Fields`. This filtering is uncommon in practice, because uninhabited fields are rarely used,
10841084
/// so we avoid it when possible to preserve performance.
10851085
#[derive(Debug, Clone)]
10861086
pub(super) enum Fields<'p, 'tcx> {

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
//!
2020
//! The algorithm implemented here is a modified version of the one described in [this
2121
//! paper](http://moscova.inria.fr/~maranget/papers/warn/index.html). We have however generalized
22-
//! it to accomodate the variety of patterns that rust supports. We thus explain our version here,
22+
//! it to accommodate the variety of patterns that Rust supports. We thus explain our version here,
2323
//! without being as rigorous.
2424
//!
2525
//!
2626
//! # Summary
2727
//!
2828
//! The core of the algorithm is the notion of "usefulness". A pattern `q` is said to be *useful*
2929
//! relative to another pattern `p` of the same type if there is a value that is matched by `q` and
30-
//! not matched by `p`. This generalizes to many `p`s: `q` is useful wrt a list of patterns `p_1 ..
31-
//! p_n` if there is a value that is matched by `q` and by none of the `p_i`. We write
30+
//! not matched by `p`. This generalizes to many `p`s: `q` is useful w.r.t. a list of patterns
31+
//! `p_1 .. p_n` if there is a value that is matched by `q` and by none of the `p_i`. We write
3232
//! `usefulness(p_1 .. p_n, q)` for a function that returns a list of such values. The aim of this
3333
//! file is to compute it efficiently.
3434
//!
3535
//! This is enough to compute reachability: a pattern in a `match` expression is reachable iff it
36-
//! is useful wrt the patterns above it:
36+
//! is useful w.r.t. the patterns above it:
3737
//! ```rust
3838
//! match x {
3939
//! Some(_) => ...,
@@ -44,8 +44,8 @@
4444
//! ```
4545
//!
4646
//! This is also enough to compute exhaustiveness: a match is exhaustive iff the wildcard `_`
47-
//! pattern is _not_ useful wrt the patterns in the match. The values returned by `usefulness` are
48-
//! used to tell the user which values are missing.
47+
//! pattern is _not_ useful w.r.t. the patterns in the match. The values returned by `usefulness`
48+
//! are used to tell the user which values are missing.
4949
//! ```rust
5050
//! match x {
5151
//! Some(0) => ...,
@@ -102,7 +102,7 @@
102102
//!
103103
//! Note: this constructors/fields distinction may not straightforwardly apply to every Rust type.
104104
//! For example a value of type `Rc<u64>` can't be deconstructed that way, and `&str` has an
105-
//! infinity of constructors. There are also subtleties with visibility of fields and
105+
//! infinitude of constructors. There are also subtleties with visibility of fields and
106106
//! uninhabitedness and various other things. The constructors idea can be extended to handle most
107107
//! of these subtleties though; caveats are documented where relevant throughout the code.
108108
//!
@@ -184,7 +184,8 @@
184184
//!
185185
//! `specialize(c, p0 | p1) := specialize(c, p0) ++ specialize(c, p1)`
186186
//!
187-
//! - We treat the other pattern constructors lik big or-patterns of all the possibilities:
187+
//! - We treat the other pattern constructors as if they were a large or-pattern of all the
188+
//! possibilities:
188189
//!
189190
//! `specialize(c, _) := specialize(c, Variant1(_) | Variant2(_, _) | ...)`
190191
//!
@@ -193,7 +194,7 @@
193194
//! `specialize(c, [p0, .., p1]) := specialize(c, [p0, p1] | [p0, _, p1] | [p0, _, _, p1] | ...)`
194195
//!
195196
//! - If `c` is a pattern-only constructor, `specialize` is defined on a case-by-case basis. See
196-
//! the discussion abount constructor splitting in [`super::deconstruct_pat`].
197+
//! the discussion about constructor splitting in [`super::deconstruct_pat`].
197198
//!
198199
//!
199200
//! We then extend this function to work with pattern-stacks as input, by acting on the first

0 commit comments

Comments
 (0)