mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 10:18:25 +00:00
Move ParamTerm
out of rustc_middle
.
It's only used in `rustc_hir_typeck`.
This commit is contained in:
parent
3a1f2d5cc2
commit
b44eb11bdf
@ -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
|
||||
|
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user