Remove Ty::is_region_ptr

This commit is contained in:
Mu42 2023-03-20 15:32:21 +08:00
parent da7c50c089
commit 20dc532085
8 changed files with 12 additions and 24 deletions

View File

@ -120,9 +120,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
&& !self.upvars.is_empty() && !self.upvars.is_empty()
{ {
item_msg = access_place_desc; item_msg = access_place_desc;
debug_assert!( debug_assert!(self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_ref());
self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_region_ptr()
);
debug_assert!(is_closure_or_generator( debug_assert!(is_closure_or_generator(
Place::ty_from( Place::ty_from(
the_place_err.local, the_place_err.local,
@ -470,11 +468,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
{ {
let local_decl = &self.body.local_decls[local]; let local_decl = &self.body.local_decls[local];
let (pointer_sigil, pointer_desc) = if local_decl.ty.is_region_ptr() { let (pointer_sigil, pointer_desc) =
("&", "reference") if local_decl.ty.is_ref() { ("&", "reference") } else { ("*const", "pointer") };
} else {
("*const", "pointer")
};
match self.local_names[local] { match self.local_names[local] {
Some(name) if !local_decl.from_compiler_desugaring() => { Some(name) if !local_decl.from_compiler_desugaring() => {
@ -1258,7 +1253,7 @@ fn suggest_ampmut<'tcx>(
( (
suggestability, suggestability,
highlight_span, highlight_span,
if local_decl.ty.is_region_ptr() { if local_decl.ty.is_ref() {
format!("&mut {}", ty_mut.ty) format!("&mut {}", ty_mut.ty)
} else { } else {
format!("*mut {}", ty_mut.ty) format!("*mut {}", ty_mut.ty)

View File

@ -48,9 +48,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
) -> (Pointer, Value) { ) -> (Pointer, Value) {
let (ptr, vtable) = 'block: { let (ptr, vtable) = 'block: {
if let Abi::Scalar(_) = arg.layout().abi { if let Abi::Scalar(_) = arg.layout().abi {
'descend_newtypes: while !arg.layout().ty.is_unsafe_ptr() 'descend_newtypes: while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() {
&& !arg.layout().ty.is_region_ptr()
{
for i in 0..arg.layout().fields.count() { for i in 0..arg.layout().fields.count() {
let field = arg.value_field(fx, mir::Field::new(i)); let field = arg.value_field(fx, mir::Field::new(i));
if !field.layout().is_zst() { if !field.layout().is_zst() {

View File

@ -917,7 +917,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// //
// This is also relevant for `Pin<&mut Self>`, where we need to peel the `Pin`. // This is also relevant for `Pin<&mut Self>`, where we need to peel the `Pin`.
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr() 'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
&& !op.layout.ty.is_region_ptr() && !op.layout.ty.is_ref()
{ {
for i in 0..op.layout.fields.count() { for i in 0..op.layout.fields.count() {
let field = op.extract_field(bx, i); let field = op.extract_field(bx, i);
@ -959,7 +959,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
Immediate(_) => { Immediate(_) => {
// See comment above explaining why we peel these newtypes // See comment above explaining why we peel these newtypes
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr() 'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
&& !op.layout.ty.is_region_ptr() && !op.layout.ty.is_ref()
{ {
for i in 0..op.layout.fields.count() { for i in 0..op.layout.fields.count() {
let field = op.extract_field(bx, i); let field = op.extract_field(bx, i);

View File

@ -1487,7 +1487,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
let deref_kind = if checked_ty.is_box() { let deref_kind = if checked_ty.is_box() {
"unboxing the value" "unboxing the value"
} else if checked_ty.is_region_ptr() { } else if checked_ty.is_ref() {
"dereferencing the borrow" "dereferencing the borrow"
} else { } else {
"dereferencing the type" "dereferencing the type"

View File

@ -1182,7 +1182,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.inputs() .inputs()
.skip_binder() .skip_binder()
.get(0) .get(0)
.filter(|ty| ty.is_region_ptr() && !rcvr_ty.is_region_ptr()) .filter(|ty| ty.is_ref() && !rcvr_ty.is_ref())
.copied() .copied()
.unwrap_or(rcvr_ty), .unwrap_or(rcvr_ty),
}; };

View File

@ -1913,11 +1913,6 @@ impl<'tcx> Ty<'tcx> {
} }
} }
#[inline]
pub fn is_region_ptr(self) -> bool {
matches!(self.kind(), Ref(..))
}
#[inline] #[inline]
pub fn is_mutable_ptr(self) -> bool { pub fn is_mutable_ptr(self) -> bool {
matches!( matches!(
@ -1944,7 +1939,7 @@ impl<'tcx> Ty<'tcx> {
/// Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer). /// Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer).
#[inline] #[inline]
pub fn is_any_ptr(self) -> bool { pub fn is_any_ptr(self) -> bool {
self.is_region_ptr() || self.is_unsafe_ptr() || self.is_fn_ptr() self.is_ref() || self.is_unsafe_ptr() || self.is_fn_ptr()
} }
#[inline] #[inline]

View File

@ -185,7 +185,7 @@ impl<'tcx> Cx<'tcx> {
if self.typeck_results().is_coercion_cast(source.hir_id) { if self.typeck_results().is_coercion_cast(source.hir_id) {
// Convert the lexpr to a vexpr. // Convert the lexpr to a vexpr.
ExprKind::Use { source: self.mirror_expr(source) } ExprKind::Use { source: self.mirror_expr(source) }
} else if self.typeck_results().expr_ty(source).is_region_ptr() { } else if self.typeck_results().expr_ty(source).is_ref() {
// Special cased so that we can type check that the element // Special cased so that we can type check that the element
// type of the source matches the pointed to type of the // type of the source matches the pointed to type of the
// destination. // destination.

View File

@ -539,7 +539,7 @@ fn make_thin_self_ptr<'tcx>(
// get a built-in pointer type // get a built-in pointer type
let mut fat_pointer_layout = layout; let mut fat_pointer_layout = layout;
'descend_newtypes: while !fat_pointer_layout.ty.is_unsafe_ptr() 'descend_newtypes: while !fat_pointer_layout.ty.is_unsafe_ptr()
&& !fat_pointer_layout.ty.is_region_ptr() && !fat_pointer_layout.ty.is_ref()
{ {
for i in 0..fat_pointer_layout.fields.count() { for i in 0..fat_pointer_layout.fields.count() {
let field_layout = fat_pointer_layout.field(cx, i); let field_layout = fat_pointer_layout.field(cx, i);