@@ -414,7 +414,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
414
414
ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Trait ( trait_predicate) ) => {
415
415
let trait_predicate = bound_predicate. rebind ( trait_predicate) ;
416
416
let trait_predicate = self . resolve_vars_if_possible ( trait_predicate) ;
417
- let trait_predicate = self . apply_do_not_recommend ( trait_predicate, & mut obligation) ;
418
417
419
418
// Let's use the root obligation as the main message, when we care about the
420
419
// most general case ("X doesn't implement Pattern<'_>") over the case that
@@ -996,12 +995,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
996
995
err. emit ( )
997
996
}
998
997
999
- fn apply_do_not_recommend (
1000
- & self ,
1001
- mut trait_predicate : ty:: Binder < ' tcx , ty:: TraitPredicate < ' tcx > > ,
1002
- obligation : & ' _ mut PredicateObligation < ' tcx > ,
1003
- ) -> ty:: Binder < ' tcx , ty:: TraitPredicate < ' tcx > > {
998
+ fn apply_do_not_recommend ( & self , obligation : & ' _ mut PredicateObligation < ' tcx > ) -> bool {
1004
999
let mut base_cause = obligation. cause . code ( ) . clone ( ) ;
1000
+ let mut applied_do_not_recommend = false ;
1005
1001
loop {
1006
1002
if let ObligationCauseCode :: ImplDerived ( ref c) = base_cause {
1007
1003
if self . tcx . has_attrs_with_path (
@@ -1011,7 +1007,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1011
1007
let code = ( * c. derived . parent_code ) . clone ( ) ;
1012
1008
obligation. cause . map_code ( |_| code) ;
1013
1009
obligation. predicate = c. derived . parent_trait_pred . upcast ( self . tcx ) ;
1014
- trait_predicate = c . derived . parent_trait_pred . clone ( ) ;
1010
+ applied_do_not_recommend = true ;
1015
1011
}
1016
1012
}
1017
1013
if let Some ( ( parent_cause, _parent_pred) ) = base_cause. parent ( ) {
@@ -1021,7 +1017,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1021
1017
}
1022
1018
}
1023
1019
1024
- trait_predicate
1020
+ applied_do_not_recommend
1025
1021
}
1026
1022
1027
1023
fn emit_specialized_closure_kind_error (
@@ -1521,6 +1517,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1521
1517
1522
1518
#[ instrument( skip( self ) , level = "debug" ) ]
1523
1519
fn report_fulfillment_error ( & self , error : & FulfillmentError < ' tcx > ) -> ErrorGuaranteed {
1520
+ let mut error = FulfillmentError {
1521
+ obligation : error. obligation . clone ( ) ,
1522
+ code : error. code . clone ( ) ,
1523
+ root_obligation : error. root_obligation . clone ( ) ,
1524
+ } ;
1525
+ if self . apply_do_not_recommend ( & mut error. obligation ) {
1526
+ error. code = FulfillmentErrorCode :: Select ( SelectionError :: Unimplemented ) ;
1527
+ }
1528
+
1524
1529
match error. code {
1525
1530
FulfillmentErrorCode :: Select ( ref selection_error) => self . report_selection_error (
1526
1531
error. obligation . clone ( ) ,
0 commit comments