Skip to content

Commit 24e0b14

Browse files
committed
Implement pin-project in pattern matching for &pin mut|const T
1 parent 49e5e4e commit 24e0b14

File tree

71 files changed

+2085
-125
lines changed

Some content is hidden

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

71 files changed

+2085
-125
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ fn suggest_ampmut<'tcx>(
15881588
} else {
15891589
// otherwise, suggest that the user annotates the binding; we provide the
15901590
// type of the local.
1591-
let ty = decl_ty.builtin_deref(true).unwrap();
1591+
let ty = decl_ty.builtin_deref(true, tcx).unwrap();
15921592

15931593
Some(AmpMutSugg {
15941594
has_sugg: false,

compiler/rustc_borrowck/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
24722472

24732473
// Check the kind of deref to decide
24742474
match base_ty.kind() {
2475-
ty::Ref(_, _, mutbl) => {
2475+
_ if let Some((_, _, _, mutbl)) =
2476+
base_ty.is_ref_or_pin_ref(self.infcx.tcx) =>
2477+
{
2478+
// FIXME(pin_ergonomics): handle `&pin mut|const T`
24762479
match mutbl {
24772480
// Shared borrowed data is never mutable
24782481
hir::Mutability::Not => Err(place),

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
17611761
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
17621762
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
17631763
let normalized_ty = self.normalize(unnormalized_ty, locations);
1764-
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
1764+
let literal_ty = constant.const_.ty().builtin_deref(true, tcx).unwrap();
17651765

17661766
if let Err(terr) =
17671767
self.eq_types(literal_ty, normalized_ty, locations, ConstraintCategory::Boring)
@@ -2360,7 +2360,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23602360

23612361
debug!("add_reborrow_constraint - base_ty = {:?}", base_ty);
23622362
match base_ty.kind() {
2363-
ty::Ref(ref_region, _, mutbl) => {
2363+
_ if let Some((ref_region, _, _, mutbl)) =
2364+
base_ty.is_ref_or_pin_ref(tcx) =>
2365+
{
2366+
// FIXME(pin_ergonomics): handle `&pin mut|const T`
23642367
constraints.outlives_constraints.push(OutlivesConstraint {
23652368
sup: ref_region.as_var(),
23662369
sub: borrow_region.as_var(),

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ fn codegen_stmt<'tcx>(
729729
let to_ty = fx.monomorphize(to_ty);
730730

731731
fn is_wide_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
732-
ty.builtin_deref(true).is_some_and(|pointee_ty| {
732+
ty.builtin_deref(true, fx.tcx).is_some_and(|pointee_ty| {
733733
fx.tcx
734734
.type_has_metadata(pointee_ty, ty::TypingEnv::fully_monomorphized())
735735
})

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
583583
intrinsic_args!(fx, args => (base, offset); intrinsic);
584584
let offset = offset.load_scalar(fx);
585585

586-
let pointee_ty = base.layout().ty.builtin_deref(true).unwrap();
586+
let pointee_ty = base.layout().ty.builtin_deref(true, fx.tcx).unwrap();
587587
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
588588
let ptr_diff = if pointee_size != 1 {
589589
fx.bcx.ins().imul_imm(offset, pointee_size as i64)
@@ -609,7 +609,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
609609
let val = val.load_scalar(fx);
610610
let count = count.load_scalar(fx);
611611

612-
let pointee_ty = dst.layout().ty.builtin_deref(true).unwrap();
612+
let pointee_ty = dst.layout().ty.builtin_deref(true, fx.tcx).unwrap();
613613
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
614614
let count = if pointee_size != 1 {
615615
fx.bcx.ins().imul_imm(count, pointee_size as i64)
@@ -717,7 +717,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
717717

718718
// Cranelift treats loads as volatile by default
719719
// FIXME correctly handle unaligned_volatile_load
720-
let inner_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap());
720+
let inner_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true, fx.tcx).unwrap());
721721
let val = CValue::by_ref(Pointer::new(ptr.load_scalar(fx)), inner_layout);
722722
ret.write_cvalue(fx, val);
723723
}

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
897897
intrinsic_args!(fx, args => (ptr, offset); intrinsic);
898898

899899
let (lane_count, ptr_lane_ty) = ptr.layout().ty.simd_size_and_type(fx.tcx);
900-
let pointee_ty = ptr_lane_ty.builtin_deref(true).unwrap();
900+
let pointee_ty = ptr_lane_ty.builtin_deref(true, fx.tcx).unwrap();
901901
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
902902
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
903903
let ret_lane_layout = fx.layout_of(ret_lane_ty);

compiler/rustc_codegen_cranelift/src/num.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
398398
let is_thin_ptr = in_lhs
399399
.layout()
400400
.ty
401-
.builtin_deref(true)
401+
.builtin_deref(true, fx.tcx)
402402
.map(|ty| !fx.tcx.type_has_metadata(ty, ty::TypingEnv::fully_monomorphized()))
403403
.unwrap_or(true);
404404

@@ -411,7 +411,7 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
411411
codegen_compare_bin_op(fx, bin_op, false, lhs, rhs)
412412
}
413413
BinOp::Offset => {
414-
let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap();
414+
let pointee_ty = in_lhs.layout().ty.builtin_deref(true, fx.tcx).unwrap();
415415
let (base, offset) = (in_lhs, in_rhs.load_scalar(fx));
416416
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
417417
let ptr_diff = fx.bcx.ins().imul_imm(offset, pointee_size as i64);

compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub(crate) fn coerce_unsized_into<'tcx>(
138138
let dst_ty = dst.layout().ty;
139139
let mut coerce_ptr = || {
140140
let (base, info) =
141-
if fx.layout_of(src.layout().ty.builtin_deref(true).unwrap()).is_unsized() {
141+
if fx.layout_of(src.layout().ty.builtin_deref(true, fx.tcx).unwrap()).is_unsized() {
142142
let (old_base, old_info) = src.load_scalar_pair(fx);
143143
unsize_ptr(fx, old_base, src.layout(), dst.layout(), Some(old_info))
144144
} else {

compiler/rustc_codegen_cranelift/src/value_and_place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ impl<'tcx> CPlace<'tcx> {
831831
}
832832

833833
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CPlace<'tcx> {
834-
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap());
834+
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true, fx.tcx).unwrap());
835835
if fx.tcx.type_has_metadata(inner_layout.ty, ty::TypingEnv::fully_monomorphized()) {
836836
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
837837
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)

compiler/rustc_codegen_cranelift/src/vtable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
5959

6060
if let ty::Ref(_, ty, _) = arg.layout().ty.kind() {
6161
if ty.is_dyn_star() {
62-
let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap());
62+
let inner_layout =
63+
fx.layout_of(arg.layout().ty.builtin_deref(true, fx.tcx).unwrap());
6364
let dyn_star = CPlace::for_ptr(Pointer::new(arg.load_scalar(fx)), inner_layout);
6465
let ptr = dyn_star.place_field(fx, FieldIdx::ZERO).to_ptr();
6566
let vtable =

0 commit comments

Comments
 (0)