This commit is contained in:
Boxy 2022-11-21 04:32:07 +00:00 committed by kadmin
parent f59b91e8a0
commit 4833ce8673
5 changed files with 8 additions and 7 deletions

View file

@ -35,7 +35,7 @@ TrivialTypeTraversalAndLiftImpls! {
pub type BoundAbstractConst<'tcx> = Result<Option<EarlyBinder<ty::Const<'tcx>>>, ErrorGuaranteed>;
impl<'tcx> TyCtxt<'tcx> {
/// Returns a const with substs applied by
/// Returns a const without substs applied
fn bound_abstract_const(self, uv: ty::WithOptConstParam<DefId>) -> BoundAbstractConst<'tcx> {
let ac = if let Some((did, param_did)) = uv.as_const_arg() {
self.thir_abstract_const_of_const_arg((did, param_did))

View file

@ -647,7 +647,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
(ty::ConstKind::Placeholder(p1), ty::ConstKind::Placeholder(p2)) => p1 == p2,
(ty::ConstKind::Value(a_val), ty::ConstKind::Value(b_val)) => a_val == b_val,
(ty::ConstKind::Unevaluated(_au), ty::ConstKind::Unevaluated(_bu))
(ty::ConstKind::Unevaluated(_), ty::ConstKind::Unevaluated(_))
if tcx.features().generic_const_exprs =>
{
if let (Ok(Some(a)), Ok(Some(b))) = (
@ -681,7 +681,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
(ty::ConstKind::Expr(ae), ty::ConstKind::Expr(be)) => {
let r = relation;
// FIXME(julianknodt): is it possible to relate two consts which are not identical
// FIXME(generic_const_exprs): is it possible to relate two consts which are not identical
// exprs? Should we care about that?
let expr = match (ae, be) {
(Expr::Binop(a_op, al, ar), Expr::Binop(b_op, bl, br))

View file

@ -286,8 +286,9 @@ where
fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow<Self::BreakTy> {
self.visit_ty(c.ty())?;
let tcx = self.def_id_visitor.tcx();
if let ty::ConstKind::Unevaluated(uv) = c.kind() &&
let Ok(Some(ct)) = tcx.expand_unevaluated_abstract_const(uv.def, uv.substs) {
if let ty::ConstKind::Unevaluated(uv) = c.kind()
&& let Ok(Some(ct)) = tcx.expand_unevaluated_abstract_const(uv.def, uv.substs)
{
ct.super_visit_with(self)?;
}
ControlFlow::CONTINUE

View file

@ -78,7 +78,7 @@ pub fn is_const_evaluatable<'tcx>(
// compilation with a useful error.
Err(_) if tcx.sess.is_nightly_build()
&& let Ok(Some(ac)) = tcx.expand_abstract_consts(ct)
&& let ty::ConstKind::Expr(_) = ac.kind() =>
&& let ty::ConstKind::Expr(_) = ac.kind() =>
{
tcx.sess
.struct_span_fatal(

View file

@ -15,7 +15,7 @@ fn foo<T: Foo>(_: [u8; T::N]) -> T {
pub fn bar() {
let _: u8 = foo([0; 1]);
let _ = foo([0; 1]);
//~^ ERROR type annotations needed
}