});
let substs = self.tcx.mk_substs_trait(ty.skip_binder(), &[var.into()]);
let obligation = Obligation::new(
+ self.tcx,
ObligationCause::dummy(),
param_env,
ty.rebind(ty::TraitPredicate {
trait_ref: ty::TraitRef::new(trait_def_id, substs),
constness,
polarity,
- })
- .to_predicate(self.tcx),
+ }),
);
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(self.tcx);
fulfill_cx.register_predicate_obligation(self, obligation);
))
);
- if is_try_conversion {
- let none_error = self
- .tcx
- .get_diagnostic_item(sym::none_error)
- .map(|def_id| tcx.type_of(def_id));
- let should_convert_option_to_result =
- Some(trait_ref.skip_binder().substs.type_at(1)) == none_error;
- let should_convert_result_to_option =
- Some(trait_ref.self_ty().skip_binder()) == none_error;
- if should_convert_option_to_result {
- err.span_suggestion_verbose(
- span.shrink_to_lo(),
- "consider converting the `Option<T>` into a `Result<T, _>` \
- using `Option::ok_or` or `Option::ok_or_else`",
- ".ok_or_else(|| /* error value */)",
- Applicability::HasPlaceholders,
- );
- } else if should_convert_result_to_option {
- err.span_suggestion_verbose(
- span.shrink_to_lo(),
- "consider converting the `Result<T, _>` into an `Option<T>` \
- using `Result::ok`",
- ".ok()",
- Applicability::MachineApplicable,
- );
- }
- if let Some(ret_span) = self.return_type_span(&obligation) {
- err.span_label(
- ret_span,
- &format!(
- "expected `{}` because of this",
- trait_ref.skip_binder().self_ty()
- ),
- );
- }
+ if is_try_conversion && let Some(ret_span) = self.return_type_span(&obligation) {
+ err.span_label(
+ ret_span,
+ &format!(
+ "expected `{}` because of this",
+ trait_ref.skip_binder().self_ty()
+ ),
+ );
}
if Some(trait_ref.def_id()) == tcx.lang_items().tuple_trait() {
);
trait_pred
});
- let unit_obligation = obligation.with(predicate.to_predicate(tcx));
+ let unit_obligation = obligation.with(tcx, predicate);
if self.predicate_may_hold(&unit_obligation) {
err.note(
"this error might have been caused by changes to \
..*tr
});
- Obligation::new(ObligationCause::dummy(), param_env, trait_pred.to_predicate(self.tcx))
+ Obligation::new(self.tcx, ObligationCause::dummy(), param_env, trait_pred)
}
#[instrument(skip(self), level = "debug")]
)
};
- let obligation = Obligation::new(
- obligation.cause.clone(),
- obligation.param_env,
- trait_ref.to_poly_trait_predicate(),
- );
+ let obligation = obligation.with(self.tcx, trait_ref.to_poly_trait_predicate());
let mut selcx = SelectionContext::with_query_mode(
&self,
crate::traits::TraitQueryMode::Standard,
)
.value;
- let obligation = Obligation::new(
- ObligationCause::dummy(),
- param_env,
- cleaned_pred.to_predicate(selcx.tcx()),
- );
+ let obligation =
+ Obligation::new(self.tcx, ObligationCause::dummy(), param_env, cleaned_pred);
self.predicate_may_hold(&obligation)
})
let Some(param) = generics.params.iter().find(|param| param.span == span) else {
return;
};
- let param_def_id = self.tcx.hir().local_def_id(param.hir_id);
// Check that none of the explicit trait bounds is `Sized`. Assume that an explicit
// `Sized` bound is there intentionally and we don't need to suggest relaxing it.
let explicitly_sized = generics
- .bounds_for_param(param_def_id)
+ .bounds_for_param(param.def_id)
.flat_map(|bp| bp.bounds)
.any(|bound| bound.trait_ref().and_then(|tr| tr.trait_def_id()) == sized_trait);
if explicitly_sized {
_ => {}
};
// Didn't add an indirection suggestion, so add a general suggestion to relax `Sized`.
- let (span, separator) = if let Some(s) = generics.bounds_span_for_suggestions(param_def_id)
+ let (span, separator) = if let Some(s) = generics.bounds_span_for_suggestions(param.def_id)
{
(s, " +")
} else {