DeconstructedPat.data
is always present now
This commit is contained in:
parent
6ae9fa31f0
commit
d339bdaa07
4 changed files with 15 additions and 17 deletions
|
@ -420,9 +420,9 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
|
|||
{
|
||||
let mut redundant_subpats = redundant_subpats.clone();
|
||||
// Emit lints in the order in which they occur in the file.
|
||||
redundant_subpats.sort_unstable_by_key(|pat| pat.data().unwrap().span);
|
||||
redundant_subpats.sort_unstable_by_key(|pat| pat.data().span);
|
||||
for pat in redundant_subpats {
|
||||
report_unreachable_pattern(cx, arm.arm_data, pat.data().unwrap().span, None)
|
||||
report_unreachable_pattern(cx, arm.arm_data, pat.data().span, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -905,10 +905,10 @@ fn report_arm_reachability<'p, 'tcx>(
|
|||
let mut catchall = None;
|
||||
for (arm, is_useful) in report.arm_usefulness.iter() {
|
||||
if matches!(is_useful, Usefulness::Redundant) {
|
||||
report_unreachable_pattern(cx, arm.arm_data, arm.pat.data().unwrap().span, catchall)
|
||||
report_unreachable_pattern(cx, arm.arm_data, arm.pat.data().span, catchall)
|
||||
}
|
||||
if !arm.has_guard && catchall.is_none() && pat_is_catchall(arm.pat) {
|
||||
catchall = Some(arm.pat.data().unwrap().span);
|
||||
catchall = Some(arm.pat.data().span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'p, 'tcx>(
|
|||
};
|
||||
|
||||
use rustc_errors::LintDiagnostic;
|
||||
let mut err = rcx.tcx.dcx().struct_span_warn(arm.pat.data().unwrap().span, "");
|
||||
let mut err = rcx.tcx.dcx().struct_span_warn(arm.pat.data().span, "");
|
||||
err.primary_message(decorator.msg());
|
||||
decorator.decorate_lint(&mut err);
|
||||
err.emit();
|
||||
|
|
|
@ -37,9 +37,8 @@ pub struct DeconstructedPat<Cx: TypeCx> {
|
|||
/// This is also the same as `self.ctor.arity(self.ty)`.
|
||||
arity: usize,
|
||||
ty: Cx::Ty,
|
||||
/// Extra data to store in a pattern. `None` if the pattern is a wildcard that does not
|
||||
/// correspond to a user-supplied pattern.
|
||||
data: Option<Cx::PatData>,
|
||||
/// Extra data to store in a pattern.
|
||||
data: Cx::PatData,
|
||||
/// Globally-unique id used to track usefulness at the level of subpatterns.
|
||||
pub(crate) uid: PatId,
|
||||
}
|
||||
|
@ -52,7 +51,7 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
|
|||
ty: Cx::Ty,
|
||||
data: Cx::PatData,
|
||||
) -> Self {
|
||||
DeconstructedPat { ctor, fields, arity, ty, data: Some(data), uid: PatId::new() }
|
||||
DeconstructedPat { ctor, fields, arity, ty, data, uid: PatId::new() }
|
||||
}
|
||||
|
||||
pub fn at_index(self, idx: usize) -> IndexedPat<Cx> {
|
||||
|
@ -69,10 +68,9 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
|
|||
pub fn ty(&self) -> &Cx::Ty {
|
||||
&self.ty
|
||||
}
|
||||
/// Returns the extra data stored in a pattern. Returns `None` if the pattern is a wildcard that
|
||||
/// does not correspond to a user-supplied pattern.
|
||||
pub fn data(&self) -> Option<&Cx::PatData> {
|
||||
self.data.as_ref()
|
||||
/// Returns the extra data stored in a pattern.
|
||||
pub fn data(&self) -> &Cx::PatData {
|
||||
&self.data
|
||||
}
|
||||
pub fn arity(&self) -> usize {
|
||||
self.arity
|
||||
|
|
|
@ -904,10 +904,10 @@ impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
|
|||
let overlap_as_pat = self.hoist_pat_range(&overlaps_on, *pat.ty());
|
||||
let overlaps: Vec<_> = overlaps_with
|
||||
.iter()
|
||||
.map(|pat| pat.data().unwrap().span)
|
||||
.map(|pat| pat.data().span)
|
||||
.map(|span| errors::Overlap { range: overlap_as_pat.clone(), span })
|
||||
.collect();
|
||||
let pat_span = pat.data().unwrap().span;
|
||||
let pat_span = pat.data().span;
|
||||
self.tcx.emit_node_span_lint(
|
||||
lint::builtin::OVERLAPPING_RANGE_ENDPOINTS,
|
||||
self.match_lint_level,
|
||||
|
@ -927,7 +927,7 @@ impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
|
|||
gap: IntRange,
|
||||
gapped_with: &[&crate::pat::DeconstructedPat<Self>],
|
||||
) {
|
||||
let Some(&thir_pat) = pat.data() else { return };
|
||||
let &thir_pat = pat.data();
|
||||
let thir::PatKind::Range(range) = &thir_pat.kind else { return };
|
||||
// Only lint when the left range is an exclusive range.
|
||||
if range.end != rustc_hir::RangeEnd::Excluded {
|
||||
|
@ -975,7 +975,7 @@ impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
|
|||
gap_with: gapped_with
|
||||
.iter()
|
||||
.map(|pat| errors::GappedRange {
|
||||
span: pat.data().unwrap().span,
|
||||
span: pat.data().span,
|
||||
gap: gap_as_pat.clone(),
|
||||
first_range: thir_pat.clone(),
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue