From 3ef863bfdfb9173a0ad55d24e20202948dda6bbe Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 2 Jul 2018 19:00:07 +0200 Subject: Place unions, pointer casts and pointer derefs behind extra feature gates --- src/libsyntax/feature_gate.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/libsyntax') diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index a3822a4a1f9..5ae9ae7f404 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -216,6 +216,15 @@ declare_features! ( // Allows let bindings and destructuring in `const fn` functions and constants. (active, const_let, "1.22.1", Some(48821), None), + // Allows accessing fields of unions inside const fn + (active, const_fn_union, "1.27.0", Some(51909), None), + + // Allows casting raw pointers to `usize` during const eval + (active, const_raw_ptr_to_usize_cast, "1.27.0", Some(51910), None), + + // Allows dereferencing raw pointers during const eval + (active, const_raw_ptr_deref, "1.27.0", Some(51911), None), + // Allows using #[prelude_import] on glob `use` items. // // rustc internal -- cgit 1.4.1-3-g733a5 From 36907fc18d10b05d8b7a7383a4f0ecab9b431845 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 3 Aug 2018 11:12:10 +0200 Subject: Also put comparing raw pointers behind a feature gate --- src/librustc_mir/diagnostics.rs | 30 ---------------------------- src/librustc_mir/transform/qualify_consts.rs | 13 ++++++------ src/libsyntax/feature_gate.rs | 3 +++ src/test/ui/error-codes/E0395.rs | 2 +- src/test/ui/error-codes/E0395.stderr | 10 ++++++---- src/test/ui/issue-25826.rs | 2 +- src/test/ui/issue-25826.stderr | 8 +++++--- 7 files changed, 22 insertions(+), 46 deletions(-) (limited to 'src/libsyntax') 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 } 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 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:: 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`. -- cgit 1.4.1-3-g733a5