Skip to content

Commit

Permalink
raw pointers are not references
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 17, 2023
1 parent 7dd47c9 commit d2b0d0c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ const_eval_too_many_caller_args =
const_eval_transient_mut_borrow = mutable references are not allowed in {const_eval_const_context}s
const_eval_transient_mut_borrow_raw = raw mutable references are not allowed in {const_eval_const_context}s
const_eval_transient_mut_raw = raw mutable pointers are not allowed in {const_eval_const_context}s
const_eval_try_block_from_output_non_const =
`try` block cannot convert `{$ty}` to the result in {const_eval_const_context}s
Expand All @@ -360,8 +360,8 @@ const_eval_unallowed_mutable_refs =
If you really want global mutable state, try using static mut or a global UnsafeCell.
const_eval_unallowed_mutable_refs_raw =
raw mutable references are not allowed in the final value of {const_eval_const_context}s
const_eval_unallowed_mutable_raw =
raw mutable pointers are not allowed in the final value of {const_eval_const_context}s
.teach_note =
References in statics and constants may only refer to immutable values.
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ pub(crate) struct TransientMutBorrowErr {
}

#[derive(Diagnostic)]
#[diag(const_eval_transient_mut_borrow_raw, code = "E0658")]
pub(crate) struct TransientMutBorrowErrRaw {
#[diag(const_eval_transient_mut_raw, code = "E0658")]
pub(crate) struct TransientMutRawErr {
#[primary_span]
pub span: Span,
pub kind: ConstContext,
Expand Down Expand Up @@ -156,8 +156,8 @@ pub(crate) struct UnallowedMutableRefs {
}

#[derive(Diagnostic)]
#[diag(const_eval_unallowed_mutable_refs_raw, code = "E0764")]
pub(crate) struct UnallowedMutableRefsRaw {
#[diag(const_eval_unallowed_mutable_raw, code = "E0764")]
pub(crate) struct UnallowedMutableRaw {
#[primary_span]
pub span: Span,
pub kind: ConstContext,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
match self.0 {
hir::BorrowKind::Raw => ccx.tcx.sess.create_err(errors::UnallowedMutableRefsRaw {
hir::BorrowKind::Raw => ccx.tcx.sess.create_err(errors::UnallowedMutableRaw {
span,
kind: ccx.const_kind(),
teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()),
Expand Down Expand Up @@ -537,10 +537,10 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let kind = ccx.const_kind();
match self.0 {
hir::BorrowKind::Raw => ccx.tcx.sess.create_feature_err(
errors::TransientMutBorrowErrRaw { span, kind },
sym::const_mut_refs,
),
hir::BorrowKind::Raw => ccx
.tcx
.sess
.create_feature_err(errors::TransientMutRawErr { span, kind }, sym::const_mut_refs),
hir::BorrowKind::Ref => ccx.tcx.sess.create_feature_err(
errors::TransientMutBorrowErr { span, kind },
sym::const_mut_refs,
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/consts/const-address-of-mut.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![feature(raw_ref_op)]

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

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

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

const fn foo() {
let mut x = 0;
let y = &raw mut x; //~ mutable reference
let y = &raw mut x; //~ mutable pointer
}

fn main() {}
8 changes: 4 additions & 4 deletions tests/ui/consts/const-address-of-mut.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0658]: raw mutable references are not allowed in constants
error[E0658]: raw mutable pointers are not allowed in constants
--> $DIR/const-address-of-mut.rs:3:32
|
LL | const A: () = { let mut x = 2; &raw mut x; };
Expand All @@ -7,7 +7,7 @@ LL | const A: () = { let mut x = 2; &raw mut x; };
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable

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

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

error[E0658]: raw mutable references are not allowed in constant functions
error[E0658]: raw mutable pointers are not allowed in constant functions
--> $DIR/const-address-of-mut.rs:11:13
|
LL | let y = &raw mut x;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/min_const_fn/address_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

const fn mutable_address_of_in_const() {
let mut a = 0;
let b = &raw mut a; //~ ERROR mutable reference
let b = &raw mut a; //~ ERROR mutable pointer
}

struct X;

impl X {
const fn inherent_mutable_address_of_in_const() {
let mut a = 0;
let b = &raw mut a; //~ ERROR mutable reference
let b = &raw mut a; //~ ERROR mutable pointer
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/min_const_fn/address_of.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0658]: raw mutable references are not allowed in constant functions
error[E0658]: raw mutable pointers are not allowed in constant functions
--> $DIR/address_of.rs:5:13
|
LL | let b = &raw mut a;
Expand All @@ -7,7 +7,7 @@ LL | let b = &raw mut a;
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable

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

0 comments on commit d2b0d0c

Please sign in to comment.