Skip to content

Commit f8d12d9

Browse files
Stop passing both trait pred and trait ref
1 parent 93d83c8 commit f8d12d9

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
@@ -4863,14 +4863,13 @@ impl<'a, 'hir> hir::intravisit::Visitor<'hir> for ReplaceImplTraitVisitor<'a> {
48634863
pub(super) fn get_explanation_based_on_obligation<'tcx>(
48644864
tcx: TyCtxt<'tcx>,
48654865
obligation: &PredicateObligation<'tcx>,
4866-
trait_ref: ty::PolyTraitRef<'tcx>,
48674866
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
48684867
pre_message: String,
48694868
) -> String {
48704869
if let ObligationCauseCode::MainFunctionType = obligation.cause.code() {
48714870
"consider using `()`, or a `Result`".to_owned()
48724871
} else {
4873-
let ty_desc = match trait_ref.skip_binder().self_ty().kind() {
4872+
let ty_desc = match trait_predicate.self_ty().skip_binder().kind() {
48744873
ty::FnDef(_, _) => Some("fn item"),
48754874
ty::Closure(_, _) => Some("closure"),
48764875
_ => None,
@@ -4895,7 +4894,7 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
48954894
format!(
48964895
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
48974896
trait_predicate.print_modifiers_and_trait_path(),
4898-
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
4897+
tcx.short_ty_string(trait_predicate.self_ty().skip_binder(), &mut None),
48994898
)
49004899
} else {
49014900
// "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
);
@@ -759,7 +758,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
759758

760759
self.try_to_add_help_message(
761760
&obligation,
762-
leaf_trait_ref,
763761
&leaf_trait_predicate,
764762
&mut err,
765763
span,
@@ -3215,7 +3213,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32153213
fn try_to_add_help_message(
32163214
&self,
32173215
obligation: &PredicateObligation<'tcx>,
3218-
trait_ref: ty::PolyTraitRef<'tcx>,
32193216
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
32203217
err: &mut Diag<'_>,
32213218
span: Span,
@@ -3233,15 +3230,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32333230
};
32343231

32353232
// Try to report a help message
3233+
let trait_def_id = trait_predicate.def_id();
32363234
if is_fn_trait
32373235
&& let Ok((implemented_kind, params)) = self.type_implements_fn_trait(
32383236
obligation.param_env,
3239-
trait_ref.self_ty(),
3237+
trait_predicate.self_ty(),
32403238
trait_predicate.skip_binder().polarity,
32413239
)
32423240
{
3243-
self.add_help_message_for_fn_trait(trait_ref, err, implemented_kind, params);
3244-
} else if !trait_ref.has_non_region_infer()
3241+
self.add_help_message_for_fn_trait(
3242+
trait_predicate.to_poly_trait_ref(),
3243+
err,
3244+
implemented_kind,
3245+
params,
3246+
);
3247+
} else if !trait_predicate.has_non_region_infer()
32453248
&& self.predicate_can_apply(obligation.param_env, *trait_predicate)
32463249
{
32473250
// If a where-clause may be useful, remind the
@@ -3257,21 +3260,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32573260
None,
32583261
obligation.cause.body_id,
32593262
);
3260-
} else if trait_ref.def_id().is_local()
3261-
&& self.tcx.trait_impls_of(trait_ref.def_id()).is_empty()
3262-
&& !self.tcx.trait_is_auto(trait_ref.def_id())
3263-
&& !self.tcx.trait_is_alias(trait_ref.def_id())
3263+
} else if trait_def_id.is_local()
3264+
&& self.tcx.trait_impls_of(trait_def_id).is_empty()
3265+
&& !self.tcx.trait_is_auto(trait_def_id)
3266+
&& !self.tcx.trait_is_alias(trait_def_id)
32643267
{
32653268
err.span_help(
3266-
self.tcx.def_span(trait_ref.def_id()),
3269+
self.tcx.def_span(trait_def_id),
32673270
crate::fluent_generated::trait_selection_trait_has_no_impls,
32683271
);
32693272
} else if !suggested && !unsatisfied_const {
32703273
// Can't show anything else useful, try to find similar impls.
32713274
let impl_candidates = self.find_similar_impl_candidates(*trait_predicate);
32723275
if !self.report_similar_impl_candidates(
32733276
&impl_candidates,
3274-
trait_ref,
3277+
trait_predicate.to_poly_trait_ref(),
32753278
body_def_id,
32763279
err,
32773280
true,
@@ -3288,7 +3291,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32883291
self.suggest_convert_to_slice(
32893292
err,
32903293
obligation,
3291-
trait_ref,
3294+
trait_predicate.to_poly_trait_ref(),
32923295
impl_candidates.as_slice(),
32933296
span,
32943297
);

0 commit comments

Comments
 (0)