Skip to content

Commit ea4de88

Browse files
committed
Auto merge of rust-lang#127679 - RalfJung:raw_ref_op, r=<try>
Stabilize `raw_ref_op` (RFC 2582) This stabilizes the syntax `&raw const $expr` and `&raw mut $expr`. It has existed unstably for ~4 years now, and has been exposed on stable via the `addr_of` and `addr_of_mut` macros since Rust 1.51 (released more than 3 years ago). I think it has become clear that these operations are here to stay. So it is about time we give them proper primitive syntax. This has two advantages over the macro: - Being macros, `addr_of`/`addr_of_mut` could in theory do arbitrary magic with the expression on which they work. The only "magic" they actually do is using the argument as a place expression rather than as a value expression. Place expressions are already a subtle topic and poorly understood by many programmers; having this hidden behind a macro using unstable language features makes this even worse. Conversely, people do have an idea of what happens below `&`/`&mut`, so we can make the subtle topic a lot more approachable by connecting to existing intuition. - The name `addr_of` is quite unfortunate from today's perspective, given that we have accepted provenance as a reality, which means that a pointer is *not* just an address. Strict provenance has a method, `addr`, which extracts the address of a pointer; using the term `addr` in two different ways is quite unfortunate. That's why this PR soft-deprecates `addr_of` -- we will wait a long time before actually showing any warning here, but we should start telling people that the "addr" part of this name is somewhat misleading, and `&raw` avoids that potential confusion. In summary, this syntax improves developers' ability to conceptualize the operational semantics of Rust, while making a fundamental operation frequently used in unsafe code feel properly built in. Possible questions to consider, based on the RFC and [this](rust-lang#64490 (comment)) great summary by `@CAD97:` - Some questions are entirely about the semantics. The semantics are the same as with the macros so I don't think this should have any impact on this syntax PR. Still, for completeness' sake: - Should `&raw const *mut_ref` give a read-only pointer? - Tracked at: rust-lang/unsafe-code-guidelines#257 - I think ideally the answer is "no". Stacked Borrows says that pointer is read-only, but Tree Borrows says it is mutable. - What exactly does `&raw const (*ptr).field` require? Answered in [the reference](https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html): the arithmetic to compute the field offset follows the rules of `ptr::offset`, making it UB if it goes out-of-bounds. Making this a safe operation (using `wrapping_offset` rules) is considered too much of a loss for alias analysis. - Choose a different syntax? I don't want to re-litigate the RFC. The only credible alternative that has been proposed is `&raw $place` instead of `&raw const $place`, which (IIUC) could be achieved by making `raw` a contextual keyword in a new edition. The type is named `*const T`, so the explicit `const` is consistent in that regard. `&raw expr` lacks the explicit indication of immutability. However, `&raw const expr` is quite a but longer than `addr_of!(expr)`. - Shouldn't we have a completely new, better raw pointer type instead? Yes we all want to see that happen -- but I don't think we should block stabilization on that, given that such a nicer type is not on the horizon currently and given the issues with `addr_of!` mentioned above. (If we keep the `&raw $place` syntax free for this, we could use it in the future for that new type.) - What about the lint the RFC talked about? It hasn't been implemented yet. Given that the problematic code is UB with or without this stabilization, I don't think the lack of the lint should block stabilization. - I created an issue to track adding it: rust-lang#127724 - Other points from the "future possibilites of the RFC - "Syntactic sugar" extension: this has not been implemented. I'd argue this is too confusing, we should stick to what the RFC suggested and if we want to do anything about such expressions, add the lint. - Encouraging / requiring `&raw` in situations where references are often/definitely incorrect: this has been / is being implemented. On packed fields this already is a hard error, and for `static mut` a lint suggesting raw pointers is being rolled out. - Lowering of casts: this has been implemented. (It's also an invisible implementation detail.) - `offsetof` woes: we now have native `offset_of` so this is not relevant any more. To be done before landing: - [x] Suppress `unused_parens` lint around `&raw {const|mut}` expressions - See bottom of rust-lang#127679 (comment) for rationale - Implementation: rust-lang#128782 - [ ] Update the Reference. - rust-lang/reference#1567 Fixes rust-lang#64490 cc `@rust-lang/lang` `@rust-lang/opsem` // try-job: i686-mingw // `dump-ice-to-disk` is flaky try-job: x86_64-msvc try-job: test-various try-job: dist-various-1 try-job: armhf-gnu try-job: aarch64-apple
2 parents 79f5c16 + 367c014 commit ea4de88

File tree

114 files changed

+204
-337
lines changed

Some content is hidden

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

114 files changed

+204
-337
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
539539
}
540540
}
541541
gate_all!(gen_blocks, "gen blocks are experimental");
542-
gate_all!(raw_ref_op, "raw address of syntax is experimental");
543542
gate_all!(const_trait_impl, "const trait impls are experimental");
544543
gate_all!(
545544
half_open_range_patterns_in_slices,

compiler/rustc_borrowck/src/def_use.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
5555
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) |
5656
PlaceContext::NonUse(NonUseContext::AscribeUserTy(_)) |
5757

58-
PlaceContext::MutatingUse(MutatingUseContext::AddressOf) |
59-
PlaceContext::NonMutatingUse(NonMutatingUseContext::AddressOf) |
58+
PlaceContext::MutatingUse(MutatingUseContext::RawBorrow) |
59+
PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow) |
6060
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) |
6161
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) |
6262
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) |

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
12421242
);
12431243
}
12441244

1245-
&Rvalue::AddressOf(mutability, place) => {
1245+
&Rvalue::RawPtr(mutability, place) => {
12461246
let access_kind = match mutability {
12471247
Mutability::Mut => (
12481248
Deep,

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl<'cx, 'tcx> LoanInvalidationsGenerator<'cx, 'tcx> {
269269
self.access_place(location, place, access_kind, LocalMutationIsAllowed::No);
270270
}
271271

272-
&Rvalue::AddressOf(mutability, place) => {
272+
&Rvalue::RawPtr(mutability, place) => {
273273
let access_kind = match mutability {
274274
Mutability::Mut => (
275275
Deep,

compiler/rustc_borrowck/src/type_check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
756756
PlaceContext::MutatingUse(_) => ty::Invariant,
757757
PlaceContext::NonUse(StorageDead | StorageLive | VarDebugInfo) => ty::Invariant,
758758
PlaceContext::NonMutatingUse(
759-
Inspect | Copy | Move | PlaceMention | SharedBorrow | FakeBorrow | AddressOf
759+
Inspect | Copy | Move | PlaceMention | SharedBorrow | FakeBorrow | RawBorrow
760760
| Projection,
761761
) => ty::Covariant,
762762
PlaceContext::NonUse(AscribeUserTy(variance)) => variance,
@@ -2468,7 +2468,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24682468
self.check_operand(right, location);
24692469
}
24702470

2471-
Rvalue::AddressOf(..)
2471+
Rvalue::RawPtr(..)
24722472
| Rvalue::ThreadLocalRef(..)
24732473
| Rvalue::Len(..)
24742474
| Rvalue::Discriminant(..)
@@ -2485,7 +2485,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24852485
| Rvalue::ThreadLocalRef(_)
24862486
| Rvalue::Repeat(..)
24872487
| Rvalue::Ref(..)
2488-
| Rvalue::AddressOf(..)
2488+
| Rvalue::RawPtr(..)
24892489
| Rvalue::Len(..)
24902490
| Rvalue::Cast(..)
24912491
| Rvalue::ShallowInitBox(..)

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
extern_types,
77
naked_functions,
88
thread_local,
9-
repr_simd,
10-
raw_ref_op
9+
repr_simd
1110
)]
1211
#![no_core]
1312
#![allow(dead_code, non_camel_case_types, internal_features)]

compiler/rustc_codegen_cranelift/src/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
2525
for stmt in bb.statements.iter() {
2626
match &stmt.kind {
2727
Assign(place_and_rval) => match &place_and_rval.1 {
28-
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
28+
Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) => {
2929
flag_map[place.local] = SsaKind::NotSsa;
3030
}
3131
_ => {}

compiler/rustc_codegen_cranelift/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ fn codegen_stmt<'tcx>(
595595
let val = cplace.to_cvalue(fx);
596596
lval.write_cvalue(fx, val)
597597
}
598-
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
598+
Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) => {
599599
let place = codegen_place(fx, place);
600600
let ref_ = place.place_ref(fx, lval.layout());
601601
lval.write_cvalue(fx, ref_);

compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![feature(
44
no_core, unboxed_closures, start, lang_items, never_type, linkage,
5-
extern_types, thread_local, raw_ref_op
5+
extern_types, thread_local
66
)]
77
#![no_core]
88
#![allow(dead_code, internal_features, non_camel_case_types)]

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,14 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
220220
| MutatingUseContext::SetDiscriminant
221221
| MutatingUseContext::AsmOutput
222222
| MutatingUseContext::Borrow
223-
| MutatingUseContext::AddressOf
223+
| MutatingUseContext::RawBorrow
224224
| MutatingUseContext::Projection,
225225
)
226226
| PlaceContext::NonMutatingUse(
227227
NonMutatingUseContext::Inspect
228228
| NonMutatingUseContext::SharedBorrow
229229
| NonMutatingUseContext::FakeBorrow
230-
| NonMutatingUseContext::AddressOf
230+
| NonMutatingUseContext::RawBorrow
231231
| NonMutatingUseContext::Projection,
232232
) => {
233233
self.locals[local] = LocalKind::Memory;

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
584584
mir::Rvalue::CopyForDeref(place) => {
585585
self.codegen_operand(bx, &mir::Operand::Copy(place))
586586
}
587-
mir::Rvalue::AddressOf(mutability, place) => {
587+
mir::Rvalue::RawPtr(mutability, place) => {
588588
let mk_ptr =
589589
move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| Ty::new_ptr(tcx, ty, mutability);
590590
self.codegen_place_to_pointer(bx, place, mk_ptr)
@@ -813,7 +813,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
813813
cg_value.len(bx.cx())
814814
}
815815

816-
/// Codegen an `Rvalue::AddressOf` or `Rvalue::Ref`
816+
/// Codegen an `Rvalue::RawPtr` or `Rvalue::Ref`
817817
fn codegen_place_to_pointer(
818818
&mut self,
819819
bx: &mut Bx,
@@ -1085,7 +1085,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10851085
}
10861086
mir::Rvalue::Ref(..) |
10871087
mir::Rvalue::CopyForDeref(..) |
1088-
mir::Rvalue::AddressOf(..) |
1088+
mir::Rvalue::RawPtr(..) |
10891089
mir::Rvalue::Len(..) |
10901090
mir::Rvalue::Cast(..) | // (*)
10911091
mir::Rvalue::ShallowInitBox(..) | // (*)

compiler/rustc_const_eval/src/check_consts/check.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,13 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
431431
return;
432432
}
433433
}
434-
Rvalue::AddressOf(mutbl, place) => {
434+
Rvalue::RawPtr(mutbl, place) => {
435435
if let Some(reborrowed_place_ref) = place_as_reborrow(self.tcx, self.body, place) {
436436
let ctx = match mutbl {
437437
Mutability::Not => {
438-
PlaceContext::NonMutatingUse(NonMutatingUseContext::AddressOf)
438+
PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow)
439439
}
440-
Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::AddressOf),
440+
Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::RawBorrow),
441441
};
442442
self.visit_local(reborrowed_place_ref.local, ctx, location);
443443
self.visit_projection(reborrowed_place_ref, ctx, location);
@@ -472,7 +472,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
472472
}
473473

474474
Rvalue::Ref(_, BorrowKind::Mut { .. }, place)
475-
| Rvalue::AddressOf(Mutability::Mut, place) => {
475+
| Rvalue::RawPtr(Mutability::Mut, place) => {
476476
// Inside mutable statics, we allow arbitrary mutable references.
477477
// We've allowed `static mut FOO = &mut [elements];` for a long time (the exact
478478
// reasons why are lost to history), and there is no reason to restrict that to
@@ -493,7 +493,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
493493
}
494494

495495
Rvalue::Ref(_, BorrowKind::Shared | BorrowKind::Fake(_), place)
496-
| Rvalue::AddressOf(Mutability::Not, place) => {
496+
| Rvalue::RawPtr(Mutability::Not, place) => {
497497
let borrowed_place_has_mut_interior = qualifs::in_place::<HasMutInterior, _>(
498498
self.ccx,
499499
&mut |local| self.qualifs.has_mut_interior(self.ccx, local, location),

compiler/rustc_const_eval/src/check_consts/qualifs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ where
291291
in_operand::<Q, _>(cx, in_local, lhs) || in_operand::<Q, _>(cx, in_local, rhs)
292292
}
293293

294-
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
294+
Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) => {
295295
// Special-case reborrows to be more like a copy of the reference.
296296
if let Some((place_base, ProjectionElem::Deref)) = place.as_ref().last_projection() {
297297
let base_ty = place_base.ty(cx.body, cx.tcx).ty;

compiler/rustc_const_eval/src/check_consts/resolver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ where
9696
}
9797

9898
fn address_of_allows_mutation(&self) -> bool {
99-
// Exact set of permissions granted by AddressOf is undecided. Conservatively assume that
99+
// Exact set of permissions granted by RawPtr is undecided. Conservatively assume that
100100
// it might allow mutation until resolution of #56604.
101101
true
102102
}
@@ -170,7 +170,7 @@ where
170170
self.super_rvalue(rvalue, location);
171171

172172
match rvalue {
173-
mir::Rvalue::AddressOf(_mt, borrowed_place) => {
173+
mir::Rvalue::RawPtr(_mt, borrowed_place) => {
174174
if !borrowed_place.is_indirect() && self.address_of_allows_mutation() {
175175
let place_ty = borrowed_place.ty(self.ccx.body, self.ccx.tcx).ty;
176176
if Q::in_any_value_of_ty(self.ccx, place_ty) {

compiler/rustc_const_eval/src/interpret/step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
234234
self.write_immediate(*val, &dest)?;
235235
}
236236

237-
AddressOf(_, place) => {
237+
RawPtr(_, place) => {
238238
// Figure out whether this is an addr_of of an already raw place.
239239
let place_base_raw = if place.is_indirect_first_projection() {
240240
let ty = self.frame().body.local_decls[place.local].ty;

compiler/rustc_error_codes/src/error_codes/E0745.md

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ The address of temporary value was taken.
33
Erroneous code example:
44

55
```compile_fail,E0745
6-
# #![feature(raw_ref_op)]
76
fn temp_address() {
87
let ptr = &raw const 2; // error!
98
}
@@ -15,7 +14,6 @@ In this example, `2` is destroyed right after the assignment, which means that
1514
To avoid this error, first bind the temporary to a named local variable:
1615

1716
```
18-
# #![feature(raw_ref_op)]
1917
fn temp_address() {
2018
let val = 2;
2119
let ptr = &raw const val; // ok!

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ declare_features! (
321321
(accepted, raw_dylib, "1.71.0", Some(58713)),
322322
/// Allows keywords to be escaped for use as identifiers.
323323
(accepted, raw_identifiers, "1.30.0", Some(48589)),
324+
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
325+
(accepted, raw_ref_op, "CURRENT_RUSTC_VERSION", Some(64490)),
324326
/// Allows relaxing the coherence rules such that
325327
/// `impl<T> ForeignTrait<LocalType> for ForeignType<T>` is permitted.
326328
(accepted, re_rebalance_coherence, "1.41.0", Some(55437)),

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,6 @@ declare_features! (
565565
(unstable, precise_capturing, "1.79.0", Some(123432)),
566566
/// Allows macro attributes on expressions, statements and non-inline modules.
567567
(unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
568-
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
569-
(unstable, raw_ref_op, "1.41.0", Some(64490)),
570568
/// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024.
571569
(incomplete, ref_pat_eat_one_layer_2024, "1.79.0", Some(123076)),
572570
/// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024—structural variant

compiler/rustc_hir_typeck/src/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
967967
// need to special-case obtaining a raw pointer
968968
// from a region pointer to a vector.
969969

970-
// Coerce to a raw pointer so that we generate AddressOf in MIR.
970+
// Coerce to a raw pointer so that we generate RawPtr in MIR.
971971
let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr.ty, m_expr.mutbl);
972972
fcx.coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
973973
.unwrap_or_else(|_| {

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
10381038

10391039
CopyForDeref(ref place) => write!(fmt, "deref_copy {place:#?}"),
10401040

1041-
AddressOf(mutability, ref place) => {
1041+
RawPtr(mutability, ref place) => {
10421042
write!(fmt, "&raw {mut_str} {place:?}", mut_str = mutability.ptr_str())
10431043
}
10441044

compiler/rustc_middle/src/mir/statement.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl<'tcx> Rvalue<'tcx> {
423423
| Rvalue::Repeat(_, _)
424424
| Rvalue::Ref(_, _, _)
425425
| Rvalue::ThreadLocalRef(_)
426-
| Rvalue::AddressOf(_, _)
426+
| Rvalue::RawPtr(_, _)
427427
| Rvalue::Len(_)
428428
| Rvalue::Cast(
429429
CastKind::IntToInt

compiler/rustc_middle/src/mir/syntax.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1293,14 +1293,14 @@ pub enum Rvalue<'tcx> {
12931293
/// nature of this operation?
12941294
ThreadLocalRef(DefId),
12951295

1296-
/// Creates a pointer with the indicated mutability to the place.
1296+
/// Creates a raw pointer with the indicated mutability to the place.
12971297
///
1298-
/// This is generated by pointer casts like `&v as *const _` or raw address of expressions like
1299-
/// `&raw v` or `addr_of!(v)`.
1298+
/// This is generated by pointer casts like `&v as *const _` or raw borrow expressions like
1299+
/// `&raw const v`.
13001300
///
13011301
/// Like with references, the semantics of this operation are heavily dependent on the aliasing
13021302
/// model.
1303-
AddressOf(Mutability, Place<'tcx>),
1303+
RawPtr(Mutability, Place<'tcx>),
13041304

13051305
/// Yields the length of the place, as a `usize`.
13061306
///

compiler/rustc_middle/src/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'tcx> Rvalue<'tcx> {
170170
let place_ty = place.ty(local_decls, tcx).ty;
171171
Ty::new_ref(tcx, reg, place_ty, bk.to_mutbl_lossy())
172172
}
173-
Rvalue::AddressOf(mutability, ref place) => {
173+
Rvalue::RawPtr(mutability, ref place) => {
174174
let place_ty = place.ty(local_decls, tcx).ty;
175175
Ty::new_ptr(tcx, place_ty, mutability)
176176
}

compiler/rustc_middle/src/mir/visit.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -682,13 +682,13 @@ macro_rules! make_mir_visitor {
682682
);
683683
}
684684

685-
Rvalue::AddressOf(m, path) => {
685+
Rvalue::RawPtr(m, path) => {
686686
let ctx = match m {
687687
Mutability::Mut => PlaceContext::MutatingUse(
688-
MutatingUseContext::AddressOf
688+
MutatingUseContext::RawBorrow
689689
),
690690
Mutability::Not => PlaceContext::NonMutatingUse(
691-
NonMutatingUseContext::AddressOf
691+
NonMutatingUseContext::RawBorrow
692692
),
693693
};
694694
self.visit_place(path, ctx, location);
@@ -1299,8 +1299,8 @@ pub enum NonMutatingUseContext {
12991299
/// FIXME: do we need to distinguish shallow and deep fake borrows? In fact, do we need to
13001300
/// distinguish fake and normal deep borrows?
13011301
FakeBorrow,
1302-
/// AddressOf for *const pointer.
1303-
AddressOf,
1302+
/// `&raw const`.
1303+
RawBorrow,
13041304
/// PlaceMention statement.
13051305
///
13061306
/// This statement is executed as a check that the `Place` is live without reading from it,
@@ -1333,8 +1333,8 @@ pub enum MutatingUseContext {
13331333
Drop,
13341334
/// Mutable borrow.
13351335
Borrow,
1336-
/// AddressOf for *mut pointer.
1337-
AddressOf,
1336+
/// `&raw mut`.
1337+
RawBorrow,
13381338
/// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place.
13391339
/// For example, the projection `x.y` is marked as a mutation in these cases:
13401340
/// ```ignore (illustrative)
@@ -1386,8 +1386,8 @@ impl PlaceContext {
13861386
pub fn is_address_of(&self) -> bool {
13871387
matches!(
13881388
self,
1389-
PlaceContext::NonMutatingUse(NonMutatingUseContext::AddressOf)
1390-
| PlaceContext::MutatingUse(MutatingUseContext::AddressOf)
1389+
PlaceContext::NonMutatingUse(NonMutatingUseContext::RawBorrow)
1390+
| PlaceContext::MutatingUse(MutatingUseContext::RawBorrow)
13911391
)
13921392
}
13931393

compiler/rustc_middle/src/thir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ pub enum ExprKind<'tcx> {
407407
arg: ExprId,
408408
},
409409
/// A `&raw [const|mut] $place_expr` raw borrow resulting in type `*[const|mut] T`.
410-
AddressOf {
410+
RawBorrow {
411411
mutability: hir::Mutability,
412412
arg: ExprId,
413413
},

compiler/rustc_middle/src/thir/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
9292
}
9393
VarRef { id: _ } | UpvarRef { closure_def_id: _, var_hir_id: _ } => {}
9494
Borrow { arg, borrow_kind: _ } => visitor.visit_expr(&visitor.thir()[arg]),
95-
AddressOf { arg, mutability: _ } => visitor.visit_expr(&visitor.thir()[arg]),
95+
RawBorrow { arg, mutability: _ } => visitor.visit_expr(&visitor.thir()[arg]),
9696
Break { value, label: _ } => {
9797
if let Some(value) = value {
9898
visitor.visit_expr(&visitor.thir()[value])

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
244244
ExprKind::Borrow { borrow_kind, arg } => Ok(
245245
Rvalue::Ref(self.tcx.lifetimes.re_erased, *borrow_kind, self.parse_place(*arg)?)
246246
),
247-
ExprKind::AddressOf { mutability, arg } => Ok(
248-
Rvalue::AddressOf(*mutability, self.parse_place(*arg)?)
247+
ExprKind::RawBorrow { mutability, arg } => Ok(
248+
Rvalue::RawPtr(*mutability, self.parse_place(*arg)?)
249249
),
250250
ExprKind::Binary { op, lhs, rhs } => Ok(
251251
Rvalue::BinaryOp(*op, Box::new((self.parse_operand(*lhs)?, self.parse_operand(*rhs)?)))

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
542542
| ExprKind::PointerCoercion { .. }
543543
| ExprKind::Repeat { .. }
544544
| ExprKind::Borrow { .. }
545-
| ExprKind::AddressOf { .. }
545+
| ExprKind::RawBorrow { .. }
546546
| ExprKind::Match { .. }
547547
| ExprKind::If { .. }
548548
| ExprKind::Loop { .. }

0 commit comments

Comments
 (0)