Skip to content

Commit 295d922

Browse files
Stop passing both trait pred and trait ref
1 parent 63e2986 commit 295d922

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
@@ -601,7 +601,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
601601
let explanation = get_explanation_based_on_obligation(
602602
self.tcx,
603603
&obligation,
604-
main_trait_ref,
605604
&main_trait_predicate,
606605
pre_message,
607606
);
@@ -753,7 +752,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
753752

754753
self.try_to_add_help_message(
755754
&obligation,
756-
main_trait_ref,
757755
&main_trait_predicate,
758756
&mut err,
759757
span,
@@ -3205,7 +3203,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32053203
fn try_to_add_help_message(
32063204
&self,
32073205
obligation: &PredicateObligation<'tcx>,
3208-
trait_ref: ty::PolyTraitRef<'tcx>,
32093206
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
32103207
err: &mut Diag<'_>,
32113208
span: Span,
@@ -3223,15 +3220,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32233220
};
32243221

32253222
// Try to report a help message
3223+
let trait_def_id = trait_predicate.def_id();
32263224
if is_fn_trait
32273225
&& let Ok((implemented_kind, params)) = self.type_implements_fn_trait(
32283226
obligation.param_env,
3229-
trait_ref.self_ty(),
3227+
trait_predicate.self_ty(),
32303228
trait_predicate.skip_binder().polarity,
32313229
)
32323230
{
3233-
self.add_help_message_for_fn_trait(trait_ref, err, implemented_kind, params);
3234-
} else if !trait_ref.has_non_region_infer()
3231+
self.add_help_message_for_fn_trait(
3232+
trait_predicate.to_poly_trait_ref(),
3233+
err,
3234+
implemented_kind,
3235+
params,
3236+
);
3237+
} else if !trait_predicate.has_non_region_infer()
32353238
&& self.predicate_can_apply(obligation.param_env, *trait_predicate)
32363239
{
32373240
// If a where-clause may be useful, remind the
@@ -3247,21 +3250,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32473250
None,
32483251
obligation.cause.body_id,
32493252
);
3250-
} else if trait_ref.def_id().is_local()
3251-
&& self.tcx.trait_impls_of(trait_ref.def_id()).is_empty()
3252-
&& !self.tcx.trait_is_auto(trait_ref.def_id())
3253-
&& !self.tcx.trait_is_alias(trait_ref.def_id())
3253+
} else if trait_def_id.is_local()
3254+
&& self.tcx.trait_impls_of(trait_def_id).is_empty()
3255+
&& !self.tcx.trait_is_auto(trait_def_id)
3256+
&& !self.tcx.trait_is_alias(trait_def_id)
32543257
{
32553258
err.span_help(
3256-
self.tcx.def_span(trait_ref.def_id()),
3259+
self.tcx.def_span(trait_def_id),
32573260
crate::fluent_generated::trait_selection_trait_has_no_impls,
32583261
);
32593262
} else if !suggested && !unsatisfied_const {
32603263
// Can't show anything else useful, try to find similar impls.
32613264
let impl_candidates = self.find_similar_impl_candidates(*trait_predicate);
32623265
if !self.report_similar_impl_candidates(
32633266
&impl_candidates,
3264-
trait_ref,
3267+
trait_predicate.to_poly_trait_ref(),
32653268
body_def_id,
32663269
err,
32673270
true,
@@ -3278,7 +3281,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32783281
self.suggest_convert_to_slice(
32793282
err,
32803283
obligation,
3281-
trait_ref,
3284+
trait_predicate.to_poly_trait_ref(),
32823285
impl_candidates.as_slice(),
32833286
span,
32843287
);

0 commit comments

Comments
 (0)