about summary refs log tree commit diff
path: root/compiler/rustc_session/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-10-24 16:13:39 +0200
committerRalf Jung <post@ralfj.de>2020-10-24 16:15:42 +0200
commit1333206eb32a78ef6ffe0defd4acd164e47146b7 (patch)
tree1432bb73ab8de8e8f543c7f5ebb3b2de767f68bc /compiler/rustc_session/src
parent2e8a54af60df63034e41359acfc923e5c5769a91 (diff)
downloadrust-1333206eb32a78ef6ffe0defd4acd164e47146b7.tar.gz
rust-1333206eb32a78ef6ffe0defd4acd164e47146b7.zip
ensure that statics are inhabited
Diffstat (limited to 'compiler/rustc_session/src')
-rw-r--r--compiler/rustc_session/src/lint/builtin.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/compiler/rustc_session/src/lint/builtin.rs b/compiler/rustc_session/src/lint/builtin.rs
index fef3164de59..d12eb0edd4d 100644
--- a/compiler/rustc_session/src/lint/builtin.rs
+++ b/compiler/rustc_session/src/lint/builtin.rs
@@ -2647,6 +2647,35 @@ declare_lint! {
     };
 }
 
+declare_lint! {
+    /// The `uninhabited_static` lint detects uninhbaited statics.
+    ///
+    /// ### Example
+    ///
+    /// ```rust
+    /// enum Void {}
+    /// extern {
+    ///     static EXTERN: Void;
+    /// }
+    /// ```
+    ///
+    /// {{produces}}
+    ///
+    /// ### Explanation
+    ///
+    /// Statics with an uninhabited type can never be initialized, so they are impossible to define.
+    /// However, this can be side-stepped with an `extern static`, leading to problems later in the
+    /// compiler which assumes that there are no initialized uninhabited places (such as locals or
+    /// statics). This was accientally allowed, but is being phased out.
+    pub UNINHABITED_STATIC,
+    Warn,
+    "uninhabited static",
+    @future_incompatible = FutureIncompatibleInfo {
+        reference: "issue #74840 <https://github.com/rust-lang/rust/issues/74840>",
+        edition: None,
+    };
+}
+
 declare_tool_lint! {
     pub rustc::INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
     Deny,
@@ -2732,6 +2761,7 @@ declare_lint_pass! {
         CENUM_IMPL_DROP_CAST,
         CONST_EVALUATABLE_UNCHECKED,
         INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
+        UNINHABITED_STATIC,
     ]
 }