@@ -1432,8 +1432,11 @@ impl<'tcx> TyCtxt<'tcx> {
1432
1432
}
1433
1433
1434
1434
impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
1435
- fn maybe_report_ambiguity ( & self , obligation : & PredicateObligation < ' tcx > ,
1436
- body_id : Option < hir:: BodyId > ) {
1435
+ fn maybe_report_ambiguity (
1436
+ & self ,
1437
+ obligation : & PredicateObligation < ' tcx > ,
1438
+ body_id : Option < hir:: BodyId > ,
1439
+ ) {
1437
1440
// Unable to successfully determine, probably means
1438
1441
// insufficient type information, but could mean
1439
1442
// ambiguous impls. The latter *ought* to be a
@@ -1442,9 +1445,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1442
1445
let predicate = self . resolve_vars_if_possible ( & obligation. predicate ) ;
1443
1446
let span = obligation. cause . span ;
1444
1447
1445
- debug ! ( "maybe_report_ambiguity(predicate={:?}, obligation={:?})" ,
1446
- predicate,
1447
- obligation) ;
1448
+ debug ! (
1449
+ "maybe_report_ambiguity(predicate={:?}, obligation={:?} body_id={:?}, code={:?})" ,
1450
+ predicate,
1451
+ obligation,
1452
+ body_id,
1453
+ obligation. cause. code,
1454
+ ) ;
1448
1455
1449
1456
// Ambiguity errors are often caused as fallout from earlier
1450
1457
// errors. So just ignore them if this infcx is tainted.
@@ -1456,6 +1463,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1456
1463
ty:: Predicate :: Trait ( ref data) => {
1457
1464
let trait_ref = data. to_poly_trait_ref ( ) ;
1458
1465
let self_ty = trait_ref. self_ty ( ) ;
1466
+ debug ! ( "self_ty {:?} {:?} trait_ref {:?}" , self_ty, self_ty. sty, trait_ref) ;
1467
+
1459
1468
if predicate. references_error ( ) {
1460
1469
return ;
1461
1470
}
@@ -1480,24 +1489,25 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1480
1489
// be ignoring the fact that we don't KNOW the type works
1481
1490
// out. Though even that would probably be harmless, given that
1482
1491
// we're only talking about builtin traits, which are known to be
1483
- // inhabited. But in any case I just threw in this check for
1484
- // has_errors() to be sure that compilation isn't happening
1485
- // anyway. In that case, why inundate the user.
1486
- if !self . tcx . sess . has_errors ( ) {
1487
- if
1488
- self . tcx . lang_items ( ) . sized_trait ( )
1489
- . map_or ( false , |sized_id| sized_id == trait_ref. def_id ( ) )
1490
- {
1491
- self . need_type_info_err ( body_id, span, self_ty) . emit ( ) ;
1492
- } else {
1493
- let mut err = struct_span_err ! ( self . tcx. sess,
1494
- span, E0283 ,
1495
- "type annotations required: \
1496
- cannot resolve `{}`",
1497
- predicate) ;
1498
- self . note_obligation_cause ( & mut err, obligation) ;
1499
- err. emit ( ) ;
1500
- }
1492
+ // inhabited. We used to check for `self.tcx.sess.has_errors()` to
1493
+ // avoid inundating the user with unnecessary errors, but we now
1494
+ // check upstream for type errors and dont add the obligations to
1495
+ // begin with in those cases.
1496
+ if
1497
+ self . tcx . lang_items ( ) . sized_trait ( )
1498
+ . map_or ( false , |sized_id| sized_id == trait_ref. def_id ( ) )
1499
+ {
1500
+ self . need_type_info_err ( body_id, span, self_ty) . emit ( ) ;
1501
+ } else {
1502
+ let mut err = struct_span_err ! (
1503
+ self . tcx. sess,
1504
+ span,
1505
+ E0283 ,
1506
+ "type annotations needed: cannot resolve `{}`" ,
1507
+ predicate,
1508
+ ) ;
1509
+ self . note_obligation_cause ( & mut err, obligation) ;
1510
+ err. emit ( ) ;
1501
1511
}
1502
1512
}
1503
1513
@@ -1524,11 +1534,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1524
1534
1525
1535
_ => {
1526
1536
if !self . tcx . sess . has_errors ( ) {
1527
- let mut err = struct_span_err ! ( self . tcx. sess,
1528
- obligation. cause. span, E0284 ,
1529
- "type annotations required: \
1530
- cannot resolve `{}`",
1531
- predicate) ;
1537
+ let mut err = struct_span_err ! (
1538
+ self . tcx. sess,
1539
+ obligation. cause. span,
1540
+ E0284 ,
1541
+ "type annotations needed: cannot resolve `{}`" ,
1542
+ predicate,
1543
+ ) ;
1532
1544
self . note_obligation_cause ( & mut err, obligation) ;
1533
1545
err. emit ( ) ;
1534
1546
}
@@ -1766,7 +1778,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1766
1778
but not on the corresponding trait method",
1767
1779
predicate) ) ;
1768
1780
}
1769
- ObligationCauseCode :: ReturnType ( _) |
1781
+ ObligationCauseCode :: ReturnType |
1782
+ ObligationCauseCode :: ReturnValue ( _) |
1770
1783
ObligationCauseCode :: BlockTailExpression ( _) => ( ) ,
1771
1784
ObligationCauseCode :: TrivialBound => {
1772
1785
err. help ( "see issue #48214" ) ;
0 commit comments