1
Fork 0

Remove ty::ClosureKind::from_def_id

…in favour of `TyCtxt::fn_trait_kind_from_def_id`
This commit is contained in:
Maybe Waffle 2022-11-22 18:24:50 +00:00
parent 881862ecb7
commit d0c7ed3bea
4 changed files with 12 additions and 20 deletions

View file

@ -357,7 +357,8 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
ocx.register_obligation(obligation);
if ocx.select_all_or_error().is_empty() {
return Ok((
ty::ClosureKind::from_def_id(self.tcx, trait_def_id)
self.tcx
.fn_trait_kind_from_def_id(trait_def_id)
.expect("expected to map DefId to ClosureKind"),
ty.rebind(self.resolve_vars_if_possible(var)),
));
@ -686,7 +687,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
ObligationCauseCode::BindingObligation(def_id, _)
| ObligationCauseCode::ItemObligation(def_id)
if ty::ClosureKind::from_def_id(tcx, *def_id).is_some() =>
if tcx.fn_trait_kind_from_def_id(*def_id).is_some() =>
{
err.code(rustc_errors::error_code!(E0059));
err.set_primary_message(format!(
@ -847,7 +848,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
let is_fn_trait =
ty::ClosureKind::from_def_id(tcx, trait_ref.def_id()).is_some();
tcx.fn_trait_kind_from_def_id(trait_ref.def_id()).is_some();
let is_target_feature_fn = if let ty::FnDef(def_id, _) =
*trait_ref.skip_binder().self_ty().kind()
{
@ -877,7 +878,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// Note if the `FnMut` or `FnOnce` is less general than the trait we're trying
// to implement.
let selected_kind =
ty::ClosureKind::from_def_id(self.tcx, trait_ref.def_id())
self.tcx.fn_trait_kind_from_def_id(trait_ref.def_id())
.expect("expected to map DefId to ClosureKind");
if !implemented_kind.extends(selected_kind) {
err.note(

View file

@ -1752,7 +1752,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
&& let predicates = self.tcx.predicates_of(def_id).instantiate_identity(self.tcx)
&& let Some(pred) = predicates.predicates.get(*idx)
&& let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = pred.kind().skip_binder()
&& ty::ClosureKind::from_def_id(self.tcx, trait_pred.def_id()).is_some()
&& self.tcx.fn_trait_kind_from_def_id(trait_pred.def_id()).is_some()
{
let expected_self =
self.tcx.anonymize_late_bound_regions(pred.kind().rebind(trait_pred.self_ty()));
@ -1766,7 +1766,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.enumerate()
.find(|(other_idx, (pred, _))| match pred.kind().skip_binder() {
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred))
if ty::ClosureKind::from_def_id(self.tcx, trait_pred.def_id())
if self.tcx.fn_trait_kind_from_def_id(trait_pred.def_id())
.is_some()
&& other_idx != idx
// Make sure that the self type matches