Auto merge of #105012 - WaffleLapkin:into, r=oli-obk

Make `tcx.mk_const` more permissive wrt `kind` argument (`impl Into`)

r? `@oli-obk` you've asked for this >:)
This commit is contained in:
bors 2022-11-29 13:28:44 +00:00
commit e0098a5cc3
20 changed files with 86 additions and 98 deletions

View file

@ -147,7 +147,7 @@ impl<'tcx> InferCtxt<'tcx> {
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }, ty) => {
let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name };
self.tcx.mk_const(ty::ConstKind::Placeholder(placeholder_mapped), ty).into()
self.tcx.mk_const(placeholder_mapped, ty).into()
}
}
}

View file

@ -753,7 +753,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
origin: var_value.origin,
val: ConstVariableValue::Unknown { universe: self.for_universe },
});
Ok(self.tcx().mk_const_var(new_var_id, c.ty()))
Ok(self.tcx().mk_const(new_var_id, c.ty()))
}
}
}
@ -765,10 +765,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
substs,
substs,
)?;
Ok(self.tcx().mk_const(
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
c.ty(),
))
Ok(self.tcx().mk_const(ty::UnevaluatedConst { def, substs }, c.ty()))
}
_ => relate::super_relate_consts(self, c, c),
}
@ -975,7 +972,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
},
},
);
Ok(self.tcx().mk_const_var(new_var_id, c.ty()))
Ok(self.tcx().mk_const(new_var_id, c.ty()))
}
}
}
@ -988,10 +985,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
substs,
)?;
Ok(self.tcx().mk_const(
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
c.ty(),
))
Ok(self.tcx().mk_const(ty::UnevaluatedConst { def, substs }, c.ty()))
}
_ => relate::super_relate_consts(self, c, c),
}

View file

@ -102,7 +102,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
Entry::Vacant(entry) => {
let index = self.const_freshen_count;
self.const_freshen_count += 1;
let ct = self.infcx.tcx.mk_const_infer(freshener(index), ty);
let ct = self.infcx.tcx.mk_const(freshener(index), ty);
entry.insert(ct);
ct
}

View file

@ -94,13 +94,8 @@ impl<'tcx> InferCtxt<'tcx> {
}))
},
consts: &mut |bound_var: ty::BoundVar, ty| {
self.tcx.mk_const(
ty::ConstKind::Placeholder(ty::PlaceholderConst {
universe: next_universe,
name: bound_var,
}),
ty,
)
self.tcx
.mk_const(ty::PlaceholderConst { universe: next_universe, name: bound_var }, ty)
},
};

View file

@ -1065,7 +1065,7 @@ impl<'tcx> InferCtxt<'tcx> {
}
pub fn next_const_var(&self, ty: Ty<'tcx>, origin: ConstVariableOrigin) -> ty::Const<'tcx> {
self.tcx.mk_const_var(self.next_const_var_id(origin), ty)
self.tcx.mk_const(self.next_const_var_id(origin), ty)
}
pub fn next_const_var_in_universe(
@ -1079,7 +1079,7 @@ impl<'tcx> InferCtxt<'tcx> {
.borrow_mut()
.const_unification_table()
.new_key(ConstVarValue { origin, val: ConstVariableValue::Unknown { universe } });
self.tcx.mk_const_var(vid, ty)
self.tcx.mk_const(vid, ty)
}
pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid<'tcx> {
@ -1195,7 +1195,7 @@ impl<'tcx> InferCtxt<'tcx> {
origin,
val: ConstVariableValue::Unknown { universe: self.universe() },
});
self.tcx.mk_const_var(const_var_id, self.tcx.type_of(param.def_id)).into()
self.tcx.mk_const(const_var_id, self.tcx.type_of(param.def_id)).into()
}
}
}
@ -1580,7 +1580,7 @@ impl<'tcx> InferCtxt<'tcx> {
span: Option<Span>,
) -> Result<ty::Const<'tcx>, ErrorHandled> {
match self.const_eval_resolve(param_env, unevaluated, span) {
Ok(Some(val)) => Ok(ty::Const::from_value(self.tcx, val, ty)),
Ok(Some(val)) => Ok(self.tcx.mk_const(val, ty)),
Ok(None) => {
let tcx = self.tcx;
let def_id = unevaluated.def.did;
@ -2049,10 +2049,10 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
bug!("const `{ct}`'s type should not reference params or types");
}
tcx.mk_const(
ty::ConstKind::Placeholder(ty::PlaceholderConst {
ty::PlaceholderConst {
universe: ty::UniverseIndex::ROOT,
name: ty::BoundVar::from_usize(idx),
}),
},
ty,
)
.into()

View file

@ -1087,7 +1087,7 @@ where
origin: var_value.origin,
val: ConstVariableValue::Unknown { universe: self.universe },
});
Ok(self.tcx().mk_const_var(new_var_id, a.ty()))
Ok(self.tcx().mk_const(new_var_id, a.ty()))
}
}
}