@@ -20,7 +20,6 @@ use rustc_hir::Node;
20
20
use rustc_middle:: mir:: interpret:: ErrorHandled ;
21
21
use rustc_middle:: ty:: error:: ExpectedFound ;
22
22
use rustc_middle:: ty:: fold:: TypeFolder ;
23
- use rustc_middle:: ty:: subst:: GenericArgKind ;
24
23
use rustc_middle:: ty:: {
25
24
self , fast_reject, AdtKind , SubtypePredicate , ToPolyTraitRef , ToPredicate , Ty , TyCtxt ,
26
25
TypeFoldable , WithConstness ,
@@ -1513,10 +1512,21 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1513
1512
// check upstream for type errors and don't add the obligations to
1514
1513
// begin with in those cases.
1515
1514
if self . tcx . lang_items ( ) . sized_trait ( ) == Some ( trait_ref. def_id ( ) ) {
1516
- self . need_type_info_err ( body_id, span, self_ty, ErrorCode :: E0282 ) . emit ( ) ;
1515
+ self . emit_inference_failure_err (
1516
+ body_id,
1517
+ span,
1518
+ self_ty. into ( ) ,
1519
+ ErrorCode :: E0282 ,
1520
+ )
1521
+ . emit ( ) ;
1517
1522
return ;
1518
1523
}
1519
- let mut err = self . need_type_info_err ( body_id, span, self_ty, ErrorCode :: E0283 ) ;
1524
+ let mut err = self . emit_inference_failure_err (
1525
+ body_id,
1526
+ span,
1527
+ self_ty. into ( ) ,
1528
+ ErrorCode :: E0283 ,
1529
+ ) ;
1520
1530
err. note ( & format ! ( "cannot satisfy `{}`" , predicate) ) ;
1521
1531
if let ObligationCauseCode :: ItemObligation ( def_id) = obligation. cause . code {
1522
1532
self . suggest_fully_qualified_path ( & mut err, def_id, span, trait_ref. def_id ( ) ) ;
@@ -1580,17 +1590,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1580
1590
return ;
1581
1591
}
1582
1592
1583
- match arg. unpack ( ) {
1584
- GenericArgKind :: Lifetime ( lt) => {
1585
- span_bug ! ( span, "unexpected well formed predicate: {:?}" , lt)
1586
- }
1587
- GenericArgKind :: Type ( ty) => {
1588
- self . need_type_info_err ( body_id, span, ty, ErrorCode :: E0282 )
1589
- }
1590
- GenericArgKind :: Const ( ct) => {
1591
- self . need_type_info_err_const ( body_id, span, ct, ErrorCode :: E0282 )
1592
- }
1593
- }
1593
+ self . emit_inference_failure_err ( body_id, span, arg, ErrorCode :: E0282 )
1594
1594
}
1595
1595
1596
1596
ty:: PredicateAtom :: Subtype ( data) => {
@@ -1601,7 +1601,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1601
1601
let SubtypePredicate { a_is_expected : _, a, b } = data;
1602
1602
// both must be type variables, or the other would've been instantiated
1603
1603
assert ! ( a. is_ty_var( ) && b. is_ty_var( ) ) ;
1604
- self . need_type_info_err ( body_id, span, a, ErrorCode :: E0282 )
1604
+ self . emit_inference_failure_err ( body_id, span, a. into ( ) , ErrorCode :: E0282 )
1605
1605
}
1606
1606
ty:: PredicateAtom :: Projection ( data) => {
1607
1607
let trait_ref = ty:: Binder :: bind ( data) . to_poly_trait_ref ( self . tcx ) ;
@@ -1612,7 +1612,12 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1612
1612
}
1613
1613
if self_ty. needs_infer ( ) && ty. needs_infer ( ) {
1614
1614
// We do this for the `foo.collect()?` case to produce a suggestion.
1615
- let mut err = self . need_type_info_err ( body_id, span, self_ty, ErrorCode :: E0284 ) ;
1615
+ let mut err = self . emit_inference_failure_err (
1616
+ body_id,
1617
+ span,
1618
+ self_ty. into ( ) ,
1619
+ ErrorCode :: E0284 ,
1620
+ ) ;
1616
1621
err. note ( & format ! ( "cannot satisfy `{}`" , predicate) ) ;
1617
1622
err
1618
1623
} else {
0 commit comments