diff options
| author | Ralf Jung <post@ralfj.de> | 2025-06-27 15:32:53 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-06-27 17:03:48 +0200 |
| commit | d0fa0260ca410b5691a03237e7336bb09c135230 (patch) | |
| tree | 36bbbda6a73349ccbc9a4806f94177d3b91971f0 /compiler/rustc_const_eval | |
| parent | e61dd437f33b5a640e67dc3628397689c664c17f (diff) | |
| download | rust-d0fa0260ca410b5691a03237e7336bb09c135230.tar.gz rust-d0fa0260ca410b5691a03237e7336bb09c135230.zip | |
const checks: avoid 'top-level scope' terminology
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/messages.ftl | 28 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/check_consts/ops.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/errors.rs | 13 |
3 files changed, 19 insertions, 35 deletions
diff --git a/compiler/rustc_const_eval/messages.ftl b/compiler/rustc_const_eval/messages.ftl index 97b154ad142..94d1d7d388b 100644 --- a/compiler/rustc_const_eval/messages.ftl +++ b/compiler/rustc_const_eval/messages.ftl @@ -125,16 +125,11 @@ const_eval_incompatible_types = calling a function with argument of type {$callee_ty} passing data of type {$caller_ty} const_eval_interior_mutable_borrow_escaping = - interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a {const_eval_const_context} are not allowed - .label = this borrow of an interior mutable value refers to a lifetime-extended temporary - .help = to fix this, the value can be extracted to a separate `static` item and then referenced - .teach_note = - This creates a raw pointer to a temporary that has its lifetime extended to last for the entire program. - Lifetime-extended temporaries in constants and statics must be immutable. - This is to avoid accidentally creating shared mutable state. - - - If you really want global mutable state, try using an interior mutable `static` or a `static mut`. + interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed + .label = this borrow of an interior mutable value refers to such a temporary + .note = Temporaries in constants and statics can have their lifetime extended until the end of the program + .note2 = To avoid accidentally creating global mutable state, such temporaries must be immutable + .help = If you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut` const_eval_intern_kind = {$kind -> [static] static @@ -215,14 +210,11 @@ const_eval_modified_global = modifying a static's initial value from another static's initializer const_eval_mutable_borrow_escaping = - mutable borrows of lifetime-extended temporaries in the top-level scope of a {const_eval_const_context} are not allowed - .teach_note = - This creates a reference to a temporary that has its lifetime extended to last for the entire program. - Lifetime-extended temporaries in constants and statics must be immutable. - This is to avoid accidentally creating shared mutable state. - - - If you really want global mutable state, try using an interior mutable `static` or a `static mut`. + mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed + .label = this mutable borrow refers to such a temporary + .note = Temporaries in constants and statics can have their lifetime extended until the end of the program + .note2 = To avoid accidentally creating global mutable state, such temporaries must be immutable + .help = If you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut` const_eval_mutable_ptr_in_final = encountered mutable pointer in final value of {const_eval_intern_kind} diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index 02edff8f632..9c583a35f1b 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -567,12 +567,7 @@ impl<'tcx> NonConstOp<'tcx> for EscapingCellBorrow { DiagImportance::Secondary } fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { - ccx.dcx().create_err(errors::InteriorMutableBorrowEscaping { - span, - opt_help: matches!(ccx.const_kind(), hir::ConstContext::Static(_)), - kind: ccx.const_kind(), - teach: ccx.tcx.sess.teach(E0492), - }) + ccx.dcx().create_err(errors::InteriorMutableBorrowEscaping { span, kind: ccx.const_kind() }) } } @@ -594,11 +589,7 @@ impl<'tcx> NonConstOp<'tcx> for EscapingMutBorrow { } fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { - ccx.dcx().create_err(errors::MutableBorrowEscaping { - span, - kind: ccx.const_kind(), - teach: ccx.tcx.sess.teach(E0764), - }) + ccx.dcx().create_err(errors::MutableBorrowEscaping { span, kind: ccx.const_kind() }) } } diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index b2c3103c34a..14abdd8c98c 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -151,12 +151,14 @@ pub(crate) struct UnmarkedIntrinsicExposed { #[derive(Diagnostic)] #[diag(const_eval_mutable_borrow_escaping, code = E0764)] +#[note] +#[note(const_eval_note2)] +#[help] pub(crate) struct MutableBorrowEscaping { #[primary_span] + #[label] pub span: Span, pub kind: ConstContext, - #[note(const_eval_teach_note)] - pub teach: bool, } #[derive(Diagnostic)] @@ -217,15 +219,14 @@ pub(crate) struct UnallowedInlineAsm { #[derive(Diagnostic)] #[diag(const_eval_interior_mutable_borrow_escaping, code = E0492)] +#[note] +#[note(const_eval_note2)] +#[help] pub(crate) struct InteriorMutableBorrowEscaping { #[primary_span] #[label] pub span: Span, - #[help] - pub opt_help: bool, pub kind: ConstContext, - #[note(const_eval_teach_note)] - pub teach: bool, } #[derive(LintDiagnostic)] |
