diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index e38b8633108c..3312cd78c547 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 7a724a2e3949..1a66a1751ffa 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 5ae9ae7f404a..a3090597096d 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 00008ea6b6f3..e8d1b0f54c1c 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 ee90df798706..90f9ab9ec364 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 00e1279d58a0..6b9caba0218f 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 } fn main() { const A: bool = id:: as *const () < id:: 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 fed9e8efa848..a5ab7cfa6d3c 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:: as *const () < id:: 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`.