Skip to content

Commit 85e449a

Browse files
committed
Auto merge of #122852 - compiler-errors:raw-ptr, r=lcnr
Remove `TypeAndMut` from `ty::RawPtr` variant, make it take `Ty` and `Mutability` Pretty much mechanically converting `ty::RawPtr(ty::TypeAndMut { ty, mutbl })` to `ty::RawPtr(ty, mutbl)` and its fallout. r? lcnr cc rust-lang/types-team#124
2 parents b3df0d7 + 6a40dab commit 85e449a

File tree

126 files changed

+410
-579
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+410
-579
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
366366
Some(variant.fields[field].name.to_string())
367367
}
368368
ty::Tuple(_) => Some(field.index().to_string()),
369-
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
369+
ty::Ref(_, ty, _) | ty::RawPtr(ty, _) => {
370370
self.describe_field_from_ty(ty, field, variant_index, including_tuple_field)
371371
}
372372
ty::Array(ty, _) | ty::Slice(ty) => {

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16491649
| ty::Str
16501650
| ty::Array(_, _)
16511651
| ty::Slice(_)
1652-
| ty::RawPtr(_)
1652+
| ty::RawPtr(_, _)
16531653
| ty::Ref(_, _, _)
16541654
| ty::FnDef(_, _)
16551655
| ty::FnPtr(_)
@@ -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: 8 additions & 15 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
};
@@ -2190,12 +2187,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21902187
let ty_from = op.ty(body, tcx);
21912188

21922189
let opt_ty_elem_mut = match ty_from.kind() {
2193-
ty::RawPtr(ty::TypeAndMut { mutbl: array_mut, ty: array_ty }) => {
2194-
match array_ty.kind() {
2195-
ty::Array(ty_elem, _) => Some((ty_elem, *array_mut)),
2196-
_ => None,
2197-
}
2198-
}
2190+
ty::RawPtr(array_ty, array_mut) => match array_ty.kind() {
2191+
ty::Array(ty_elem, _) => Some((ty_elem, *array_mut)),
2192+
_ => None,
2193+
},
21992194
_ => None,
22002195
};
22012196

@@ -2210,9 +2205,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22102205
};
22112206

22122207
let (ty_to, ty_to_mut) = match ty.kind() {
2213-
ty::RawPtr(ty::TypeAndMut { mutbl: ty_to_mut, ty: ty_to }) => {
2214-
(ty_to, *ty_to_mut)
2215-
}
2208+
ty::RawPtr(ty_to, ty_to_mut) => (ty_to, *ty_to_mut),
22162209
_ => {
22172210
span_mirbug!(
22182211
self,
@@ -2413,7 +2406,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24132406
let ty_left = left.ty(body, tcx);
24142407
match ty_left.kind() {
24152408
// Types with regions are comparable if they have a common super-type.
2416-
ty::RawPtr(_) | ty::FnPtr(_) => {
2409+
ty::RawPtr(_, _) | ty::FnPtr(_) => {
24172410
let ty_right = right.ty(body, tcx);
24182411
let common_ty = self.infcx.next_ty_var(TypeVariableOrigin {
24192412
kind: TypeVariableOriginKind::MiscVariable,

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,7 @@ pub(crate) fn codegen_drop<'tcx>(
677677

678678
let arg_value = drop_place.place_ref(
679679
fx,
680-
fx.layout_of(Ty::new_ref(
681-
fx.tcx,
682-
fx.tcx.lifetimes.re_erased,
683-
TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut },
684-
)),
680+
fx.layout_of(Ty::new_mut_ref(fx.tcx, fx.tcx.lifetimes.re_erased, ty)),
685681
);
686682
let arg_value = adjust_arg_for_abi(fx, arg_value, &fn_abi.args[0], true);
687683

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types::Typ
6969
FloatTy::F128 => unimplemented!("f16_f128"),
7070
},
7171
ty::FnPtr(_) => pointer_ty(tcx),
72-
ty::RawPtr(TypeAndMut { ty: pointee_ty, mutbl: _ }) | ty::Ref(_, pointee_ty, _) => {
72+
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
7373
if has_ptr_meta(tcx, *pointee_ty) {
7474
return None;
7575
} else {
@@ -89,7 +89,7 @@ fn clif_pair_type_from_ty<'tcx>(
8989
ty::Tuple(types) if types.len() == 2 => {
9090
(clif_type_from_ty(tcx, types[0])?, clif_type_from_ty(tcx, types[1])?)
9191
}
92-
ty::RawPtr(TypeAndMut { ty: pointee_ty, mutbl: _ }) | ty::Ref(_, pointee_ty, _) => {
92+
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
9393
if has_ptr_meta(tcx, *pointee_ty) {
9494
(pointer_ty(tcx), pointer_ty(tcx))
9595
} else {

compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ fn unsize_ptr<'tcx>(
7070
) -> (Value, Value) {
7171
match (&src_layout.ty.kind(), &dst_layout.ty.kind()) {
7272
(&ty::Ref(_, a, _), &ty::Ref(_, b, _))
73-
| (&ty::Ref(_, a, _), &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
74-
| (&ty::RawPtr(ty::TypeAndMut { ty: a, .. }), &ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
75-
(src, unsized_info(fx, *a, *b, old_info))
76-
}
73+
| (&ty::Ref(_, a, _), &ty::RawPtr(b, _))
74+
| (&ty::RawPtr(a, _), &ty::RawPtr(b, _)) => (src, unsized_info(fx, *a, *b, old_info)),
7775
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
7876
assert_eq!(def_a, def_b);
7977

compiler/rustc_codegen_cranelift/src/value_and_place.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,10 @@ pub(crate) fn assert_assignable<'tcx>(
865865
return;
866866
}
867867
match (from_ty.kind(), to_ty.kind()) {
868-
(ty::Ref(_, a, _), ty::Ref(_, b, _))
869-
| (
870-
ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }),
871-
ty::RawPtr(TypeAndMut { ty: b, mutbl: _ }),
872-
) => {
868+
(ty::Ref(_, a, _), ty::Ref(_, b, _)) | (ty::RawPtr(a, _), ty::RawPtr(b, _)) => {
873869
assert_assignable(fx, *a, *b, limit - 1);
874870
}
875-
(ty::Ref(_, a, _), ty::RawPtr(TypeAndMut { ty: b, mutbl: _ }))
876-
| (ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }), ty::Ref(_, b, _)) => {
871+
(ty::Ref(_, a, _), ty::RawPtr(b, _)) | (ty::RawPtr(a, _), ty::Ref(_, b, _)) => {
877872
assert_assignable(fx, *a, *b, limit - 1);
878873
}
879874
(ty::FnPtr(_), ty::FnPtr(_)) => {

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
_ => {

0 commit comments

Comments
 (0)