@@ -1303,10 +1303,39 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1303
1303
_ => { }
1304
1304
}
1305
1305
1306
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
1307
+ enum TyKind {
1308
+ Closure ,
1309
+ Opaque ,
1310
+ Generator ,
1311
+ Foreign ,
1312
+ }
1313
+
1314
+ impl TyKind {
1315
+ fn descr ( & self ) -> & ' static str {
1316
+ match self {
1317
+ Self :: Closure => "closure" ,
1318
+ Self :: Opaque => "opaque type" ,
1319
+ Self :: Generator => "generator" ,
1320
+ Self :: Foreign => "foreign type" ,
1321
+ }
1322
+ }
1323
+
1324
+ fn from_ty ( ty : Ty < ' _ > ) -> Option < ( Self , DefId ) > {
1325
+ match ty. kind {
1326
+ ty:: Closure ( def_id, _) => Some ( ( Self :: Closure , def_id) ) ,
1327
+ ty:: Opaque ( def_id, _) => Some ( ( Self :: Opaque , def_id) ) ,
1328
+ ty:: Generator ( def_id, ..) => Some ( ( Self :: Generator , def_id) ) ,
1329
+ ty:: Foreign ( def_id) => Some ( ( Self :: Foreign , def_id) ) ,
1330
+ _ => None ,
1331
+ }
1332
+ }
1333
+ }
1334
+
1306
1335
struct OpaqueTypesVisitor < ' tcx > {
1307
- types : FxHashMap < & ' static str , FxHashSet < Span > > ,
1308
- expected : FxHashMap < & ' static str , FxHashSet < Span > > ,
1309
- found : FxHashMap < & ' static str , FxHashSet < Span > > ,
1336
+ types : FxHashMap < TyKind , FxHashSet < Span > > ,
1337
+ expected : FxHashMap < TyKind , FxHashSet < Span > > ,
1338
+ found : FxHashMap < TyKind , FxHashSet < Span > > ,
1310
1339
ignore_span : Span ,
1311
1340
tcx : TyCtxt < ' tcx > ,
1312
1341
}
@@ -1350,7 +1379,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1350
1379
} ,
1351
1380
if count > 1 { "one of the " } else { "" } ,
1352
1381
target,
1353
- key,
1382
+ key. descr ( ) ,
1354
1383
pluralize!( count) ,
1355
1384
) ,
1356
1385
) ;
@@ -1362,18 +1391,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1362
1391
1363
1392
impl < ' tcx > ty:: fold:: TypeVisitor < ' tcx > for OpaqueTypesVisitor < ' tcx > {
1364
1393
fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> bool {
1365
- let kind = match t. kind {
1366
- ty:: Closure ( ..) => "closure" ,
1367
- ty:: Opaque ( ..) => "opaque type" ,
1368
- ty:: Generator ( ..) => "generator" ,
1369
- ty:: Foreign ( ..) => "foreign type" ,
1370
- _ => "" ,
1371
- } ;
1372
- if let ty:: Closure ( def_id, _)
1373
- | ty:: Opaque ( def_id, _)
1374
- | ty:: Generator ( def_id, ..)
1375
- | ty:: Foreign ( def_id) = t. kind
1376
- {
1394
+ if let Some ( ( kind, def_id) ) = TyKind :: from_ty ( t) {
1377
1395
let span = self . tcx . def_span ( def_id) ;
1378
1396
// Avoid cluttering the output when the "found" and error span overlap:
1379
1397
//
0 commit comments