diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 4e4bf8a5562..ed88e32a273 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -17,6 +17,21 @@ enum ClauseFlavor { Const, } +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +enum ParamTerm { + Ty(ty::ParamTy), + Const(ty::ParamConst), +} + +impl ParamTerm { + fn index(self) -> usize { + match self { + ParamTerm::Ty(ty) => ty.index as usize, + ParamTerm::Const(ct) => ct.index as usize, + } + } +} + impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn adjust_fulfillment_error_for_expr_obligation( &self, @@ -77,17 +92,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => return false, }; - let find_param_matching = |matches: &dyn Fn(ty::ParamTerm) -> bool| { + let find_param_matching = |matches: &dyn Fn(ParamTerm) -> bool| { predicate_args.iter().find_map(|arg| { arg.walk().find_map(|arg| { if let ty::GenericArgKind::Type(ty) = arg.kind() && let ty::Param(param_ty) = *ty.kind() - && matches(ty::ParamTerm::Ty(param_ty)) + && matches(ParamTerm::Ty(param_ty)) { Some(arg) } else if let ty::GenericArgKind::Const(ct) = arg.kind() && let ty::ConstKind::Param(param_ct) = ct.kind() - && matches(ty::ParamTerm::Const(param_ct)) + && matches(ParamTerm::Const(param_ct)) { Some(arg) } else { @@ -106,14 +121,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // from a trait or impl, for example. let mut fallback_param_to_point_at = find_param_matching(&|param_term| { self.tcx.parent(generics.param_at(param_term.index(), self.tcx).def_id) != def_id - && !matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper) + && !matches!(param_term, ParamTerm::Ty(ty) if ty.name == kw::SelfUpper) }); // Finally, the `Self` parameter is possibly the reason that the predicate // is unsatisfied. This is less likely to be true for methods, because // method probe means that we already kinda check that the predicates due // to the `Self` type are true. let mut self_param_to_point_at = find_param_matching( - &|param_term| matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper), + &|param_term| matches!(param_term, ParamTerm::Ty(ty) if ty.name == kw::SelfUpper), ); // Finally, for ambiguity-related errors, we actually want to look diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 67828185485..1e70d63539d 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -673,21 +673,6 @@ impl<'tcx> TermKind<'tcx> { } } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub enum ParamTerm { - Ty(ParamTy), - Const(ParamConst), -} - -impl ParamTerm { - pub fn index(self) -> usize { - match self { - ParamTerm::Ty(ty) => ty.index as usize, - ParamTerm::Const(ct) => ct.index as usize, - } - } -} - #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum TermVid { Ty(ty::TyVid),