Make builtin_deref just return a Ty
This commit is contained in:
parent
8c7c151a7a
commit
d50c2b0a52
43 changed files with 92 additions and 116 deletions
|
@ -106,7 +106,7 @@ impl<'tcx, 'a> Visitor<'tcx> for PointerFinder<'tcx, 'a> {
|
|||
}
|
||||
|
||||
let pointee_ty =
|
||||
pointer_ty.builtin_deref(true).expect("no builtin_deref for an unsafe pointer").ty;
|
||||
pointer_ty.builtin_deref(true).expect("no builtin_deref for an unsafe pointer");
|
||||
// Ideally we'd support this in the future, but for now we are limited to sized types.
|
||||
if !pointee_ty.is_sized(self.tcx, self.param_env) {
|
||||
debug!("Unsafe pointer, but pointee is not known to be sized: {:?}", pointer_ty);
|
||||
|
|
|
@ -202,7 +202,7 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
|
|||
if let Some(target_len) = self.map().find_len(target.as_ref())
|
||||
&& let operand_ty = operand.ty(self.local_decls, self.tcx)
|
||||
&& let Some(operand_ty) = operand_ty.builtin_deref(true)
|
||||
&& let ty::Array(_, len) = operand_ty.ty.kind()
|
||||
&& let ty::Array(_, len) = operand_ty.kind()
|
||||
&& let Some(len) = Const::Ty(*len).try_eval_scalar_int(self.tcx, self.param_env)
|
||||
{
|
||||
state.insert_value_idx(target_len, FlatSet::Elem(len.into()), self.map());
|
||||
|
|
|
@ -594,7 +594,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
let ty = place.ty(self.local_decls, self.tcx).ty;
|
||||
if let Some(Mutability::Not) = ty.ref_mutability()
|
||||
&& let Some(pointee_ty) = ty.builtin_deref(true)
|
||||
&& pointee_ty.ty.is_freeze(self.tcx, self.param_env)
|
||||
&& pointee_ty.is_freeze(self.tcx, self.param_env)
|
||||
{
|
||||
// An immutable borrow `_x` always points to the same value for the
|
||||
// lifetime of the borrow, so we can merge all instances of `*_x`.
|
||||
|
@ -1133,9 +1133,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
if let Value::Cast { kind, from, to, .. } = self.get(inner)
|
||||
&& let CastKind::PointerCoercion(ty::adjustment::PointerCoercion::Unsize) = kind
|
||||
&& let Some(from) = from.builtin_deref(true)
|
||||
&& let ty::Array(_, len) = from.ty.kind()
|
||||
&& let ty::Array(_, len) = from.kind()
|
||||
&& let Some(to) = to.builtin_deref(true)
|
||||
&& let ty::Slice(..) = to.ty.kind()
|
||||
&& let ty::Slice(..) = to.kind()
|
||||
{
|
||||
return self.insert_constant(Const::from_ty_const(*len, self.tcx));
|
||||
}
|
||||
|
|
|
@ -79,8 +79,8 @@ impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> {
|
|||
// add everything that may involve a vtable.
|
||||
let source_ty = operand.ty(self.body, self.tcx);
|
||||
let may_involve_vtable = match (
|
||||
source_ty.builtin_deref(true).map(|t| t.ty.kind()),
|
||||
target_ty.builtin_deref(true).map(|t| t.ty.kind()),
|
||||
source_ty.builtin_deref(true).map(|t| t.kind()),
|
||||
target_ty.builtin_deref(true).map(|t| t.kind()),
|
||||
) {
|
||||
(Some(ty::Array(..)), Some(ty::Str | ty::Slice(..))) => false, // &str/&[T] unsizing
|
||||
_ => true,
|
||||
|
|
|
@ -48,9 +48,9 @@ fn compute_slice_length<'tcx>(
|
|||
let operand_ty = operand.ty(body, tcx);
|
||||
debug!(?operand_ty);
|
||||
if let Some(operand_ty) = operand_ty.builtin_deref(true)
|
||||
&& let ty::Array(_, len) = operand_ty.ty.kind()
|
||||
&& let ty::Array(_, len) = operand_ty.kind()
|
||||
&& let Some(cast_ty) = cast_ty.builtin_deref(true)
|
||||
&& let ty::Slice(..) = cast_ty.ty.kind()
|
||||
&& let ty::Slice(..) = cast_ty.kind()
|
||||
{
|
||||
slice_lengths[local] = Some(*len);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue