@@ -1402,8 +1402,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1402
1402
}
1403
1403
1404
1404
debug ! ( "note_type_err(diag={:?})" , diag) ;
1405
+ enum Mismatch < ' a > {
1406
+ Variable ( ty:: error:: ExpectedFound < Ty < ' a > > ) ,
1407
+ Fixed ( & ' static str ) ,
1408
+ }
1405
1409
let ( expected_found, exp_found, is_simple_error) = match values {
1406
- None => ( None , None , false ) ,
1410
+ None => ( None , Mismatch :: Fixed ( "type" ) , false ) ,
1407
1411
Some ( values) => {
1408
1412
let ( is_simple_error, exp_found) = match values {
1409
1413
ValuePairs :: Types ( exp_found) => {
@@ -1417,9 +1421,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1417
1421
)
1418
1422
. report ( diag) ;
1419
1423
1420
- ( is_simple_err, Some ( exp_found) )
1424
+ ( is_simple_err, Mismatch :: Variable ( exp_found) )
1421
1425
}
1422
- _ => ( false , None ) ,
1426
+ ValuePairs :: TraitRefs ( _) => ( false , Mismatch :: Fixed ( "trait" ) ) ,
1427
+ _ => ( false , Mismatch :: Fixed ( "type" ) ) ,
1423
1428
} ;
1424
1429
let vals = match self . values_str ( & values) {
1425
1430
Some ( ( expected, found) ) => Some ( ( expected, found) ) ,
@@ -1445,8 +1450,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1445
1450
}
1446
1451
} ;
1447
1452
if let Some ( ( expected, found) ) = expected_found {
1448
- let expected_label = exp_found. map_or ( "type" . into ( ) , |ef| ef. expected . prefix_string ( ) ) ;
1449
- let found_label = exp_found. map_or ( "type" . into ( ) , |ef| ef. found . prefix_string ( ) ) ;
1453
+ let expected_label = match exp_found {
1454
+ Mismatch :: Variable ( ef) => ef. expected . prefix_string ( ) ,
1455
+ Mismatch :: Fixed ( s) => s. into ( ) ,
1456
+ } ;
1457
+ let found_label = match exp_found {
1458
+ Mismatch :: Variable ( ef) => ef. found . prefix_string ( ) ,
1459
+ Mismatch :: Fixed ( s) => s. into ( ) ,
1460
+ } ;
1461
+ let exp_found = match exp_found {
1462
+ Mismatch :: Variable ( exp_found) => Some ( exp_found) ,
1463
+ Mismatch :: Fixed ( _) => None ,
1464
+ } ;
1450
1465
match ( & terr, expected == found) {
1451
1466
( TypeError :: Sorts ( values) , extra) => {
1452
1467
let sort_string = |ty : Ty < ' tcx > | match ( extra, & ty. kind ) {
@@ -1499,6 +1514,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1499
1514
}
1500
1515
}
1501
1516
}
1517
+ let exp_found = match exp_found {
1518
+ Mismatch :: Variable ( exp_found) => Some ( exp_found) ,
1519
+ Mismatch :: Fixed ( _) => None ,
1520
+ } ;
1502
1521
if let Some ( exp_found) = exp_found {
1503
1522
self . suggest_as_ref_where_appropriate ( span, & exp_found, diag) ;
1504
1523
}
0 commit comments