Skip to content

Commit b0f3844

Browse files
The rest of the owl
1 parent 96a66b0 commit b0f3844

File tree

58 files changed

+402
-93
lines changed

Some content is hidden

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

58 files changed

+402
-93
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ impl GenBlockKind {
16681668
}
16691669

16701670
/// Whether we're unwrapping or wrapping an unsafe binder
1671-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1671+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
16721672
#[derive(Encodable, Decodable, HashStable_Generic)]
16731673
pub enum UnsafeBinderCastKind {
16741674
// e.g. `&i32` -> `unsafe<'a> &'a i32`

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3976,7 +3976,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
39763976
ProjectionElem::ConstantIndex { .. }
39773977
| ProjectionElem::Subslice { .. }
39783978
| ProjectionElem::Subtype(_)
3979-
| ProjectionElem::Index(_) => kind,
3979+
| ProjectionElem::Index(_)
3980+
| ProjectionElem::UnsafeBinderCast(..) => kind,
39803981
},
39813982
place_ty.projection_ty(tcx, elem),
39823983
)

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
243243
ProjectionElem::Downcast(..) => (),
244244
ProjectionElem::OpaqueCast(..) => (),
245245
ProjectionElem::Subtype(..) => (),
246+
ProjectionElem::UnsafeBinderCast(..) => (),
246247
ProjectionElem::Field(field, _ty) => {
247248
// FIXME(project-rfc_2229#36): print capture precisely here.
248249
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
@@ -323,9 +324,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
323324
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)
324325
}
325326
ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx),
326-
ProjectionElem::Subtype(ty) | ProjectionElem::OpaqueCast(ty) => {
327-
PlaceTy::from_ty(*ty)
328-
}
327+
ProjectionElem::Subtype(ty)
328+
| ProjectionElem::OpaqueCast(ty)
329+
| ProjectionElem::UnsafeBinderCast(_, ty) => PlaceTy::from_ty(*ty),
329330
ProjectionElem::Field(_, field_type) => PlaceTy::from_ty(*field_type),
330331
},
331332
};

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
167167
| ProjectionElem::ConstantIndex { .. }
168168
| ProjectionElem::OpaqueCast { .. }
169169
| ProjectionElem::Subslice { .. }
170-
| ProjectionElem::Downcast(..),
170+
| ProjectionElem::Downcast(..)
171+
| ProjectionElem::UnsafeBinderCast(..),
171172
],
172173
} => bug!("Unexpected immutable place."),
173174
}

compiler/rustc_borrowck/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
16851685
// So it's safe to skip these.
16861686
ProjectionElem::OpaqueCast(_)
16871687
| ProjectionElem::Subtype(_)
1688-
| ProjectionElem::Downcast(_, _) => (),
1688+
| ProjectionElem::Downcast(_, _)
1689+
| ProjectionElem::UnsafeBinderCast(_, _) => (),
16891690
}
16901691

16911692
place_ty = place_ty.projection_ty(tcx, elem);
@@ -1919,6 +1920,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19191920
// FIXME: is this true even if P is an adt with a dtor?
19201921
{ }
19211922

1923+
ProjectionElem::UnsafeBinderCast(..) => {
1924+
check_parent_of_field(self, location, place_base, span, state);
1925+
}
1926+
19221927
// assigning to (*P) requires P to be initialized
19231928
ProjectionElem::Deref => {
19241929
self.check_if_full_path_is_moved(
@@ -2299,7 +2304,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
22992304
| ProjectionElem::Subslice { .. }
23002305
| ProjectionElem::Subtype(..)
23012306
| ProjectionElem::OpaqueCast { .. }
2302-
| ProjectionElem::Downcast(..) => {
2307+
| ProjectionElem::Downcast(..)
2308+
| ProjectionElem::UnsafeBinderCast(..) => {
23032309
let upvar_field_projection = self.is_upvar_field_projection(place);
23042310
if let Some(field) = upvar_field_projection {
23052311
let upvar = &self.upvars[field.index()];

compiler/rustc_borrowck/src/places_conflict.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ fn place_components_conflict<'tcx>(
250250
| (ProjectionElem::Subslice { .. }, _, _)
251251
| (ProjectionElem::OpaqueCast { .. }, _, _)
252252
| (ProjectionElem::Subtype(_), _, _)
253-
| (ProjectionElem::Downcast { .. }, _, _) => {
253+
| (ProjectionElem::Downcast { .. }, _, _)
254+
| (ProjectionElem::UnsafeBinderCast(..), _, _) => {
254255
// Recursive case. This can still be disjoint on a
255256
// further iteration if this a shallow access and
256257
// there's a deref later on, e.g., a borrow
@@ -519,5 +520,9 @@ fn place_projection_conflict<'tcx>(
519520
pi1_elem,
520521
pi2_elem
521522
),
523+
524+
(ProjectionElem::UnsafeBinderCast(..), _) => {
525+
todo!()
526+
}
522527
}
523528
}

compiler/rustc_borrowck/src/prefixes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ impl<'tcx> Iterator for Prefixes<'tcx> {
6666
self.next = Some(cursor_base);
6767
return Some(cursor);
6868
}
69+
ProjectionElem::UnsafeBinderCast(..) => {
70+
self.next = Some(cursor_base);
71+
return Some(cursor);
72+
}
6973
ProjectionElem::Downcast(..)
7074
| ProjectionElem::Subslice { .. }
7175
| ProjectionElem::OpaqueCast { .. }

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,48 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
693693
.unwrap();
694694
PlaceTy::from_ty(ty)
695695
}
696+
ProjectionElem::UnsafeBinderCast(kind, ty) => match kind {
697+
hir::UnsafeBinderCastKind::Wrap => {
698+
let ty::UnsafeBinder(binder_ty) = *ty.kind() else {
699+
bug!();
700+
};
701+
let expected_ty = self.typeck.infcx.instantiate_binder_with_fresh_vars(
702+
self.body().source_info(location).span,
703+
BoundRegionConversionTime::HigherRankedType,
704+
binder_ty.into(),
705+
);
706+
self.typeck
707+
.relate_types(
708+
expected_ty,
709+
self.get_ambient_variance(context),
710+
base_ty,
711+
location.to_locations(),
712+
ConstraintCategory::TypeAnnotation,
713+
)
714+
.unwrap();
715+
PlaceTy::from_ty(ty)
716+
}
717+
hir::UnsafeBinderCastKind::Unwrap => {
718+
let ty::UnsafeBinder(binder_ty) = *base_ty.kind() else {
719+
bug!();
720+
};
721+
let found_ty = self.typeck.infcx.instantiate_binder_with_fresh_vars(
722+
self.body().source_info(location).span,
723+
BoundRegionConversionTime::HigherRankedType,
724+
binder_ty.into(),
725+
);
726+
self.typeck
727+
.relate_types(
728+
ty,
729+
self.get_ambient_variance(context),
730+
found_ty,
731+
location.to_locations(),
732+
ConstraintCategory::TypeAnnotation,
733+
)
734+
.unwrap();
735+
PlaceTy::from_ty(ty)
736+
}
737+
},
696738
}
697739
}
698740

@@ -2679,7 +2721,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26792721
| ProjectionElem::OpaqueCast(..)
26802722
| ProjectionElem::Index(..)
26812723
| ProjectionElem::ConstantIndex { .. }
2682-
| ProjectionElem::Subslice { .. } => {
2724+
| ProjectionElem::Subslice { .. }
2725+
| ProjectionElem::UnsafeBinderCast(..) => {
26832726
// other field access
26842727
}
26852728
ProjectionElem::Subtype(_) => {

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,9 @@ pub(crate) fn codegen_place<'tcx>(
983983
cplace = cplace.place_deref(fx);
984984
}
985985
PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"),
986-
PlaceElem::Subtype(ty) => cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty)),
986+
PlaceElem::Subtype(ty) | PlaceElem::UnsafeBinderCast(_, ty) => {
987+
cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty));
988+
}
987989
PlaceElem::Field(field, _ty) => {
988990
cplace = cplace.place_field(fx, field);
989991
}

compiler/rustc_codegen_ssa/src/mir/place.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
502502
bug!("encountered OpaqueCast({ty}) in codegen")
503503
}
504504
mir::ProjectionElem::Subtype(ty) => cg_base.project_type(bx, self.monomorphize(ty)),
505+
mir::ProjectionElem::UnsafeBinderCast(_, ty) => {
506+
cg_base.project_type(bx, self.monomorphize(ty))
507+
}
505508
mir::ProjectionElem::Index(index) => {
506509
let index = &mir::Operand::Copy(mir::Place::from(index));
507510
let index = self.codegen_operand(bx, index);

0 commit comments

Comments
 (0)