@@ -137,8 +137,11 @@ fn apply_adjustment<'a, 'tcx>(
137137 arg : expr. to_ref ( ) ,
138138 }
139139 }
140- Adjust :: Borrow ( AutoBorrow :: RawPtr ( mutbl) ) => {
141- raw_ref_shim ( cx, expr. to_ref ( ) , adjustment. target , mutbl, span, temp_lifetime)
140+ Adjust :: Borrow ( AutoBorrow :: RawPtr ( mutability) ) => {
141+ ExprKind :: AddressOf {
142+ mutability,
143+ arg : expr. to_ref ( ) ,
144+ }
142145 }
143146 } ;
144147
@@ -262,17 +265,11 @@ fn make_mirror_unadjusted<'a, 'tcx>(
262265 }
263266 }
264267
265- hir:: ExprKind :: AddrOf ( hir:: BorrowKind :: Raw , mutbl, ref arg) => {
266- cx. tcx . sess
267- . struct_span_err (
268- expr. span ,
269- "raw borrows are not yet implemented"
270- )
271- . note ( "for more information, see https://github.com/rust-lang/rust/issues/64490" )
272- . emit ( ) ;
273-
274- // Lower to an approximation to avoid further errors.
275- raw_ref_shim ( cx, arg. to_ref ( ) , expr_ty, mutbl, expr. span , temp_lifetime)
268+ hir:: ExprKind :: AddrOf ( hir:: BorrowKind :: Raw , mutability, ref arg) => {
269+ ExprKind :: AddressOf {
270+ mutability,
271+ arg : arg. to_ref ( ) ,
272+ }
276273 }
277274
278275 hir:: ExprKind :: Block ( ref blk, _) => ExprKind :: Block { body : & blk } ,
@@ -1082,67 +1079,6 @@ fn convert_var(
10821079}
10831080
10841081
1085- /// Fake `&raw [mut|const] expr` using a borrow and a cast until `AddressOf`
1086- /// exists in MIR.
1087- fn raw_ref_shim < ' tcx > (
1088- cx : & mut Cx < ' _ , ' tcx > ,
1089- arg : ExprRef < ' tcx > ,
1090- ty : Ty < ' tcx > ,
1091- mutbl : hir:: Mutability ,
1092- span : Span ,
1093- temp_lifetime : Option < region:: Scope > ,
1094- ) -> ExprKind < ' tcx > {
1095- let arg_tm = if let ty:: RawPtr ( type_mutbl) = ty. kind {
1096- type_mutbl
1097- } else {
1098- bug ! ( "raw_ref_shim called with non-raw pointer type" ) ;
1099- } ;
1100- // Convert this to a suitable `&foo` and
1101- // then an unsafe coercion.
1102- let borrow_expr = Expr {
1103- temp_lifetime,
1104- ty : cx. tcx . mk_ref ( cx. tcx . lifetimes . re_erased , arg_tm) ,
1105- span,
1106- kind : ExprKind :: Borrow {
1107- borrow_kind : mutbl. to_borrow_kind ( ) ,
1108- arg,
1109- } ,
1110- } ;
1111- let cast_expr = Expr {
1112- temp_lifetime,
1113- ty,
1114- span,
1115- kind : ExprKind :: Cast { source : borrow_expr. to_ref ( ) }
1116- } ;
1117-
1118- // To ensure that both implicit and explicit coercions are
1119- // handled the same way, we insert an extra layer of indirection here.
1120- // For explicit casts (e.g., 'foo as *const T'), the source of the 'Use'
1121- // will be an ExprKind::Hair with the appropriate cast expression. Here,
1122- // we make our Use source the generated Cast from the original coercion.
1123- //
1124- // In both cases, this outer 'Use' ensures that the inner 'Cast' is handled by
1125- // as_operand, not by as_rvalue - causing the cast result to be stored in a temporary.
1126- // Ordinary, this is identical to using the cast directly as an rvalue. However, if the
1127- // source of the cast was previously borrowed as mutable, storing the cast in a
1128- // temporary gives the source a chance to expire before the cast is used. For
1129- // structs with a self-referential *mut ptr, this allows assignment to work as
1130- // expected.
1131- //
1132- // For example, consider the type 'struct Foo { field: *mut Foo }',
1133- // The method 'fn bar(&mut self) { self.field = self }'
1134- // triggers a coercion from '&mut self' to '*mut self'. In order
1135- // for the assignment to be valid, the implicit borrow
1136- // of 'self' involved in the coercion needs to end before the local
1137- // containing the '*mut T' is assigned to 'self.field' - otherwise,
1138- // we end up trying to assign to 'self.field' while we have another mutable borrow
1139- // active.
1140- //
1141- // We only need to worry about this kind of thing for coercions from refs to ptrs,
1142- // since they get rid of a borrow implicitly.
1143- ExprKind :: Use { source : cast_expr. to_ref ( ) }
1144- }
1145-
11461082fn bin_op ( op : hir:: BinOpKind ) -> BinOp {
11471083 match op {
11481084 hir:: BinOpKind :: Add => BinOp :: Add ,
0 commit comments