@@ -1468,75 +1468,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1468
1468
// error type, meaning that an error occurred when typechecking this expression),
1469
1469
// this is a derived error. The error cascaded from another error (that was already
1470
1470
// reported), so it's not useful to display it to the user.
1471
- // The following four methods -- type_error_message_str, type_error_message_str_with_expected,
1472
- // type_error_message, and report_mismatched_types -- implement this logic.
1471
+ // The following methods implement this logic.
1473
1472
// They check if either the actual or expected type is TyError, and don't print the error
1474
1473
// in this case. The typechecker should only ever report type errors involving mismatched
1475
- // types using one of these four methods, and should not call span_err directly for such
1474
+ // types using one of these methods, and should not call span_err directly for such
1476
1475
// errors.
1477
- pub fn type_error_message_str < M > ( & self ,
1478
- sp : Span ,
1479
- mk_msg : M ,
1480
- actual_ty : String ,
1481
- err : Option < & TypeError < ' tcx > > )
1482
- where M : FnOnce ( Option < String > , String ) -> String ,
1483
- {
1484
- self . type_error_message_str_with_expected ( sp, mk_msg, None , actual_ty, err)
1485
- }
1486
-
1487
- pub fn type_error_struct_str < M > ( & self ,
1488
- sp : Span ,
1489
- mk_msg : M ,
1490
- actual_ty : String ,
1491
- err : Option < & TypeError < ' tcx > > )
1492
- -> DiagnosticBuilder < ' tcx >
1493
- where M : FnOnce ( Option < String > , String ) -> String ,
1494
- {
1495
- self . type_error_struct_str_with_expected ( sp, mk_msg, None , actual_ty, err)
1496
- }
1497
-
1498
- pub fn type_error_message_str_with_expected < M > ( & self ,
1499
- sp : Span ,
1500
- mk_msg : M ,
1501
- expected_ty : Option < Ty < ' tcx > > ,
1502
- actual_ty : String ,
1503
- err : Option < & TypeError < ' tcx > > )
1504
- where M : FnOnce ( Option < String > , String ) -> String ,
1505
- {
1506
- self . type_error_struct_str_with_expected ( sp, mk_msg, expected_ty, actual_ty, err)
1507
- . emit ( ) ;
1508
- }
1509
-
1510
- pub fn type_error_struct_str_with_expected < M > ( & self ,
1511
- sp : Span ,
1512
- mk_msg : M ,
1513
- expected_ty : Option < Ty < ' tcx > > ,
1514
- actual_ty : String ,
1515
- err : Option < & TypeError < ' tcx > > )
1516
- -> DiagnosticBuilder < ' tcx >
1517
- where M : FnOnce ( Option < String > , String ) -> String ,
1518
- {
1519
- debug ! ( "hi! expected_ty = {:?}, actual_ty = {}" , expected_ty, actual_ty) ;
1520
-
1521
- let resolved_expected = expected_ty. map ( |e_ty| self . resolve_type_vars_if_possible ( & e_ty) ) ;
1522
-
1523
- if !resolved_expected. references_error ( ) {
1524
- let error_str = err. map_or ( "" . to_string ( ) , |t_err| {
1525
- format ! ( " ({})" , t_err)
1526
- } ) ;
1527
-
1528
- let mut db = self . tcx . sess . struct_span_err ( sp, & format ! ( "{}{}" ,
1529
- mk_msg( resolved_expected. map( |t| self . ty_to_string( t) ) , actual_ty) ,
1530
- error_str) ) ;
1531
-
1532
- if let Some ( err) = err {
1533
- self . tcx . note_and_explain_type_err ( & mut db, err, sp) ;
1534
- }
1535
- db
1536
- } else {
1537
- self . tcx . sess . diagnostic ( ) . struct_dummy ( )
1538
- }
1539
- }
1540
1476
1541
1477
pub fn type_error_message < M > ( & self ,
1542
1478
sp : Span ,
@@ -1556,16 +1492,30 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1556
1492
-> DiagnosticBuilder < ' tcx >
1557
1493
where M : FnOnce ( String ) -> String ,
1558
1494
{
1495
+ debug ! ( "type_error_struct({:?}, {:?}, {:?})" , sp, actual_ty, err) ;
1496
+
1559
1497
let actual_ty = self . resolve_type_vars_if_possible ( & actual_ty) ;
1560
1498
1561
1499
// Don't report an error if actual type is TyError.
1562
1500
if actual_ty. references_error ( ) {
1563
1501
return self . tcx . sess . diagnostic ( ) . struct_dummy ( ) ;
1564
1502
}
1565
1503
1566
- self . type_error_struct_str ( sp,
1567
- move |_e, a| { mk_msg ( a) } ,
1568
- self . ty_to_string ( actual_ty) , err)
1504
+ let error_str = err. map_or ( "" . to_string ( ) , |t_err| {
1505
+ format ! ( " ({})" , t_err)
1506
+ } ) ;
1507
+
1508
+ let msg = mk_msg ( self . ty_to_string ( actual_ty) ) ;
1509
+
1510
+ // FIXME: use an error code.
1511
+ let mut db = self . tcx . sess . struct_span_err (
1512
+ sp, & format ! ( "{} {}" , msg, error_str) ) ;
1513
+
1514
+ if let Some ( err) = err {
1515
+ self . tcx . note_and_explain_type_err ( & mut db, err, sp) ;
1516
+ }
1517
+
1518
+ db
1569
1519
}
1570
1520
1571
1521
pub fn report_mismatched_types ( & self ,
0 commit comments