@@ -634,7 +634,7 @@ impl<'tcx> Constructor<'tcx> {
634
634
fn split_meta_constructor (
635
635
self ,
636
636
cx : & MatchCheckCtxt < ' _ , ' tcx > ,
637
- pcx : PatCtxt < ' tcx > ,
637
+ ty : Ty < ' tcx > ,
638
638
head_ctors : & Vec < Constructor < ' tcx > > ,
639
639
) -> SmallVec < [ Constructor < ' tcx > ; 1 ] > {
640
640
debug ! ( "split_meta_constructor {:?}" , self ) ;
@@ -735,7 +735,7 @@ impl<'tcx> Constructor<'tcx> {
735
735
( Border :: JustBefore ( n) , Border :: AfterMax ) => Some ( n..=u128:: MAX ) ,
736
736
( Border :: AfterMax , _) => None ,
737
737
} )
738
- . map ( |range| IntRange :: range_to_ctor ( cx. tcx , pcx . ty , range) )
738
+ . map ( |range| IntRange :: range_to_ctor ( cx. tcx , ty, range) )
739
739
. collect ( )
740
740
}
741
741
ConstantRange ( ..) => smallvec ! [ self ] ,
@@ -843,20 +843,19 @@ impl<'tcx> Constructor<'tcx> {
843
843
. collect ( )
844
844
}
845
845
Wildcard => {
846
- let is_declared_nonexhaustive =
847
- !cx. is_local ( pcx. ty ) && cx. is_non_exhaustive_enum ( pcx. ty ) ;
846
+ let is_declared_nonexhaustive = !cx. is_local ( ty) && cx. is_non_exhaustive_enum ( ty) ;
848
847
849
848
// `all_ctors` are all the constructors for the given type, which
850
849
// should all be represented (or caught with the wild pattern `_`).
851
- let all_ctors = all_constructors ( cx, pcx ) ;
850
+ let all_ctors = all_constructors ( cx, ty ) ;
852
851
853
- let is_privately_empty = all_ctors. is_empty ( ) && !cx. is_uninhabited ( pcx . ty ) ;
852
+ let is_privately_empty = all_ctors. is_empty ( ) && !cx. is_uninhabited ( ty) ;
854
853
855
854
// For privately empty and non-exhaustive enums, we work as if there were an "extra"
856
855
// `_` constructor for the type, so we can never match over all constructors.
857
856
let is_non_exhaustive = is_privately_empty
858
857
|| is_declared_nonexhaustive
859
- || ( pcx . ty . is_ptr_sized_integral ( )
858
+ || ( ty. is_ptr_sized_integral ( )
860
859
&& !cx. tcx . features ( ) . precise_pointer_size_matching ) ;
861
860
862
861
// `missing_ctors` is the set of constructors from the same type as the
@@ -880,13 +879,8 @@ impl<'tcx> Constructor<'tcx> {
880
879
881
880
// Missing constructors are those that are not matched by any
882
881
// non-wildcard patterns in the current column.
883
- let missing_ctors = MissingConstructors :: new (
884
- pcx,
885
- cx. tcx ,
886
- cx. param_env ,
887
- all_ctors,
888
- head_ctors. clone ( ) ,
889
- ) ;
882
+ let missing_ctors =
883
+ MissingConstructors :: new ( cx. tcx , cx. param_env , all_ctors, head_ctors. clone ( ) ) ;
890
884
debug ! (
891
885
"missing_ctors.is_empty()={:#?} is_non_exhaustive={:#?}" ,
892
886
missing_ctors. is_empty( ) ,
@@ -920,7 +914,7 @@ impl<'tcx> Constructor<'tcx> {
920
914
// contain any wildcards so we don't recurse infinitely.
921
915
all_ctors
922
916
. into_iter ( )
923
- . flat_map ( |ctor| ctor. split_meta_constructor ( cx, pcx , head_ctors) )
917
+ . flat_map ( |ctor| ctor. split_meta_constructor ( cx, ty , head_ctors) )
924
918
. collect ( )
925
919
}
926
920
}
@@ -933,7 +927,6 @@ impl<'tcx> Constructor<'tcx> {
933
927
/// notation).
934
928
fn subtract_meta_constructor (
935
929
self ,
936
- _pcx : PatCtxt < ' tcx > ,
937
930
tcx : TyCtxt < ' tcx > ,
938
931
param_env : ty:: ParamEnv < ' tcx > ,
939
932
used_ctors : & Vec < Constructor < ' tcx > > ,
@@ -1170,7 +1163,6 @@ impl<'tcx> Constructor<'tcx> {
1170
1163
fn apply < ' a > (
1171
1164
& self ,
1172
1165
cx : & MatchCheckCtxt < ' a , ' tcx > ,
1173
- pcx : PatCtxt < ' tcx > ,
1174
1166
ty : Ty < ' tcx > ,
1175
1167
pats : impl IntoIterator < Item = Pat < ' tcx > > ,
1176
1168
) -> SmallVec < [ Pat < ' tcx > ; 1 ] > {
@@ -1236,7 +1228,7 @@ impl<'tcx> Constructor<'tcx> {
1236
1228
// `Option::Some`, we get the pattern `Some(_)`.
1237
1229
return missing_ctors
1238
1230
. iter ( )
1239
- . flat_map ( |ctor| ctor. apply_wildcards ( cx, pcx , ty) )
1231
+ . flat_map ( |ctor| ctor. apply_wildcards ( cx, ty) )
1240
1232
. collect ( ) ;
1241
1233
}
1242
1234
} ;
@@ -1248,11 +1240,10 @@ impl<'tcx> Constructor<'tcx> {
1248
1240
fn apply_wildcards < ' a > (
1249
1241
& self ,
1250
1242
cx : & MatchCheckCtxt < ' a , ' tcx > ,
1251
- pcx : PatCtxt < ' tcx > ,
1252
1243
ty : Ty < ' tcx > ,
1253
1244
) -> SmallVec < [ Pat < ' tcx > ; 1 ] > {
1254
1245
let pats = self . wildcard_subpatterns ( cx, ty) . rev ( ) ;
1255
- self . apply ( cx, pcx , ty, pats)
1246
+ self . apply ( cx, ty, pats)
1256
1247
}
1257
1248
}
1258
1249
@@ -1281,15 +1272,14 @@ impl<'tcx> Usefulness<'tcx> {
1281
1272
fn apply_constructor (
1282
1273
self ,
1283
1274
cx : & MatchCheckCtxt < ' _ , ' tcx > ,
1284
- pcx : PatCtxt < ' tcx > ,
1285
1275
ctor : & Constructor < ' tcx > ,
1286
- lty : Ty < ' tcx > ,
1276
+ ty : Ty < ' tcx > ,
1287
1277
) -> Self {
1288
1278
match self {
1289
1279
UsefulWithWitness ( witnesses) => UsefulWithWitness (
1290
1280
witnesses
1291
1281
. into_iter ( )
1292
- . flat_map ( |witness| witness. apply_constructor ( cx, pcx , & ctor, lty ) )
1282
+ . flat_map ( |witness| witness. apply_constructor ( cx, & ctor, ty ) )
1293
1283
. collect ( ) ,
1294
1284
) ,
1295
1285
x => x,
@@ -1303,11 +1293,6 @@ pub enum WitnessPreference {
1303
1293
LeaveOutWitness ,
1304
1294
}
1305
1295
1306
- #[ derive( Copy , Clone , Debug ) ]
1307
- struct PatCtxt < ' tcx > {
1308
- ty : Ty < ' tcx > ,
1309
- }
1310
-
1311
1296
/// A witness of non-exhaustiveness for error reporting, represented
1312
1297
/// as a list of patterns (in reverse order of construction) with
1313
1298
/// wildcards inside to represent elements that can take any inhabitant
@@ -1365,15 +1350,14 @@ impl<'tcx> Witness<'tcx> {
1365
1350
fn apply_constructor < ' a > (
1366
1351
mut self ,
1367
1352
cx : & MatchCheckCtxt < ' a , ' tcx > ,
1368
- pcx : PatCtxt < ' tcx > ,
1369
1353
ctor : & Constructor < ' tcx > ,
1370
1354
ty : Ty < ' tcx > ,
1371
1355
) -> SmallVec < [ Self ; 1 ] > {
1372
1356
let arity = ctor. arity ( cx, ty) ;
1373
1357
let applied_pats = {
1374
1358
let len = self . 0 . len ( ) as u64 ;
1375
1359
let pats = self . 0 . drain ( ( len - arity) as usize ..) . rev ( ) ;
1376
- ctor. apply ( cx, pcx , ty, pats)
1360
+ ctor. apply ( cx, ty, pats)
1377
1361
} ;
1378
1362
1379
1363
applied_pats
@@ -1396,10 +1380,10 @@ impl<'tcx> Witness<'tcx> {
1396
1380
/// `Option<!>`, we do not include `Some(_)` in the returned list of constructors.
1397
1381
fn all_constructors < ' a , ' tcx > (
1398
1382
cx : & MatchCheckCtxt < ' a , ' tcx > ,
1399
- pcx : PatCtxt < ' tcx > ,
1383
+ ty : Ty < ' tcx > ,
1400
1384
) -> Vec < Constructor < ' tcx > > {
1401
- debug ! ( "all_constructors({:?})" , pcx . ty) ;
1402
- let ctors = match pcx . ty . kind {
1385
+ debug ! ( "all_constructors({:?})" , ty) ;
1386
+ let ctors = match ty. kind {
1403
1387
ty:: Bool => {
1404
1388
[ true , false ] . iter ( ) . map ( |& b| ConstantValue ( ty:: Const :: from_bool ( cx. tcx , b) ) ) . collect ( )
1405
1389
}
@@ -1447,15 +1431,15 @@ fn all_constructors<'a, 'tcx>(
1447
1431
let bits = Integer :: from_attr ( & cx. tcx , SignedInt ( ity) ) . size ( ) . bits ( ) as u128 ;
1448
1432
let min = 1u128 << ( bits - 1 ) ;
1449
1433
let max = min - 1 ;
1450
- vec ! [ ConstantRange ( min, max, pcx . ty, RangeEnd :: Included ) ]
1434
+ vec ! [ ConstantRange ( min, max, ty, RangeEnd :: Included ) ]
1451
1435
}
1452
1436
ty:: Uint ( uty) => {
1453
1437
let size = Integer :: from_attr ( & cx. tcx , UnsignedInt ( uty) ) . size ( ) ;
1454
1438
let max = truncate ( u128:: max_value ( ) , size) ;
1455
- vec ! [ ConstantRange ( 0 , max, pcx . ty, RangeEnd :: Included ) ]
1439
+ vec ! [ ConstantRange ( 0 , max, ty, RangeEnd :: Included ) ]
1456
1440
}
1457
1441
_ => {
1458
- if cx. is_uninhabited ( pcx . ty ) {
1442
+ if cx. is_uninhabited ( ty) {
1459
1443
vec ! [ ]
1460
1444
} else {
1461
1445
vec ! [ Single ]
@@ -1648,9 +1632,8 @@ impl<'tcx> IntRange<'tcx> {
1648
1632
// A struct to compute a set of constructors equivalent to `all_ctors \ used_ctors`.
1649
1633
#[ derive( Clone ) ]
1650
1634
struct MissingConstructors < ' tcx > {
1651
- pcx : PatCtxt < ' tcx > ,
1652
- tcx : TyCtxt < ' tcx > ,
1653
1635
param_env : ty:: ParamEnv < ' tcx > ,
1636
+ tcx : TyCtxt < ' tcx > ,
1654
1637
all_ctors : Vec < Constructor < ' tcx > > ,
1655
1638
used_ctors : Vec < Constructor < ' tcx > > ,
1656
1639
}
@@ -1663,13 +1646,12 @@ type MissingConstructorsIter<'a, 'tcx, F> = std::iter::FlatMap<
1663
1646
1664
1647
impl < ' tcx > MissingConstructors < ' tcx > {
1665
1648
fn new (
1666
- pcx : PatCtxt < ' tcx > ,
1667
1649
tcx : TyCtxt < ' tcx > ,
1668
1650
param_env : ty:: ParamEnv < ' tcx > ,
1669
1651
all_ctors : Vec < Constructor < ' tcx > > ,
1670
1652
used_ctors : Vec < Constructor < ' tcx > > ,
1671
1653
) -> Self {
1672
- MissingConstructors { pcx , tcx, param_env, all_ctors, used_ctors }
1654
+ MissingConstructors { tcx, param_env, all_ctors, used_ctors }
1673
1655
}
1674
1656
1675
1657
fn into_inner ( self ) -> ( Vec < Constructor < ' tcx > > , Vec < Constructor < ' tcx > > ) {
@@ -1690,12 +1672,7 @@ impl<'tcx> MissingConstructors<'tcx> {
1690
1672
impl FnMut ( & ' a Constructor < ' tcx > ) -> SmallVec < [ Constructor < ' tcx > ; 1 ] > ,
1691
1673
> {
1692
1674
self . all_ctors . iter ( ) . flat_map ( move |req_ctor| {
1693
- req_ctor. clone ( ) . subtract_meta_constructor (
1694
- self . pcx ,
1695
- self . tcx ,
1696
- self . param_env ,
1697
- & self . used_ctors ,
1698
- )
1675
+ req_ctor. clone ( ) . subtract_meta_constructor ( self . tcx , self . param_env , & self . used_ctors )
1699
1676
} )
1700
1677
}
1701
1678
}
@@ -1801,12 +1778,10 @@ pub fn is_useful<'p, 'a, 'tcx>(
1801
1778
. collect ( ) ;
1802
1779
debug ! ( "matrix_head_ctors = {:#?}" , matrix_head_ctors) ;
1803
1780
1804
- let pcx = PatCtxt { ty } ;
1805
-
1806
1781
v_constructors
1807
1782
. into_iter ( )
1808
- . flat_map ( |ctor| ctor. split_meta_constructor ( cx, pcx , & matrix_head_ctors) )
1809
- . map ( |c| is_useful_specialized ( cx, pcx , matrix, v, c, pcx . ty , witness_preference) )
1783
+ . flat_map ( |ctor| ctor. split_meta_constructor ( cx, ty , & matrix_head_ctors) )
1784
+ . map ( |c| is_useful_specialized ( cx, matrix, v, c, ty, witness_preference) )
1810
1785
. find ( |result| result. is_useful ( ) )
1811
1786
. unwrap_or ( NotUseful )
1812
1787
}
@@ -1815,23 +1790,22 @@ pub fn is_useful<'p, 'a, 'tcx>(
1815
1790
/// to the specialised version of both the pattern matrix `M` and the new pattern `q`.
1816
1791
fn is_useful_specialized < ' p , ' a , ' tcx > (
1817
1792
cx : & MatchCheckCtxt < ' a , ' tcx > ,
1818
- pcx : PatCtxt < ' tcx > ,
1819
1793
matrix : & Matrix < ' p , ' tcx > ,
1820
1794
v : & PatStack < ' _ , ' tcx > ,
1821
1795
ctor : Constructor < ' tcx > ,
1822
- lty : Ty < ' tcx > ,
1796
+ ty : Ty < ' tcx > ,
1823
1797
witness_preference : WitnessPreference ,
1824
1798
) -> Usefulness < ' tcx > {
1825
- debug ! ( "is_useful_specialized({:#?}, {:#?}, {:?})" , v, ctor, lty ) ;
1799
+ debug ! ( "is_useful_specialized({:#?}, {:#?}, {:?})" , v, ctor, ty ) ;
1826
1800
1827
- let ctor_wild_subpatterns_owned: Vec < _ > = ctor. wildcard_subpatterns ( cx, lty ) . collect ( ) ;
1801
+ let ctor_wild_subpatterns_owned: Vec < _ > = ctor. wildcard_subpatterns ( cx, ty ) . collect ( ) ;
1828
1802
let ctor_wild_subpatterns: Vec < _ > = ctor_wild_subpatterns_owned. iter ( ) . collect ( ) ;
1829
1803
let matrix = matrix. specialize ( cx, & ctor, & ctor_wild_subpatterns) ;
1830
1804
let ret = v
1831
1805
. specialize ( cx, & ctor, & ctor_wild_subpatterns)
1832
1806
. into_iter ( )
1833
1807
. map ( |v| is_useful ( cx, & matrix, & v, witness_preference) )
1834
- . map ( |u| u. apply_constructor ( cx, pcx , & ctor, lty ) )
1808
+ . map ( |u| u. apply_constructor ( cx, & ctor, ty ) )
1835
1809
. find ( |result| result. is_useful ( ) )
1836
1810
. unwrap_or ( NotUseful ) ;
1837
1811
ret
0 commit comments