about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-09-26 13:36:03 +0000
committerbors <bors@rust-lang.org>2024-09-26 13:36:03 +0000
commit4428a051679ec6194a118424f4616d922249a1e6 (patch)
tree7bb80ed4191d62d4e00ab509fb56a1b557715165 /compiler
parentf2becdff0496003217e7fc6fbfcaf2640e162775 (diff)
parent1576a6d618a7584659be5d4d770324d5537c0d26 (diff)
downloadrust-4428a051679ec6194a118424f4616d922249a1e6.tar.gz
rust-4428a051679ec6194a118424f4616d922249a1e6.zip
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.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_const_eval/src/check_consts/check.rs1
-rw-r--r--compiler/rustc_const_eval/src/check_consts/ops.rs28
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0013.md2
-rw-r--r--compiler/rustc_feature/src/accepted.rs2
-rw-r--r--compiler/rustc_feature/src/unstable.rs2
5 files changed, 3 insertions, 32 deletions
diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs
index e1b60597997..2cbf242fcf2 100644
--- a/compiler/rustc_const_eval/src/check_consts/check.rs
+++ b/compiler/rustc_const_eval/src/check_consts/check.rs
@@ -317,7 +317,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
         {
             self.error_emitted = Some(guar);
         }
-        self.check_op_spanned(ops::StaticAccess, span)
     }
 
     /// Returns whether this place can possibly escape the evaluation of the current const/static
diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs
index df8313d0e70..6eb33c29e1d 100644
--- a/compiler/rustc_const_eval/src/check_consts/ops.rs
+++ b/compiler/rustc_const_eval/src/check_consts/ops.rs
@@ -16,7 +16,6 @@ use rustc_middle::ty::{
     suggest_constraining_type_param,
 };
 use rustc_middle::util::{CallDesugaringKind, CallKind, call_kind};
-use rustc_session::parse::feature_err;
 use rustc_span::symbol::sym;
 use rustc_span::{BytePos, Pos, Span, Symbol};
 use rustc_trait_selection::traits::SelectionContext;
@@ -477,33 +476,6 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
     }
 }
 
-/// An access to a (non-thread-local) `static`.
-#[derive(Debug)]
-pub(crate) struct StaticAccess;
-impl<'tcx> NonConstOp<'tcx> for StaticAccess {
-    fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status {
-        if let hir::ConstContext::Static(_) = ccx.const_kind() {
-            Status::Allowed
-        } else {
-            Status::Unstable(sym::const_refs_to_static)
-        }
-    }
-
-    #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
-    fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
-        let mut err = feature_err(
-            &ccx.tcx.sess,
-            sym::const_refs_to_static,
-            span,
-            format!("referencing statics in {}s is unstable", ccx.const_kind(),),
-        );
-        err
-            .note("`static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.")
-            .help("to fix this, the value can be extracted to a `const` and then used.");
-        err
-    }
-}
-
 /// An access to a thread-local `static`.
 #[derive(Debug)]
 pub(crate) struct ThreadLocalAccess;
diff --git a/compiler/rustc_error_codes/src/error_codes/E0013.md b/compiler/rustc_error_codes/src/error_codes/E0013.md
index 9f4848343ff..c4d65225ece 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0013.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0013.md
@@ -5,7 +5,7 @@ variable cannot refer to a static variable.
 
 Erroneous code example:
 
-```compile_fail,E0658
+```
 static X: i32 = 42;
 const Y: i32 = X;
 ```
diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs
index 70e92f545c6..5ff002dd7d2 100644
--- a/compiler/rustc_feature/src/accepted.rs
+++ b/compiler/rustc_feature/src/accepted.rs
@@ -151,6 +151,8 @@ declare_features! (
     (accepted, const_raw_ptr_deref, "1.58.0", Some(51911)),
     /// Allows references to types with interior mutability within constants
     (accepted, const_refs_to_cell, "CURRENT_RUSTC_VERSION", Some(80384)),
+    /// Allows creating pointers and references to `static` items in constants.
+    (accepted, const_refs_to_static, "CURRENT_RUSTC_VERSION", Some(119618)),
     /// Allows implementing `Copy` for closures where possible (RFC 2132).
     (accepted, copy_closures, "1.26.0", Some(44490)),
     /// Allows `crate` in paths.
diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs
index 63b4b272f76..91b072b56db 100644
--- a/compiler/rustc_feature/src/unstable.rs
+++ b/compiler/rustc_feature/src/unstable.rs
@@ -407,8 +407,6 @@ declare_features! (
     (unstable, const_for, "1.56.0", Some(87575)),
     /// Be more precise when looking for live drops in a const context.
     (unstable, const_precise_live_drops, "1.46.0", Some(73255)),
-    /// Allows creating pointers and references to `static` items in constants.
-    (unstable, const_refs_to_static, "1.78.0", Some(119618)),
     /// Allows `impl const Trait for T` syntax.
     (unstable, const_trait_impl, "1.42.0", Some(67792)),
     /// Allows the `?` operator in const contexts.