@@ -1303,39 +1303,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1303
1303
_ => { }
1304
1304
}
1305
1305
1306
- /// This is a bare signal of what kind of type we're dealing with. `ty::TyKind` tracks
1307
- /// extra information about each type, but we only care about the category.
1308
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
1309
- enum TyCategory {
1310
- Closure ,
1311
- Opaque ,
1312
- Generator ,
1313
- Foreign ,
1314
- }
1315
-
1316
- impl TyCategory {
1317
- fn descr ( & self ) -> & ' static str {
1318
- match self {
1319
- Self :: Closure => "closure" ,
1320
- Self :: Opaque => "opaque type" ,
1321
- Self :: Generator => "generator" ,
1322
- Self :: Foreign => "foreign type" ,
1323
- }
1324
- }
1325
-
1326
- fn from_ty ( ty : Ty < ' _ > ) -> Option < ( Self , DefId ) > {
1327
- match ty. kind {
1328
- ty:: Closure ( def_id, _) => Some ( ( Self :: Closure , def_id) ) ,
1329
- ty:: Opaque ( def_id, _) => Some ( ( Self :: Opaque , def_id) ) ,
1330
- ty:: Generator ( def_id, ..) => Some ( ( Self :: Generator , def_id) ) ,
1331
- ty:: Foreign ( def_id) => Some ( ( Self :: Foreign , def_id) ) ,
1332
- _ => None ,
1333
- }
1334
- }
1335
- }
1336
-
1337
1306
struct OpaqueTypesVisitor < ' tcx > {
1338
- types : FxHashMap < TyKind , FxHashSet < Span > > ,
1307
+ types : FxHashMap < TyCategory , FxHashSet < Span > > ,
1339
1308
expected : FxHashMap < TyCategory , FxHashSet < Span > > ,
1340
1309
found : FxHashMap < TyCategory , FxHashSet < Span > > ,
1341
1310
ignore_span : Span ,
@@ -1375,7 +1344,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1375
1344
& self ,
1376
1345
err : & mut DiagnosticBuilder < ' _ > ,
1377
1346
target : & str ,
1378
- types : & FxHashMap < TyKind , FxHashSet < Span > > ,
1347
+ types : & FxHashMap < TyCategory , FxHashSet < Span > > ,
1379
1348
) {
1380
1349
for ( key, values) in types. iter ( ) {
1381
1350
let count = values. len ( ) ;
@@ -1394,7 +1363,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1394
1363
} ,
1395
1364
if count > 1 { "one of the " } else { "" } ,
1396
1365
target,
1397
- key ,
1366
+ kind ,
1398
1367
pluralize!( count) ,
1399
1368
) ,
1400
1369
) ;
@@ -1405,7 +1374,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1405
1374
1406
1375
impl < ' tcx > ty:: fold:: TypeVisitor < ' tcx > for OpaqueTypesVisitor < ' tcx > {
1407
1376
fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> bool {
1408
- if let Some ( ( kind, def_id) ) = TyKind :: from_ty ( t) {
1377
+ if let Some ( ( kind, def_id) ) = TyCategory :: from_ty ( t) {
1409
1378
let span = self . tcx . def_span ( def_id) ;
1410
1379
// Avoid cluttering the output when the "found" and error span overlap:
1411
1380
//
@@ -2067,3 +2036,34 @@ impl<'tcx> ObligationCause<'tcx> {
2067
2036
}
2068
2037
}
2069
2038
}
2039
+
2040
+ /// This is a bare signal of what kind of type we're dealing with. `ty::TyKind` tracks
2041
+ /// extra information about each type, but we only care about the category.
2042
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
2043
+ crate enum TyCategory {
2044
+ Closure ,
2045
+ Opaque ,
2046
+ Generator ,
2047
+ Foreign ,
2048
+ }
2049
+
2050
+ impl TyCategory {
2051
+ fn descr ( & self ) -> & ' static str {
2052
+ match self {
2053
+ Self :: Closure => "closure" ,
2054
+ Self :: Opaque => "opaque type" ,
2055
+ Self :: Generator => "generator" ,
2056
+ Self :: Foreign => "foreign type" ,
2057
+ }
2058
+ }
2059
+
2060
+ pub fn from_ty ( ty : Ty < ' _ > ) -> Option < ( Self , DefId ) > {
2061
+ match ty. kind {
2062
+ ty:: Closure ( def_id, _) => Some ( ( Self :: Closure , def_id) ) ,
2063
+ ty:: Opaque ( def_id, _) => Some ( ( Self :: Opaque , def_id) ) ,
2064
+ ty:: Generator ( def_id, ..) => Some ( ( Self :: Generator , def_id) ) ,
2065
+ ty:: Foreign ( def_id) => Some ( ( Self :: Foreign , def_id) ) ,
2066
+ _ => None ,
2067
+ }
2068
+ }
2069
+ }
0 commit comments