Skip to content

Commit 5cbd6c7

Browse files
Stop passing both trait pred and trait ref
1 parent 4ef3d8b commit 5cbd6c7

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4822,14 +4822,13 @@ impl<'a, 'hir> hir::intravisit::Visitor<'hir> for ReplaceImplTraitVisitor<'a> {
48224822
pub(super) fn get_explanation_based_on_obligation<'tcx>(
48234823
tcx: TyCtxt<'tcx>,
48244824
obligation: &PredicateObligation<'tcx>,
4825-
trait_ref: ty::PolyTraitRef<'tcx>,
48264825
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
48274826
pre_message: String,
48284827
) -> String {
48294828
if let ObligationCauseCode::MainFunctionType = obligation.cause.code() {
48304829
"consider using `()`, or a `Result`".to_owned()
48314830
} else {
4832-
let ty_desc = match trait_ref.skip_binder().self_ty().kind() {
4831+
let ty_desc = match trait_predicate.self_ty().skip_binder().kind() {
48334832
ty::FnDef(_, _) => Some("fn item"),
48344833
ty::Closure(_, _) => Some("closure"),
48354834
_ => None,
@@ -4854,7 +4853,7 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
48544853
format!(
48554854
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
48564855
trait_predicate.print_modifiers_and_trait_path(),
4857-
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
4856+
tcx.short_ty_string(trait_predicate.self_ty().skip_binder(), &mut None),
48584857
)
48594858
} else {
48604859
// "the trait bound `T: !Send` is not satisfied" reads better than "`!Send` is

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
603603
let explanation = get_explanation_based_on_obligation(
604604
self.tcx,
605605
&obligation,
606-
leaf_trait_ref,
607606
&leaf_trait_predicate,
608607
pre_message,
609608
);
@@ -755,7 +754,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
755754

756755
self.try_to_add_help_message(
757756
&obligation,
758-
leaf_trait_ref,
759757
&leaf_trait_predicate,
760758
&mut err,
761759
span,
@@ -3207,7 +3205,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32073205
fn try_to_add_help_message(
32083206
&self,
32093207
obligation: &PredicateObligation<'tcx>,
3210-
trait_ref: ty::PolyTraitRef<'tcx>,
32113208
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
32123209
err: &mut Diag<'_>,
32133210
span: Span,
@@ -3225,15 +3222,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32253222
};
32263223

32273224
// Try to report a help message
3225+
let trait_def_id = trait_predicate.def_id();
32283226
if is_fn_trait
32293227
&& let Ok((implemented_kind, params)) = self.type_implements_fn_trait(
32303228
obligation.param_env,
3231-
trait_ref.self_ty(),
3229+
trait_predicate.self_ty(),
32323230
trait_predicate.skip_binder().polarity,
32333231
)
32343232
{
3235-
self.add_help_message_for_fn_trait(trait_ref, err, implemented_kind, params);
3236-
} else if !trait_ref.has_non_region_infer()
3233+
self.add_help_message_for_fn_trait(
3234+
trait_predicate.to_poly_trait_ref(),
3235+
err,
3236+
implemented_kind,
3237+
params,
3238+
);
3239+
} else if !trait_predicate.has_non_region_infer()
32373240
&& self.predicate_can_apply(obligation.param_env, *trait_predicate)
32383241
{
32393242
// If a where-clause may be useful, remind the
@@ -3249,21 +3252,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32493252
None,
32503253
obligation.cause.body_id,
32513254
);
3252-
} else if trait_ref.def_id().is_local()
3253-
&& self.tcx.trait_impls_of(trait_ref.def_id()).is_empty()
3254-
&& !self.tcx.trait_is_auto(trait_ref.def_id())
3255-
&& !self.tcx.trait_is_alias(trait_ref.def_id())
3255+
} else if trait_def_id.is_local()
3256+
&& self.tcx.trait_impls_of(trait_def_id).is_empty()
3257+
&& !self.tcx.trait_is_auto(trait_def_id)
3258+
&& !self.tcx.trait_is_alias(trait_def_id)
32563259
{
32573260
err.span_help(
3258-
self.tcx.def_span(trait_ref.def_id()),
3261+
self.tcx.def_span(trait_def_id),
32593262
crate::fluent_generated::trait_selection_trait_has_no_impls,
32603263
);
32613264
} else if !suggested && !unsatisfied_const {
32623265
// Can't show anything else useful, try to find similar impls.
32633266
let impl_candidates = self.find_similar_impl_candidates(*trait_predicate);
32643267
if !self.report_similar_impl_candidates(
32653268
&impl_candidates,
3266-
trait_ref,
3269+
trait_predicate.to_poly_trait_ref(),
32673270
body_def_id,
32683271
err,
32693272
true,
@@ -3280,7 +3283,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32803283
self.suggest_convert_to_slice(
32813284
err,
32823285
obligation,
3283-
trait_ref,
3286+
trait_predicate.to_poly_trait_ref(),
32843287
impl_candidates.as_slice(),
32853288
span,
32863289
);

0 commit comments

Comments
 (0)