Skip to content

Commit 4030b73

Browse files
committed
Use Spans to identify unreachable subpatterns in or-patterns
1 parent 8a6d434 commit 4030b73

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/librustc_mir_build/hair/pattern/_match.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1246,15 +1246,15 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
12461246
}
12471247

12481248
#[derive(Clone, Debug)]
1249-
crate enum Usefulness<'tcx, 'p> {
1249+
crate enum Usefulness<'tcx> {
12501250
/// Carries a list of unreachable subpatterns. Used only in the presence of or-patterns.
1251-
Useful(Vec<&'p Pat<'tcx>>),
1251+
Useful(Vec<Span>),
12521252
/// Carries a list of witnesses of non-exhaustiveness.
12531253
UsefulWithWitness(Vec<Witness<'tcx>>),
12541254
NotUseful,
12551255
}
12561256

1257-
impl<'tcx, 'p> Usefulness<'tcx, 'p> {
1257+
impl<'tcx> Usefulness<'tcx> {
12581258
fn new_useful(preference: WitnessPreference) -> Self {
12591259
match preference {
12601260
ConstructWitness => UsefulWithWitness(vec![Witness(vec![])]),
@@ -1269,7 +1269,7 @@ impl<'tcx, 'p> Usefulness<'tcx, 'p> {
12691269
}
12701270
}
12711271

1272-
fn apply_constructor(
1272+
fn apply_constructor<'p>(
12731273
self,
12741274
cx: &MatchCheckCtxt<'p, 'tcx>,
12751275
ctor: &Constructor<'tcx>,
@@ -1828,7 +1828,7 @@ crate fn is_useful<'p, 'tcx>(
18281828
hir_id: HirId,
18291829
is_under_guard: bool,
18301830
is_top_level: bool,
1831-
) -> Usefulness<'tcx, 'p> {
1831+
) -> Usefulness<'tcx> {
18321832
let &Matrix(ref rows) = matrix;
18331833
debug!("is_useful({:#?}, {:#?})", matrix, v);
18341834

@@ -1861,7 +1861,7 @@ crate fn is_useful<'p, 'tcx>(
18611861
any_is_useful = true;
18621862
unreachable_pats.extend(pats);
18631863
}
1864-
NotUseful => unreachable_pats.push(v.head()),
1864+
NotUseful => unreachable_pats.push(v.head().span),
18651865
UsefulWithWitness(_) => {
18661866
bug!("Encountered or-pat in `v` during exhaustiveness checking")
18671867
}
@@ -2014,7 +2014,7 @@ fn is_useful_specialized<'p, 'tcx>(
20142014
witness_preference: WitnessPreference,
20152015
hir_id: HirId,
20162016
is_under_guard: bool,
2017-
) -> Usefulness<'tcx, 'p> {
2017+
) -> Usefulness<'tcx> {
20182018
debug!("is_useful_specialized({:#?}, {:#?}, {:?})", v, ctor, ty);
20192019

20202020
// We cache the result of `Fields::wildcards` because it is used a lot.

src/librustc_mir_build/hair/pattern/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ fn check_arms<'p, 'tcx>(
392392
}
393393
}
394394
Useful(unreachable_subpatterns) => {
395-
for pat in unreachable_subpatterns {
396-
unreachable_pattern(cx.tcx, pat.span, id, None);
395+
for span in unreachable_subpatterns {
396+
unreachable_pattern(cx.tcx, span, id, None);
397397
}
398398
}
399399
UsefulWithWitness(_) => bug!(),

0 commit comments

Comments
 (0)