1
Fork 0

ty::Expr reviews

This commit is contained in:
Boxy 2024-06-04 18:50:14 +01:00
parent 56092a345b
commit 7fa98d0c01
3 changed files with 11 additions and 7 deletions

View file

@ -104,10 +104,12 @@ impl<'tcx> Expr<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
func_ty: Ty<'tcx>, func_ty: Ty<'tcx>,
func_expr: Const<'tcx>, func_expr: Const<'tcx>,
arguments: impl Iterator<Item = Const<'tcx>>, arguments: impl IntoIterator<Item = Const<'tcx>>,
) -> Self { ) -> Self {
let args = tcx.mk_args_from_iter::<_, ty::GenericArg<'tcx>>( let args = tcx.mk_args_from_iter::<_, ty::GenericArg<'tcx>>(
[func_ty.into(), func_expr.into()].into_iter().chain(arguments.map(|ct| ct.into())), [func_ty.into(), func_expr.into()]
.into_iter()
.chain(arguments.into_iter().map(|ct| ct.into())),
); );
Self { kind: ExprKind::FunctionCall, args } Self { kind: ExprKind::FunctionCall, args }
@ -155,7 +157,7 @@ impl<'tcx> Expr<'tcx> {
Self { kind, args } Self { kind, args }
} }
pub fn args(&self) -> ty::GenericArgsRef<'tcx> { pub fn args(self) -> ty::GenericArgsRef<'tcx> {
self.args self.args
} }
} }

View file

@ -652,9 +652,11 @@ pub fn structurally_relate_consts<'tcx, R: TypeRelation<'tcx>>(
// and is the better alternative to waiting until `generic_const_exprs` can // and is the better alternative to waiting until `generic_const_exprs` can
// be stabilized. // be stabilized.
(ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) if au.def == bu.def => { (ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) if au.def == bu.def => {
let a_ty = tcx.type_of(au.def).instantiate(tcx, au.args); if cfg!(debug_assertions) {
let b_ty = tcx.type_of(bu.def).instantiate(tcx, bu.args); let a_ty = tcx.type_of(au.def).instantiate(tcx, au.args);
assert_eq!(a_ty, b_ty); let b_ty = tcx.type_of(bu.def).instantiate(tcx, bu.args);
assert_eq!(a_ty, b_ty);
}
let args = relation.relate_with_variance( let args = relation.relate_with_variance(
ty::Variance::Invariant, ty::Variance::Invariant,

View file

@ -149,7 +149,7 @@ fn recurse_build<'tcx>(
for &id in args.iter() { for &id in args.iter() {
new_args.push(recurse_build(tcx, body, id, root_span)?); new_args.push(recurse_build(tcx, body, id, root_span)?);
} }
ty::Const::new_expr(tcx, Expr::new_call(tcx, fun_ty, fun, new_args.into_iter())) ty::Const::new_expr(tcx, Expr::new_call(tcx, fun_ty, fun, new_args))
} }
&ExprKind::Binary { op, lhs, rhs } if check_binop(op) => { &ExprKind::Binary { op, lhs, rhs } if check_binop(op) => {
let lhs_ty = body.exprs[lhs].ty; let lhs_ty = body.exprs[lhs].ty;