Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4428a05

Browse files
committedSep 26, 2024
Auto merge of #129759 - dingxiangfei2009:stabilize-const-refs-to-static, r=RalfJung
Stabilize `const_refs_to_static` Meanwhile, I am cooking a sub-section in the language reference.
2 parents f2becdf + 1576a6d commit 4428a05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+157
-442
lines changed
 

‎compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
317317
{
318318
self.error_emitted = Some(guar);
319319
}
320-
self.check_op_spanned(ops::StaticAccess, span)
321320
}
322321

323322
/// Returns whether this place can possibly escape the evaluation of the current const/static

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_middle::ty::{
1616
suggest_constraining_type_param,
1717
};
1818
use rustc_middle::util::{CallDesugaringKind, CallKind, call_kind};
19-
use rustc_session::parse::feature_err;
2019
use rustc_span::symbol::sym;
2120
use rustc_span::{BytePos, Pos, Span, Symbol};
2221
use rustc_trait_selection::traits::SelectionContext;
@@ -477,33 +476,6 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
477476
}
478477
}
479478

480-
/// An access to a (non-thread-local) `static`.
481-
#[derive(Debug)]
482-
pub(crate) struct StaticAccess;
483-
impl<'tcx> NonConstOp<'tcx> for StaticAccess {
484-
fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status {
485-
if let hir::ConstContext::Static(_) = ccx.const_kind() {
486-
Status::Allowed
487-
} else {
488-
Status::Unstable(sym::const_refs_to_static)
489-
}
490-
}
491-
492-
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
493-
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
494-
let mut err = feature_err(
495-
&ccx.tcx.sess,
496-
sym::const_refs_to_static,
497-
span,
498-
format!("referencing statics in {}s is unstable", ccx.const_kind(),),
499-
);
500-
err
501-
.note("`static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.")
502-
.help("to fix this, the value can be extracted to a `const` and then used.");
503-
err
504-
}
505-
}
506-
507479
/// An access to a thread-local `static`.
508480
#[derive(Debug)]
509481
pub(crate) struct ThreadLocalAccess;

0 commit comments

Comments
 (0)
Please sign in to comment.