1
- use super :: deconstruct_pat:: { Constructor , DeconstructedPat } ;
1
+ use super :: deconstruct_pat:: { Constructor , DeconstructedPat , WitnessPat } ;
2
2
use super :: usefulness:: {
3
3
compute_match_usefulness, MatchArm , MatchCheckCtxt , Reachability , UsefulnessReport ,
4
4
} ;
@@ -279,7 +279,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
279
279
280
280
let scrut = & self . thir [ scrut] ;
281
281
let scrut_ty = scrut. ty ;
282
- let report = compute_match_usefulness ( & cx, & tarms, self . lint_level , scrut_ty) ;
282
+ let report = compute_match_usefulness ( & cx, & tarms, self . lint_level , scrut_ty, scrut . span ) ;
283
283
284
284
match source {
285
285
// Don't report arm reachability of desugared `match $iter.into_iter() { iter => .. }`
@@ -473,7 +473,8 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
473
473
let pattern = self . lower_pattern ( & mut cx, pat) ;
474
474
let pattern_ty = pattern. ty ( ) ;
475
475
let arm = MatchArm { pat : pattern, hir_id : self . lint_level , has_guard : false } ;
476
- let report = compute_match_usefulness ( & cx, & [ arm] , self . lint_level , pattern_ty) ;
476
+ let report =
477
+ compute_match_usefulness ( & cx, & [ arm] , self . lint_level , pattern_ty, pattern. span ( ) ) ;
477
478
478
479
// Note: we ignore whether the pattern is unreachable (i.e. whether the type is empty). We
479
480
// only care about exhaustiveness here.
@@ -662,7 +663,7 @@ fn is_let_irrefutable<'p, 'tcx>(
662
663
pat : & ' p DeconstructedPat < ' p , ' tcx > ,
663
664
) -> bool {
664
665
let arms = [ MatchArm { pat, hir_id : pat_id, has_guard : false } ] ;
665
- let report = compute_match_usefulness ( & cx, & arms, pat_id, pat. ty ( ) ) ;
666
+ let report = compute_match_usefulness ( & cx, & arms, pat_id, pat. ty ( ) , pat . span ( ) ) ;
666
667
667
668
// Report if the pattern is unreachable, which can only occur when the type is uninhabited.
668
669
// This also reports unreachable sub-patterns though, so we can't just replace it with an
@@ -701,8 +702,8 @@ fn report_arm_reachability<'p, 'tcx>(
701
702
}
702
703
}
703
704
704
- fn collect_non_exhaustive_tys < ' p , ' tcx > (
705
- pat : & DeconstructedPat < ' p , ' tcx > ,
705
+ fn collect_non_exhaustive_tys < ' tcx > (
706
+ pat : & WitnessPat < ' tcx > ,
706
707
non_exhaustive_tys : & mut FxHashSet < Ty < ' tcx > > ,
707
708
) {
708
709
if matches ! ( pat. ctor( ) , Constructor :: NonExhaustive ) {
@@ -718,7 +719,7 @@ fn non_exhaustive_match<'p, 'tcx>(
718
719
thir : & Thir < ' tcx > ,
719
720
scrut_ty : Ty < ' tcx > ,
720
721
sp : Span ,
721
- witnesses : Vec < DeconstructedPat < ' p , ' tcx > > ,
722
+ witnesses : Vec < WitnessPat < ' tcx > > ,
722
723
arms : & [ ArmId ] ,
723
724
expr_span : Span ,
724
725
) -> ErrorGuaranteed {
@@ -896,10 +897,10 @@ fn non_exhaustive_match<'p, 'tcx>(
896
897
897
898
pub ( crate ) fn joined_uncovered_patterns < ' p , ' tcx > (
898
899
cx : & MatchCheckCtxt < ' p , ' tcx > ,
899
- witnesses : & [ DeconstructedPat < ' p , ' tcx > ] ,
900
+ witnesses : & [ WitnessPat < ' tcx > ] ,
900
901
) -> String {
901
902
const LIMIT : usize = 3 ;
902
- let pat_to_str = |pat : & DeconstructedPat < ' p , ' tcx > | pat. to_pat ( cx) . to_string ( ) ;
903
+ let pat_to_str = |pat : & WitnessPat < ' tcx > | pat. to_pat ( cx) . to_string ( ) ;
903
904
match witnesses {
904
905
[ ] => bug ! ( ) ,
905
906
[ witness] => format ! ( "`{}`" , witness. to_pat( cx) ) ,
@@ -916,7 +917,7 @@ pub(crate) fn joined_uncovered_patterns<'p, 'tcx>(
916
917
}
917
918
918
919
pub ( crate ) fn pattern_not_covered_label (
919
- witnesses : & [ DeconstructedPat < ' _ , ' _ > ] ,
920
+ witnesses : & [ WitnessPat < ' _ > ] ,
920
921
joined_patterns : & str ,
921
922
) -> String {
922
923
format ! ( "pattern{} {} not covered" , rustc_errors:: pluralize!( witnesses. len( ) ) , joined_patterns)
@@ -927,7 +928,7 @@ fn adt_defined_here<'p, 'tcx>(
927
928
cx : & MatchCheckCtxt < ' p , ' tcx > ,
928
929
err : & mut Diagnostic ,
929
930
ty : Ty < ' tcx > ,
930
- witnesses : & [ DeconstructedPat < ' p , ' tcx > ] ,
931
+ witnesses : & [ WitnessPat < ' tcx > ] ,
931
932
) {
932
933
let ty = ty. peel_refs ( ) ;
933
934
if let ty:: Adt ( def, _) = ty. kind ( ) {
@@ -958,7 +959,7 @@ fn adt_defined_here<'p, 'tcx>(
958
959
fn maybe_point_at_variant < ' a , ' p : ' a , ' tcx : ' a > (
959
960
cx : & MatchCheckCtxt < ' p , ' tcx > ,
960
961
def : AdtDef < ' tcx > ,
961
- patterns : impl Iterator < Item = & ' a DeconstructedPat < ' p , ' tcx > > ,
962
+ patterns : impl Iterator < Item = & ' a WitnessPat < ' tcx > > ,
962
963
) -> Vec < Span > {
963
964
use Constructor :: * ;
964
965
let mut covered = vec ! [ ] ;
0 commit comments