Skip to content

Commit 2006498

Browse files
committed
DeconstructedPat.data is always present now
1 parent 85a7b13 commit 2006498

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
416416
{
417417
let mut redundant_subpats = redundant_subpats.clone();
418418
// Emit lints in the order in which they occur in the file.
419-
redundant_subpats.sort_unstable_by_key(|pat| pat.data().unwrap().span);
419+
redundant_subpats.sort_unstable_by_key(|pat| pat.data().span);
420420
for pat in redundant_subpats {
421-
report_unreachable_pattern(cx, arm.arm_data, pat.data().unwrap().span, None)
421+
report_unreachable_pattern(cx, arm.arm_data, pat.data().span, None)
422422
}
423423
}
424424
}
@@ -901,10 +901,10 @@ fn report_arm_reachability<'p, 'tcx>(
901901
let mut catchall = None;
902902
for (arm, is_useful) in report.arm_usefulness.iter() {
903903
if matches!(is_useful, Usefulness::Redundant) {
904-
report_unreachable_pattern(cx, arm.arm_data, arm.pat.data().unwrap().span, catchall)
904+
report_unreachable_pattern(cx, arm.arm_data, arm.pat.data().span, catchall)
905905
}
906906
if !arm.has_guard && catchall.is_none() && pat_is_catchall(arm.pat) {
907-
catchall = Some(arm.pat.data().unwrap().span);
907+
catchall = Some(arm.pat.data().span);
908908
}
909909
}
910910
}

Diff for: compiler/rustc_pattern_analysis/src/lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'p, 'tcx>(
9898
};
9999

100100
use rustc_errors::DecorateLint;
101-
let mut err = rcx.tcx.dcx().struct_span_warn(arm.pat.data().unwrap().span, "");
101+
let mut err = rcx.tcx.dcx().struct_span_warn(arm.pat.data().span, "");
102102
err.primary_message(decorator.msg());
103103
decorator.decorate_lint(&mut err);
104104
err.emit();

Diff for: compiler/rustc_pattern_analysis/src/pat.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ pub struct DeconstructedPat<Cx: TypeCx> {
3737
/// This is also the same as `self.ctor.arity(self.ty)`.
3838
arity: usize,
3939
ty: Cx::Ty,
40-
/// Extra data to store in a pattern. `None` if the pattern is a wildcard that does not
41-
/// correspond to a user-supplied pattern.
42-
data: Option<Cx::PatData>,
40+
/// Extra data to store in a pattern.
41+
data: Cx::PatData,
4342
/// Globally-unique id used to track usefulness at the level of subpatterns.
4443
pub(crate) uid: PatId,
4544
}
@@ -52,7 +51,7 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
5251
ty: Cx::Ty,
5352
data: Cx::PatData,
5453
) -> Self {
55-
DeconstructedPat { ctor, fields, arity, ty, data: Some(data), uid: PatId::new() }
54+
DeconstructedPat { ctor, fields, arity, ty, data, uid: PatId::new() }
5655
}
5756

5857
pub fn at_index(self, idx: usize) -> IndexedPat<Cx> {
@@ -69,10 +68,9 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
6968
pub fn ty(&self) -> &Cx::Ty {
7069
&self.ty
7170
}
72-
/// Returns the extra data stored in a pattern. Returns `None` if the pattern is a wildcard that
73-
/// does not correspond to a user-supplied pattern.
74-
pub fn data(&self) -> Option<&Cx::PatData> {
75-
self.data.as_ref()
71+
/// Returns the extra data stored in a pattern.
72+
pub fn data(&self) -> &Cx::PatData {
73+
&self.data
7674
}
7775

7876
pub fn iter_fields<'a>(&'a self) -> impl Iterator<Item = &'a IndexedPat<Cx>> {

Diff for: compiler/rustc_pattern_analysis/src/rustc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,10 @@ impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
902902
let overlap_as_pat = self.hoist_pat_range(&overlaps_on, *pat.ty());
903903
let overlaps: Vec<_> = overlaps_with
904904
.iter()
905-
.map(|pat| pat.data().unwrap().span)
905+
.map(|pat| pat.data().span)
906906
.map(|span| errors::Overlap { range: overlap_as_pat.clone(), span })
907907
.collect();
908-
let pat_span = pat.data().unwrap().span;
908+
let pat_span = pat.data().span;
909909
self.tcx.emit_node_span_lint(
910910
lint::builtin::OVERLAPPING_RANGE_ENDPOINTS,
911911
self.match_lint_level,

0 commit comments

Comments
 (0)