about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorOliver Schneider <github35764891676564198441@oli-obk.de>2018-08-03 11:12:10 +0200
committerOliver Schneider <github35764891676564198441@oli-obk.de>2018-08-07 14:41:33 +0200
commit36907fc18d10b05d8b7a7383a4f0ecab9b431845 (patch)
tree174c2ada9ffe6fb325f599e7e0033794a75aa449 /src
parent1fc7580a8e75020c486cd73ab3b149f0df2a6abd (diff)
downloadrust-36907fc18d10b05d8b7a7383a4f0ecab9b431845.tar.gz
rust-36907fc18d10b05d8b7a7383a4f0ecab9b431845.zip
Also put comparing raw pointers behind a feature gate
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/diagnostics.rs30
-rw-r--r--src/librustc_mir/transform/qualify_consts.rs13
-rw-r--r--src/libsyntax/feature_gate.rs3
-rw-r--r--src/test/ui/error-codes/E0395.rs2
-rw-r--r--src/test/ui/error-codes/E0395.stderr10
-rw-r--r--src/test/ui/issue-25826.rs2
-rw-r--r--src/test/ui/issue-25826.stderr8
7 files changed, 22 insertions, 46 deletions
diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs
index e38b8633108..3312cd78c54 100644
--- a/src/librustc_mir/diagnostics.rs
+++ b/src/librustc_mir/diagnostics.rs
@@ -1113,36 +1113,6 @@ fn main() {
 ```
 "##,
 
-E0395: r##"
-The value assigned to a constant scalar must be known at compile time,
-which is not the case when comparing raw pointers.
-
-Erroneous code example:
-
-```compile_fail,E0395
-static FOO: i32 = 42;
-static BAR: i32 = 42;
-
-static BAZ: bool = { (&FOO as *const i32) == (&BAR as *const i32) };
-// error: raw pointers cannot be compared in statics!
-```
-
-The address assigned by the linker to `FOO` and `BAR` may or may not
-be identical, so the value of `BAZ` can't be determined.
-
-If you want to do the comparison, please do it at run-time.
-
-For example:
-
-```
-static FOO: i32 = 42;
-static BAR: i32 = 42;
-
-let baz: bool = { (&FOO as *const i32) == (&BAR as *const i32) };
-// baz isn't a constant expression so it's ok
-```
-"##,
-
 E0161: r##"
 A value was moved. However, its size was not known at compile time, and only
 values of a known size can be moved.
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs
index 7a724a2e394..1a66a1751ff 100644
--- a/src/librustc_mir/transform/qualify_consts.rs
+++ b/src/librustc_mir/transform/qualify_consts.rs
@@ -752,14 +752,13 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
 
                     self.add(Qualif::NOT_CONST);
                     if self.mode != Mode::Fn {
-                        struct_span_err!(
-                            self.tcx.sess, self.span, E0395,
-                            "raw pointers cannot be compared in {}s",
-                            self.mode)
-                        .span_label(
+                        emit_feature_err(
+                            &self.tcx.sess.parse_sess,
+                            "const_compare_raw_pointers",
                             self.span,
-                            "comparing raw pointers in static")
-                        .emit();
+                            GateIssue::Language,
+                            &format!("comparing raw pointers inside {}", self.mode),
+                        );
                     }
                 }
             }
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 5ae9ae7f404..a3090597096 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -225,6 +225,9 @@ declare_features! (
     // Allows dereferencing raw pointers during const eval
     (active, const_raw_ptr_deref, "1.27.0", Some(51911), None),
 
+    // Allows comparing raw pointers during const eval
+    (active, const_compare_raw_pointers, "1.27.0", Some(53020), None),
+
     // Allows using #[prelude_import] on glob `use` items.
     //
     // rustc internal
diff --git a/src/test/ui/error-codes/E0395.rs b/src/test/ui/error-codes/E0395.rs
index 00008ea6b6f..e8d1b0f54c1 100644
--- a/src/test/ui/error-codes/E0395.rs
+++ b/src/test/ui/error-codes/E0395.rs
@@ -11,6 +11,6 @@
 static FOO: i32 = 42;
 static BAR: i32 = 42;
 
-static BAZ: bool = { (&FOO as *const i32) == (&BAR as *const i32) }; //~ ERROR E0395
+static BAZ: bool = { (&FOO as *const i32) == (&BAR as *const i32) }; //~ ERROR issue #53020
 fn main() {
 }
diff --git a/src/test/ui/error-codes/E0395.stderr b/src/test/ui/error-codes/E0395.stderr
index ee90df79870..90f9ab9ec36 100644
--- a/src/test/ui/error-codes/E0395.stderr
+++ b/src/test/ui/error-codes/E0395.stderr
@@ -1,9 +1,11 @@
-error[E0395]: raw pointers cannot be compared in statics
+error[E0658]: comparing raw pointers inside static (see issue #53020)
   --> $DIR/E0395.rs:14:22
    |
-LL | static BAZ: bool = { (&FOO as *const i32) == (&BAR as *const i32) }; //~ ERROR E0395
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comparing raw pointers in static
+LL | static BAZ: bool = { (&FOO as *const i32) == (&BAR as *const i32) }; //~ ERROR issue #53020
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: add #![feature(const_compare_raw_pointers)] to the crate attributes to enable
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0395`.
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/issue-25826.rs b/src/test/ui/issue-25826.rs
index 00e1279d58a..6b9caba0218 100644
--- a/src/test/ui/issue-25826.rs
+++ b/src/test/ui/issue-25826.rs
@@ -11,6 +11,6 @@
 fn id<T>(t: T) -> T { t }
 fn main() {
     const A: bool = id::<u8> as *const () < id::<u16> as *const ();
-    //~^ ERROR raw pointers cannot be compared in constants [E0395]
+    //~^ ERROR comparing raw pointers inside constant
     println!("{}", A);
 }
diff --git a/src/test/ui/issue-25826.stderr b/src/test/ui/issue-25826.stderr
index fed9e8efa84..a5ab7cfa6d3 100644
--- a/src/test/ui/issue-25826.stderr
+++ b/src/test/ui/issue-25826.stderr
@@ -1,9 +1,11 @@
-error[E0395]: raw pointers cannot be compared in constants
+error[E0658]: comparing raw pointers inside constant (see issue #53020)
   --> $DIR/issue-25826.rs:13:21
    |
 LL |     const A: bool = id::<u8> as *const () < id::<u16> as *const ();
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comparing raw pointers in static
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: add #![feature(const_compare_raw_pointers)] to the crate attributes to enable
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0395`.
+For more information about this error, try `rustc --explain E0658`.