1
Fork 0

Simplify calls to tcx.mk_const

`mk_const(ty::ConstKind::X(...), ty)` can now be simplified to
`mk_cosnt(...,                   ty)`.

I searched with the following regex: \mk_const\([\n\s]*(ty::)?ConstKind\
I've left `ty::ConstKind::{Bound, Error}` as-is, they seem clearer this
way.
This commit is contained in:
Maybe Waffle 2022-11-28 12:28:32 +00:00
parent 7087d9b2a0
commit 26b87bf8ff
10 changed files with 27 additions and 46 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

@ -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),
}
@ -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

@ -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

@ -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()