Skip to content

Commit 7be0dbe

Browse files
Make RawPtr take Ty and Mutbl separately
1 parent ff0c31e commit 7be0dbe

File tree

36 files changed

+112
-113
lines changed

36 files changed

+112
-113
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
503503
ty::VarianceDiagInfo::None => {}
504504
ty::VarianceDiagInfo::Invariant { ty, param_index } => {
505505
let (desc, note) = match ty.kind() {
506-
ty::RawPtr(ty_mut) => {
507-
assert_eq!(ty_mut.mutbl, rustc_hir::Mutability::Mut);
506+
ty::RawPtr(ty, mutbl) => {
507+
assert_eq!(*mutbl, rustc_hir::Mutability::Mut);
508508
(
509-
format!("a mutable pointer to `{}`", ty_mut.ty),
509+
format!("a mutable pointer to `{}`", ty),
510510
"mutable pointers are invariant over their type parameter".to_string(),
511511
)
512512
}

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
555555
search_stack.push((*elem_ty, elem_hir_ty));
556556
}
557557

558-
(ty::RawPtr(mut_ty), hir::TyKind::Ptr(mut_hir_ty)) => {
559-
search_stack.push((mut_ty.ty, &mut_hir_ty.ty));
558+
(ty::RawPtr(mut_ty, _), hir::TyKind::Ptr(mut_hir_ty)) => {
559+
search_stack.push((*mut_ty, &mut_hir_ty.ty));
560560
}
561561

562562
_ => {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,8 +2284,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22842284
}
22852285
}
22862286
}
2287-
ty::RawPtr(tnm) => {
2288-
match tnm.mutbl {
2287+
ty::RawPtr(_, mutbl) => {
2288+
match mutbl {
22892289
// `*const` raw pointers are not mutable
22902290
hir::Mutability::Not => Err(place),
22912291
// `*mut` raw pointers are always mutable, regardless of

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,15 +2157,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21572157
}
21582158

21592159
CastKind::PointerCoercion(PointerCoercion::MutToConstPointer) => {
2160-
let ty::RawPtr(ty::TypeAndMut { ty: ty_from, mutbl: hir::Mutability::Mut }) =
2161-
op.ty(body, tcx).kind()
2160+
let ty::RawPtr(ty_from, hir::Mutability::Mut) = op.ty(body, tcx).kind()
21622161
else {
21632162
span_mirbug!(self, rvalue, "unexpected base type for cast {:?}", ty,);
21642163
return;
21652164
};
2166-
let ty::RawPtr(ty::TypeAndMut { ty: ty_to, mutbl: hir::Mutability::Not }) =
2167-
ty.kind()
2168-
else {
2165+
let ty::RawPtr(ty_to, hir::Mutability::Not) = ty.kind() else {
21692166
span_mirbug!(self, rvalue, "unexpected target type for cast {:?}", ty,);
21702167
return;
21712168
};

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -796,16 +796,16 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
796796

797797
// This counts how many pointers
798798
fn ptr_count(t: Ty<'_>) -> usize {
799-
match t.kind() {
800-
ty::RawPtr(p) => 1 + ptr_count(p.ty),
799+
match *t.kind() {
800+
ty::RawPtr(p_ty, _) => 1 + ptr_count(p_ty),
801801
_ => 0,
802802
}
803803
}
804804

805805
// Non-ptr type
806806
fn non_ptr(t: Ty<'_>) -> Ty<'_> {
807-
match t.kind() {
808-
ty::RawPtr(p) => non_ptr(p.ty),
807+
match *t.kind() {
808+
ty::RawPtr(p_ty, _) => non_ptr(p_ty),
809809
_ => t,
810810
}
811811
}
@@ -814,8 +814,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
814814
// to the element type of the first argument
815815
let (_, element_ty0) = arg_tys[0].simd_size_and_type(bx.tcx());
816816
let (_, element_ty1) = arg_tys[1].simd_size_and_type(bx.tcx());
817-
let (pointer_count, underlying_ty) = match element_ty1.kind() {
818-
ty::RawPtr(p) if p.ty == in_elem => (ptr_count(element_ty1), non_ptr(element_ty1)),
817+
let (pointer_count, underlying_ty) = match *element_ty1.kind() {
818+
ty::RawPtr(p_ty, _) if p_ty == in_elem => (ptr_count(element_ty1), non_ptr(element_ty1)),
819819
_ => {
820820
require!(
821821
false,
@@ -910,16 +910,16 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
910910

911911
// This counts how many pointers
912912
fn ptr_count(t: Ty<'_>) -> usize {
913-
match t.kind() {
914-
ty::RawPtr(p) => 1 + ptr_count(p.ty),
913+
match *t.kind() {
914+
ty::RawPtr(p_ty, _) => 1 + ptr_count(p_ty),
915915
_ => 0,
916916
}
917917
}
918918

919919
// Non-ptr type
920920
fn non_ptr(t: Ty<'_>) -> Ty<'_> {
921-
match t.kind() {
922-
ty::RawPtr(p) => non_ptr(p.ty),
921+
match *t.kind() {
922+
ty::RawPtr(p_ty, _) => non_ptr(p_ty),
923923
_ => t,
924924
}
925925
}
@@ -929,8 +929,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
929929
let (_, element_ty0) = arg_tys[0].simd_size_and_type(bx.tcx());
930930
let (_, element_ty1) = arg_tys[1].simd_size_and_type(bx.tcx());
931931
let (_, element_ty2) = arg_tys[2].simd_size_and_type(bx.tcx());
932-
let (pointer_count, underlying_ty) = match element_ty1.kind() {
933-
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mut => {
932+
let (pointer_count, underlying_ty) = match *element_ty1.kind() {
933+
ty::RawPtr(p_ty, mutbl) if p_ty == in_elem && mutbl == hir::Mutability::Mut => {
934934
(ptr_count(element_ty1), non_ptr(element_ty1))
935935
}
936936
_ => {

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,8 +1548,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15481548

15491549
require!(
15501550
matches!(
1551-
element_ty1.kind(),
1552-
ty::RawPtr(p) if p.ty == in_elem && p.ty.kind() == element_ty0.kind()
1551+
*element_ty1.kind(),
1552+
ty::RawPtr(p_ty, _) if p_ty == in_elem && p_ty.kind() == element_ty0.kind()
15531553
),
15541554
InvalidMonomorphization::ExpectedElementType {
15551555
span,
@@ -1654,8 +1654,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
16541654

16551655
require!(
16561656
matches!(
1657-
pointer_ty.kind(),
1658-
ty::RawPtr(p) if p.ty == values_elem && p.ty.kind() == values_elem.kind()
1657+
*pointer_ty.kind(),
1658+
ty::RawPtr(p_ty, _) if p_ty == values_elem && p_ty.kind() == values_elem.kind()
16591659
),
16601660
InvalidMonomorphization::ExpectedElementType {
16611661
span,
@@ -1746,8 +1746,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
17461746
// The second argument must be a mutable pointer type matching the element type
17471747
require!(
17481748
matches!(
1749-
pointer_ty.kind(),
1750-
ty::RawPtr(p) if p.ty == values_elem && p.ty.kind() == values_elem.kind() && p.mutbl.is_mut()
1749+
*pointer_ty.kind(),
1750+
ty::RawPtr(p_ty, p_mutbl) if p_ty == values_elem && p_ty.kind() == values_elem.kind() && p_mutbl.is_mut()
17511751
),
17521752
InvalidMonomorphization::ExpectedElementType {
17531753
span,
@@ -1843,9 +1843,9 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
18431843

18441844
require!(
18451845
matches!(
1846-
element_ty1.kind(),
1847-
ty::RawPtr(p)
1848-
if p.ty == in_elem && p.mutbl.is_mut() && p.ty.kind() == element_ty0.kind()
1846+
*element_ty1.kind(),
1847+
ty::RawPtr(p_ty, p_mutbl)
1848+
if p_ty == in_elem && p_mutbl.is_mut() && p_ty.kind() == element_ty0.kind()
18491849
),
18501850
InvalidMonomorphization::ExpectedElementType {
18511851
span,
@@ -2074,8 +2074,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20742074
);
20752075

20762076
match in_elem.kind() {
2077-
ty::RawPtr(p) => {
2078-
let metadata = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
2077+
ty::RawPtr(p_ty, _) => {
2078+
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
20792079
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
20802080
});
20812081
require!(
@@ -2088,8 +2088,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20882088
}
20892089
}
20902090
match out_elem.kind() {
2091-
ty::RawPtr(p) => {
2092-
let metadata = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
2091+
ty::RawPtr(p_ty, _) => {
2092+
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
20932093
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
20942094
});
20952095
require!(

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::mir::interpret::{InterpResult, PointerArithmetic, Scalar};
66
use rustc_middle::mir::CastKind;
77
use rustc_middle::ty::adjustment::PointerCoercion;
88
use rustc_middle::ty::layout::{IntegerExt, LayoutOf, TyAndLayout};
9-
use rustc_middle::ty::{self, FloatTy, Ty, TypeAndMut};
9+
use rustc_middle::ty::{self, FloatTy, Ty};
1010
use rustc_target::abi::Integer;
1111
use rustc_type_ir::TyKind::*;
1212

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
375375
// We cannot use `builtin_deref` here since we need to reject `Box<T, MyAlloc>`.
376376
Ok(Some(match ty.kind() {
377377
ty::Ref(_, ty, _) => *ty,
378-
ty::RawPtr(mt) => mt.ty,
378+
ty::RawPtr(ty, _) => *ty,
379379
// We only accept `Box` with the default allocator.
380380
_ if ty.is_box_global(*self.tcx) => ty.boxed_ty(),
381381
_ => return Ok(None),

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,10 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
937937
ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_, _) => (), // struct(u8, u8, u8, u8) is ok
938938
ty::Array(t, _) if matches!(t.kind(), ty::Param(_)) => (), // pass struct<T>([T; N]) through, let monomorphization catch errors
939939
ty::Array(t, _clen)
940-
if matches!(t.kind(), ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_, _)) =>
940+
if matches!(
941+
t.kind(),
942+
ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_, _)
943+
) =>
941944
{ /* struct([f32; 4]) is ok */ }
942945
_ => {
943946
struct_span_code_err!(

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
195195
{
196196
Ok(())
197197
}
198-
(&RawPtr(tm_a), &RawPtr(tm_b)) if tm_a.mutbl == tm_b.mutbl => Ok(()),
198+
(&RawPtr(_, a_mutbl), &RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()),
199199
(&Adt(def_a, args_a), &Adt(def_b, args_b)) if def_a.is_struct() && def_b.is_struct() => {
200200
if def_a != def_b {
201201
let source_path = tcx.def_path_str(def_a.did());
@@ -351,14 +351,17 @@ pub fn coerce_unsized_info<'tcx>(
351351
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ref(tcx, r_b, ty))
352352
}
353353

354-
(&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(mt_b)) => {
355-
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
356-
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ptr(tcx, ty))
357-
}
358-
359-
(&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => {
360-
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ptr(tcx, ty))
361-
}
354+
(&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b)) => check_mutbl(
355+
ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a },
356+
ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b },
357+
&|ty| Ty::new_imm_ptr(tcx, ty),
358+
),
359+
360+
(&ty::RawPtr(ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b)) => check_mutbl(
361+
ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a },
362+
ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b },
363+
&|ty| Ty::new_imm_ptr(tcx, ty),
364+
),
362365

363366
(&ty::Adt(def_a, args_a), &ty::Adt(def_b, args_b))
364367
if def_a.is_struct() && def_b.is_struct() =>

0 commit comments

Comments
 (0)