diff options
| author | Ralf Jung <post@ralfj.de> | 2023-12-17 11:24:34 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-01-22 09:28:00 +0100 |
| commit | 0288a0bfa0f038350aaae224b6cdd7e440ea8408 (patch) | |
| tree | a17fb47acdff7992518684e27295e081418bed4f /compiler | |
| parent | 2f1a8e2d7a641a398e9e02c8c99e80f6e44dce87 (diff) | |
raw pointers are not references
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_const_eval/messages.ftl | 16 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/errors.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/check_consts/ops.rs | 10 |
3 files changed, 17 insertions, 17 deletions
diff --git a/compiler/rustc_const_eval/messages.ftl b/compiler/rustc_const_eval/messages.ftl index 2728d2ca463..e7e8b2b3600 100644 --- a/compiler/rustc_const_eval/messages.ftl +++ b/compiler/rustc_const_eval/messages.ftl @@ -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 @@ -351,21 +351,21 @@ const_eval_unallowed_heap_allocations = const_eval_unallowed_inline_asm = inline assembly is not allowed in {const_eval_const_context}s -const_eval_unallowed_mutable_refs = - 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. + + Statics are shared everywhere, and if they refer to mutable data one might violate memory safety since holding multiple mutable references to shared data is not allowed. 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_refs = + mutable references 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. - - Statics are shared everywhere, and if they refer to mutable data one might violate memory safety since holding multiple mutable references to shared data is not allowed. diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index c07db2773c1..4a654480ef5 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -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, @@ -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, diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 327c91731bf..39bc2b960e9 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -466,7 +466,7 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { match self.0 { - hir::BorrowKind::Raw => ccx.dcx().create_err(errors::UnallowedMutableRefsRaw { + hir::BorrowKind::Raw => ccx.tcx.dcx().create_err(errors::UnallowedMutableRaw { span, kind: ccx.const_kind(), teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()), @@ -491,10 +491,10 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { 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, |
