@@ -1432,8 +1432,11 @@ impl<'tcx> TyCtxt<'tcx> {
14321432} 
14331433
14341434impl < ' 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+     )  { 
14371440        // Unable to successfully determine, probably means 
14381441        // insufficient type information, but could mean 
14391442        // ambiguous impls. The latter *ought* to be a 
@@ -1442,9 +1445,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14421445        let  predicate = self . resolve_vars_if_possible ( & obligation. predicate ) ; 
14431446        let  span = obligation. cause . span ; 
14441447
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+         ) ; 
14481455
14491456        // Ambiguity errors are often caused as fallout from earlier 
14501457        // errors. So just ignore them if this infcx is tainted. 
@@ -1456,6 +1463,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14561463            ty:: Predicate :: Trait ( ref  data)  => { 
14571464                let  trait_ref = data. to_poly_trait_ref ( ) ; 
14581465                let  self_ty = trait_ref. self_ty ( ) ; 
1466+                 debug ! ( "self_ty {:?} {:?} trait_ref {:?}" ,  self_ty,  self_ty. sty,  trait_ref) ; 
1467+ 
14591468                if  predicate. references_error ( )  { 
14601469                    return ; 
14611470                } 
@@ -1480,24 +1489,25 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14801489                // be ignoring the fact that we don't KNOW the type works 
14811490                // out. Though even that would probably be harmless, given that 
14821491                // 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- , 
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 ( ) ; 
15011511                } 
15021512            } 
15031513
@@ -1524,11 +1534,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15241534
15251535            _ => { 
15261536                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- , 
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+                     ) ; 
15321544                    self . note_obligation_cause ( & mut  err,  obligation) ; 
15331545                    err. emit ( ) ; 
15341546                } 
@@ -1766,7 +1778,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17661778, 
17671779                             predicate) ) ; 
17681780            } 
1769-             ObligationCauseCode :: ReturnType ( _)  |
1781+             ObligationCauseCode :: ReturnType  |
1782+             ObligationCauseCode :: ReturnValue ( _)  |
17701783            ObligationCauseCode :: BlockTailExpression ( _)  => ( ) , 
17711784            ObligationCauseCode :: TrivialBound  => { 
17721785                err. help ( "see issue #48214" ) ; 
0 commit comments