Skip to content

Commit 8465c82

Browse files
committed
Cleanup comments and dead code
1 parent 9715df3 commit 8465c82

File tree

2 files changed

+9
-37
lines changed

2 files changed

+9
-37
lines changed

compiler/rustc_pattern_analysis/src/pat.rs

+4-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! As explained in [`crate::usefulness`], values and patterns are made from constructors applied to
22
//! fields. This file defines types that represent patterns in this way.
3-
use std::cell::Cell;
43
use std::fmt;
54

65
use smallvec::{smallvec, SmallVec};
@@ -11,11 +10,8 @@ use crate::TypeCx;
1110
use self::Constructor::*;
1211

1312
/// Values and patterns can be represented as a constructor applied to some fields. This represents
14-
/// a pattern in this form.
15-
/// This also uses interior mutability to keep track of whether the pattern has been found reachable
16-
/// during analysis. For this reason they cannot be cloned.
17-
/// A `DeconstructedPat` will almost always come from user input; the only exception are some
18-
/// `Wildcard`s introduced during specialization.
13+
/// a pattern in this form. A `DeconstructedPat` will almost always come from user input; the only
14+
/// exception are some `Wildcard`s introduced during pattern lowering.
1915
///
2016
/// Note that the number of fields may not match the fields declared in the original struct/variant.
2117
/// This happens if a private or `non_exhaustive` field is uninhabited, because the code mustn't
@@ -28,19 +24,11 @@ pub struct DeconstructedPat<Cx: TypeCx> {
2824
/// Extra data to store in a pattern. `None` if the pattern is a wildcard that does not
2925
/// correspond to a user-supplied pattern.
3026
data: Option<Cx::PatData>,
31-
/// Whether removing this arm would change the behavior of the match expression.
32-
pub(crate) useful: Cell<bool>,
3327
}
3428

3529
impl<Cx: TypeCx> DeconstructedPat<Cx> {
3630
pub fn wildcard(ty: Cx::Ty) -> Self {
37-
DeconstructedPat {
38-
ctor: Wildcard,
39-
fields: Vec::new(),
40-
ty,
41-
data: None,
42-
useful: Cell::new(false),
43-
}
31+
DeconstructedPat { ctor: Wildcard, fields: Vec::new(), ty, data: None }
4432
}
4533

4634
pub fn new(
@@ -49,7 +37,7 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
4937
ty: Cx::Ty,
5038
data: Cx::PatData,
5139
) -> Self {
52-
DeconstructedPat { ctor, fields, ty, data: Some(data), useful: Cell::new(false) }
40+
DeconstructedPat { ctor, fields, ty, data: Some(data) }
5341
}
5442

5543
pub(crate) fn is_or_pat(&self) -> bool {
@@ -107,12 +95,6 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
10795
}
10896
}
10997

110-
/// We keep track for each pattern if it was ever useful during the analysis. This is used with
111-
/// `redundant_subpatterns` to report redundant subpatterns arising from or patterns.
112-
pub(crate) fn set_useful(&self) {
113-
self.useful.set(true)
114-
}
115-
11698
/// Walk top-down and call `it` in each place where a pattern occurs
11799
/// starting with the root pattern `walk` is called on. If `it` returns
118100
/// false then we will descend no further but siblings will be processed.
@@ -267,12 +249,6 @@ impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
267249
PatOrWild::Pat(pat) => pat.specialize(other_ctor, ctor_arity),
268250
}
269251
}
270-
271-
pub(crate) fn set_useful(&self) {
272-
if let PatOrWild::Pat(pat) = self {
273-
pat.set_useful()
274-
}
275-
}
276252
}
277253

278254
impl<'p, Cx: TypeCx> fmt::Debug for PatOrWild<'p, Cx> {

compiler/rustc_pattern_analysis/src/usefulness.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,9 @@
466466
//! first pattern of a row in the matrix is an or-pattern, we expand it by duplicating the rest of
467467
//! the row as necessary. This is handled automatically in [`Matrix`].
468468
//!
469-
//! This makes usefulness tracking subtle, because we also want to compute whether an alternative
470-
//! of an or-pattern is redundant, e.g. in `Some(_) | Some(0)`. We track usefulness of each
471-
//! subpattern by interior mutability in [`DeconstructedPat`] with `set_useful`/`is_useful`.
472-
//!
473-
//! It's unfortunate that we have to use interior mutability, but believe me (Nadrieril), I have
474-
//! tried [other](https://github.com/rust-lang/rust/pull/80104)
475-
//! [solutions](https://github.com/rust-lang/rust/pull/80632) and nothing is remotely as simple.
469+
//! This makes usefulness tracking subtle, because we also want to compute whether an alternative of
470+
//! an or-pattern is redundant, e.g. in `Some(_) | Some(0)`. We therefore track usefulness of each
471+
//! subpattern of the match.
476472
//!
477473
//!
478474
//!
@@ -1462,8 +1458,8 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
14621458
/// The core of the algorithm.
14631459
///
14641460
/// This recursively computes witnesses of the non-exhaustiveness of `matrix` (if any). Also tracks
1465-
/// usefulness of each row in the matrix (in `row.useful`). We track usefulness of each
1466-
/// subpattern using interior mutability in `DeconstructedPat`.
1461+
/// usefulness of each row in the matrix (in `row.useful`). We track usefulness of each subpattern
1462+
/// in `mcx.useful_subpatterns`.
14671463
///
14681464
/// The input `Matrix` and the output `WitnessMatrix` together match the type exhaustively.
14691465
///

0 commit comments

Comments
 (0)