Skip to content

Commit b44eb11

Browse files
committed
Move ParamTerm out of rustc_middle.
It's only used in `rustc_hir_typeck`.
1 parent 3a1f2d5 commit b44eb11

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ enum ClauseFlavor {
1717
Const,
1818
}
1919

20+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
21+
enum ParamTerm {
22+
Ty(ty::ParamTy),
23+
Const(ty::ParamConst),
24+
}
25+
26+
impl ParamTerm {
27+
fn index(self) -> usize {
28+
match self {
29+
ParamTerm::Ty(ty) => ty.index as usize,
30+
ParamTerm::Const(ct) => ct.index as usize,
31+
}
32+
}
33+
}
34+
2035
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2136
pub(crate) fn adjust_fulfillment_error_for_expr_obligation(
2237
&self,
@@ -77,17 +92,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7792
_ => return false,
7893
};
7994

80-
let find_param_matching = |matches: &dyn Fn(ty::ParamTerm) -> bool| {
95+
let find_param_matching = |matches: &dyn Fn(ParamTerm) -> bool| {
8196
predicate_args.iter().find_map(|arg| {
8297
arg.walk().find_map(|arg| {
8398
if let ty::GenericArgKind::Type(ty) = arg.kind()
8499
&& let ty::Param(param_ty) = *ty.kind()
85-
&& matches(ty::ParamTerm::Ty(param_ty))
100+
&& matches(ParamTerm::Ty(param_ty))
86101
{
87102
Some(arg)
88103
} else if let ty::GenericArgKind::Const(ct) = arg.kind()
89104
&& let ty::ConstKind::Param(param_ct) = ct.kind()
90-
&& matches(ty::ParamTerm::Const(param_ct))
105+
&& matches(ParamTerm::Const(param_ct))
91106
{
92107
Some(arg)
93108
} else {
@@ -106,14 +121,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
106121
// from a trait or impl, for example.
107122
let mut fallback_param_to_point_at = find_param_matching(&|param_term| {
108123
self.tcx.parent(generics.param_at(param_term.index(), self.tcx).def_id) != def_id
109-
&& !matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper)
124+
&& !matches!(param_term, ParamTerm::Ty(ty) if ty.name == kw::SelfUpper)
110125
});
111126
// Finally, the `Self` parameter is possibly the reason that the predicate
112127
// is unsatisfied. This is less likely to be true for methods, because
113128
// method probe means that we already kinda check that the predicates due
114129
// to the `Self` type are true.
115130
let mut self_param_to_point_at = find_param_matching(
116-
&|param_term| matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper),
131+
&|param_term| matches!(param_term, ParamTerm::Ty(ty) if ty.name == kw::SelfUpper),
117132
);
118133

119134
// Finally, for ambiguity-related errors, we actually want to look

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -673,21 +673,6 @@ impl<'tcx> TermKind<'tcx> {
673673
}
674674
}
675675

676-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
677-
pub enum ParamTerm {
678-
Ty(ParamTy),
679-
Const(ParamConst),
680-
}
681-
682-
impl ParamTerm {
683-
pub fn index(self) -> usize {
684-
match self {
685-
ParamTerm::Ty(ty) => ty.index as usize,
686-
ParamTerm::Const(ct) => ct.index as usize,
687-
}
688-
}
689-
}
690-
691676
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
692677
pub enum TermVid {
693678
Ty(ty::TyVid),

0 commit comments

Comments
 (0)