@@ -764,6 +764,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
764
764
self . suggest_borrowing_for_object_cast ( & mut err, & root_obligation, * concrete_ty, * obj_ty) ;
765
765
}
766
766
767
+ let mut unsatisfied_const = false ;
767
768
if trait_predicate. is_const_if_const ( ) && obligation. param_env . is_const ( ) {
768
769
let non_const_predicate = trait_ref. without_const ( ) ;
769
770
let non_const_obligation = Obligation {
@@ -773,6 +774,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
773
774
recursion_depth : obligation. recursion_depth ,
774
775
} ;
775
776
if self . predicate_may_hold ( & non_const_obligation) {
777
+ unsatisfied_const = true ;
776
778
err. span_note (
777
779
span,
778
780
& format ! (
@@ -924,7 +926,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
924
926
}
925
927
}
926
928
} else if !trait_ref. has_non_region_infer ( )
927
- && self . predicate_can_apply ( obligation. param_env , trait_ref )
929
+ && self . predicate_can_apply ( obligation. param_env , trait_predicate )
928
930
{
929
931
// If a where-clause may be useful, remind the
930
932
// user that they can add it.
@@ -939,7 +941,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
939
941
None ,
940
942
obligation. cause . body_id ,
941
943
) ;
942
- } else if !suggested {
944
+ } else if !suggested && !unsatisfied_const {
943
945
// Can't show anything else useful, try to find similar impls.
944
946
let impl_candidates = self . find_similar_impl_candidates ( trait_predicate) ;
945
947
if !self . report_similar_impl_candidates (
@@ -1436,7 +1438,7 @@ trait InferCtxtPrivExt<'tcx> {
1436
1438
fn predicate_can_apply (
1437
1439
& self ,
1438
1440
param_env : ty:: ParamEnv < ' tcx > ,
1439
- pred : ty:: PolyTraitRef < ' tcx > ,
1441
+ pred : ty:: PolyTraitPredicate < ' tcx > ,
1440
1442
) -> bool ;
1441
1443
1442
1444
fn note_obligation_cause ( & self , err : & mut Diagnostic , obligation : & PredicateObligation < ' tcx > ) ;
@@ -2511,7 +2513,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2511
2513
fn predicate_can_apply (
2512
2514
& self ,
2513
2515
param_env : ty:: ParamEnv < ' tcx > ,
2514
- pred : ty:: PolyTraitRef < ' tcx > ,
2516
+ pred : ty:: PolyTraitPredicate < ' tcx > ,
2515
2517
) -> bool {
2516
2518
struct ParamToVarFolder < ' a , ' tcx > {
2517
2519
infcx : & ' a InferCtxt < ' tcx > ,
@@ -2555,7 +2557,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2555
2557
let obligation = Obligation :: new (
2556
2558
ObligationCause :: dummy ( ) ,
2557
2559
param_env,
2558
- cleaned_pred. without_const ( ) . to_predicate ( selcx. tcx ( ) ) ,
2560
+ cleaned_pred. to_predicate ( selcx. tcx ( ) ) ,
2559
2561
) ;
2560
2562
2561
2563
self . predicate_may_hold ( & obligation)
0 commit comments