@@ -1339,7 +1339,8 @@ pub(crate) struct DeconstructedPat<'p, 'tcx> {
1339
1339
fields : Fields < ' p , ' tcx > ,
1340
1340
ty : Ty < ' tcx > ,
1341
1341
span : Span ,
1342
- reachable : Cell < bool > ,
1342
+ /// Whether removing this arm would change the behavior of the match expression.
1343
+ useful : Cell < bool > ,
1343
1344
}
1344
1345
1345
1346
impl < ' p , ' tcx > DeconstructedPat < ' p , ' tcx > {
@@ -1353,7 +1354,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1353
1354
ty : Ty < ' tcx > ,
1354
1355
span : Span ,
1355
1356
) -> Self {
1356
- DeconstructedPat { ctor, fields, ty, span, reachable : Cell :: new ( false ) }
1357
+ DeconstructedPat { ctor, fields, ty, span, useful : Cell :: new ( false ) }
1357
1358
}
1358
1359
1359
1360
/// Note: the input patterns must have been lowered through
@@ -1634,38 +1635,38 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1634
1635
}
1635
1636
}
1636
1637
1637
- /// We keep track for each pattern if it was ever reachable during the analysis. This is used
1638
- /// with `unreachable_spans ` to report unreachable subpatterns arising from or patterns.
1639
- pub ( super ) fn set_reachable ( & self ) {
1640
- self . reachable . set ( true )
1638
+ /// We keep track for each pattern if it was ever useful during the analysis. This is used
1639
+ /// with `redundant_spans ` to report redundant subpatterns arising from or patterns.
1640
+ pub ( super ) fn set_useful ( & self ) {
1641
+ self . useful . set ( true )
1641
1642
}
1642
- pub ( super ) fn is_reachable ( & self ) -> bool {
1643
- if self . reachable . get ( ) {
1643
+ pub ( super ) fn is_useful ( & self ) -> bool {
1644
+ if self . useful . get ( ) {
1644
1645
true
1645
- } else if self . is_or_pat ( ) && self . iter_fields ( ) . any ( |f| f. is_reachable ( ) ) {
1646
+ } else if self . is_or_pat ( ) && self . iter_fields ( ) . any ( |f| f. is_useful ( ) ) {
1646
1647
// We always expand or patterns in the matrix, so we will never see the actual
1647
1648
// or-pattern (the one with constructor `Or`) in the column. As such, it will not be
1648
- // marked as reachable itself, only its children will. We recover this information here.
1649
- self . set_reachable ( ) ;
1649
+ // marked as useful itself, only its children will. We recover this information here.
1650
+ self . set_useful ( ) ;
1650
1651
true
1651
1652
} else {
1652
1653
false
1653
1654
}
1654
1655
}
1655
1656
1656
- /// Report the spans of subpatterns that were not reachable , if any.
1657
- pub ( super ) fn unreachable_spans ( & self ) -> Vec < Span > {
1657
+ /// Report the spans of subpatterns that were not useful , if any.
1658
+ pub ( super ) fn redundant_spans ( & self ) -> Vec < Span > {
1658
1659
let mut spans = Vec :: new ( ) ;
1659
- self . collect_unreachable_spans ( & mut spans) ;
1660
+ self . collect_redundant_spans ( & mut spans) ;
1660
1661
spans
1661
1662
}
1662
- fn collect_unreachable_spans ( & self , spans : & mut Vec < Span > ) {
1663
- // We don't look at subpatterns if we already reported the whole pattern as unreachable .
1664
- if !self . is_reachable ( ) {
1663
+ fn collect_redundant_spans ( & self , spans : & mut Vec < Span > ) {
1664
+ // We don't look at subpatterns if we already reported the whole pattern as redundant .
1665
+ if !self . is_useful ( ) {
1665
1666
spans. push ( self . span ) ;
1666
1667
} else {
1667
1668
for p in self . iter_fields ( ) {
1668
- p. collect_unreachable_spans ( spans) ;
1669
+ p. collect_redundant_spans ( spans) ;
1669
1670
}
1670
1671
}
1671
1672
}
0 commit comments