Skip to content

Commit a97ab84

Browse files
committed
raw pointers are not references
1 parent b1efae4 commit a97ab84

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

compiler/rustc_const_eval/messages.ftl

+8-8
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ const_eval_too_many_caller_args =
337337
338338
const_eval_transient_mut_borrow = mutable references are not allowed in {const_eval_const_context}s
339339
340-
const_eval_transient_mut_borrow_raw = raw mutable references are not allowed in {const_eval_const_context}s
340+
const_eval_transient_mut_raw = raw mutable pointers are not allowed in {const_eval_const_context}s
341341
342342
const_eval_try_block_from_output_non_const =
343343
`try` block cannot convert `{$ty}` to the result in {const_eval_const_context}s
@@ -351,21 +351,21 @@ const_eval_unallowed_heap_allocations =
351351
352352
const_eval_unallowed_inline_asm =
353353
inline assembly is not allowed in {const_eval_const_context}s
354-
const_eval_unallowed_mutable_refs =
355-
mutable references are not allowed in the final value of {const_eval_const_context}s
354+
const_eval_unallowed_mutable_raw =
355+
raw mutable pointers are not allowed in the final value of {const_eval_const_context}s
356356
.teach_note =
357+
References in statics and constants may only refer to immutable values.
358+
359+
357360
Statics are shared everywhere, and if they refer to mutable data one might violate memory
358361
safety since holding multiple mutable references to shared data is not allowed.
359362
360363
361364
If you really want global mutable state, try using static mut or a global UnsafeCell.
362365
363-
const_eval_unallowed_mutable_refs_raw =
364-
raw mutable references are not allowed in the final value of {const_eval_const_context}s
366+
const_eval_unallowed_mutable_refs =
367+
mutable references are not allowed in the final value of {const_eval_const_context}s
365368
.teach_note =
366-
References in statics and constants may only refer to immutable values.
367-
368-
369369
Statics are shared everywhere, and if they refer to mutable data one might violate memory
370370
safety since holding multiple mutable references to shared data is not allowed.
371371

compiler/rustc_const_eval/src/errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ pub(crate) struct TransientMutBorrowErr {
114114
}
115115

116116
#[derive(Diagnostic)]
117-
#[diag(const_eval_transient_mut_borrow_raw, code = "E0658")]
118-
pub(crate) struct TransientMutBorrowErrRaw {
117+
#[diag(const_eval_transient_mut_raw, code = "E0658")]
118+
pub(crate) struct TransientMutRawErr {
119119
#[primary_span]
120120
pub span: Span,
121121
pub kind: ConstContext,
@@ -156,8 +156,8 @@ pub(crate) struct UnallowedMutableRefs {
156156
}
157157

158158
#[derive(Diagnostic)]
159-
#[diag(const_eval_unallowed_mutable_refs_raw, code = "E0764")]
160-
pub(crate) struct UnallowedMutableRefsRaw {
159+
#[diag(const_eval_unallowed_mutable_raw, code = "E0764")]
160+
pub(crate) struct UnallowedMutableRaw {
161161
#[primary_span]
162162
pub span: Span,
163163
pub kind: ConstContext,

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
466466

467467
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
468468
match self.0 {
469-
hir::BorrowKind::Raw => ccx.dcx().create_err(errors::UnallowedMutableRefsRaw {
469+
hir::BorrowKind::Raw => ccx.tcx.dcx().create_err(errors::UnallowedMutableRaw {
470470
span,
471471
kind: ccx.const_kind(),
472472
teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()),
@@ -491,10 +491,10 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
491491
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
492492
let kind = ccx.const_kind();
493493
match self.0 {
494-
hir::BorrowKind::Raw => ccx.tcx.sess.create_feature_err(
495-
errors::TransientMutBorrowErrRaw { span, kind },
496-
sym::const_mut_refs,
497-
),
494+
hir::BorrowKind::Raw => ccx
495+
.tcx
496+
.sess
497+
.create_feature_err(errors::TransientMutRawErr { span, kind }, sym::const_mut_refs),
498498
hir::BorrowKind::Ref => ccx.tcx.sess.create_feature_err(
499499
errors::TransientMutBorrowErr { span, kind },
500500
sym::const_mut_refs,
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#![feature(raw_ref_op)]
22

3-
const A: () = { let mut x = 2; &raw mut x; }; //~ mutable reference
3+
const A: () = { let mut x = 2; &raw mut x; }; //~ mutable pointer
44

5-
static B: () = { let mut x = 2; &raw mut x; }; //~ mutable reference
5+
static B: () = { let mut x = 2; &raw mut x; }; //~ mutable pointer
66

7-
static mut C: () = { let mut x = 2; &raw mut x; }; //~ mutable reference
7+
static mut C: () = { let mut x = 2; &raw mut x; }; //~ mutable pointer
88

99
const fn foo() {
1010
let mut x = 0;
11-
let y = &raw mut x; //~ mutable reference
11+
let y = &raw mut x; //~ mutable pointer
1212
}
1313

1414
fn main() {}

tests/ui/consts/const-address-of-mut.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: raw mutable references are not allowed in constants
1+
error[E0658]: raw mutable pointers are not allowed in constants
22
--> $DIR/const-address-of-mut.rs:3:32
33
|
44
LL | const A: () = { let mut x = 2; &raw mut x; };
@@ -7,7 +7,7 @@ LL | const A: () = { let mut x = 2; &raw mut x; };
77
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
88
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
99

10-
error[E0658]: raw mutable references are not allowed in statics
10+
error[E0658]: raw mutable pointers are not allowed in statics
1111
--> $DIR/const-address-of-mut.rs:5:33
1212
|
1313
LL | static B: () = { let mut x = 2; &raw mut x; };
@@ -16,7 +16,7 @@ LL | static B: () = { let mut x = 2; &raw mut x; };
1616
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
1717
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1818

19-
error[E0658]: raw mutable references are not allowed in statics
19+
error[E0658]: raw mutable pointers are not allowed in statics
2020
--> $DIR/const-address-of-mut.rs:7:37
2121
|
2222
LL | static mut C: () = { let mut x = 2; &raw mut x; };
@@ -25,7 +25,7 @@ LL | static mut C: () = { let mut x = 2; &raw mut x; };
2525
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
2626
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
2727

28-
error[E0658]: raw mutable references are not allowed in constant functions
28+
error[E0658]: raw mutable pointers are not allowed in constant functions
2929
--> $DIR/const-address-of-mut.rs:11:13
3030
|
3131
LL | let y = &raw mut x;

tests/ui/consts/min_const_fn/address_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
const fn mutable_address_of_in_const() {
44
let mut a = 0;
5-
let b = &raw mut a; //~ ERROR mutable reference
5+
let b = &raw mut a; //~ ERROR mutable pointer
66
}
77

88
struct X;
99

1010
impl X {
1111
const fn inherent_mutable_address_of_in_const() {
1212
let mut a = 0;
13-
let b = &raw mut a; //~ ERROR mutable reference
13+
let b = &raw mut a; //~ ERROR mutable pointer
1414
}
1515
}
1616

tests/ui/consts/min_const_fn/address_of.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: raw mutable references are not allowed in constant functions
1+
error[E0658]: raw mutable pointers are not allowed in constant functions
22
--> $DIR/address_of.rs:5:13
33
|
44
LL | let b = &raw mut a;
@@ -7,7 +7,7 @@ LL | let b = &raw mut a;
77
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
88
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
99

10-
error[E0658]: raw mutable references are not allowed in constant functions
10+
error[E0658]: raw mutable pointers are not allowed in constant functions
1111
--> $DIR/address_of.rs:13:17
1212
|
1313
LL | let b = &raw mut a;

0 commit comments

Comments
 (0)