Skip to content

Commit d2b0d0c

Browse files
committed
raw pointers are not references
1 parent 7dd47c9 commit d2b0d0c

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

compiler/rustc_const_eval/messages.ftl

+3-3
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
@@ -360,8 +360,8 @@ const_eval_unallowed_mutable_refs =
360360
361361
If you really want global mutable state, try using static mut or a global UnsafeCell.
362362
363-
const_eval_unallowed_mutable_refs_raw =
364-
raw mutable references are not allowed in the final value of {const_eval_const_context}s
363+
const_eval_unallowed_mutable_raw =
364+
raw mutable pointers are not allowed in the final value of {const_eval_const_context}s
365365
.teach_note =
366366
References in statics and constants may only refer to immutable values.
367367

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
@@ -508,7 +508,7 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
508508
span: Span,
509509
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
510510
match self.0 {
511-
hir::BorrowKind::Raw => ccx.tcx.sess.create_err(errors::UnallowedMutableRefsRaw {
511+
hir::BorrowKind::Raw => ccx.tcx.sess.create_err(errors::UnallowedMutableRaw {
512512
span,
513513
kind: ccx.const_kind(),
514514
teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()),
@@ -537,10 +537,10 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
537537
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
538538
let kind = ccx.const_kind();
539539
match self.0 {
540-
hir::BorrowKind::Raw => ccx.tcx.sess.create_feature_err(
541-
errors::TransientMutBorrowErrRaw { span, kind },
542-
sym::const_mut_refs,
543-
),
540+
hir::BorrowKind::Raw => ccx
541+
.tcx
542+
.sess
543+
.create_feature_err(errors::TransientMutRawErr { span, kind }, sym::const_mut_refs),
544544
hir::BorrowKind::Ref => ccx.tcx.sess.create_feature_err(
545545
errors::TransientMutBorrowErr { span, kind },
546546
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)