]> git.lizzy.rs Git - rust.git/commitdiff
Add and update tests
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Mon, 19 Nov 2018 14:24:23 +0000 (15:24 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 4 Dec 2018 09:17:37 +0000 (10:17 +0100)
src/test/run-pass-fulldeps/newtype_index.rs
src/test/ui/consts/min_const_fn/min_const_fn.rs
src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs
src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr
src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs
src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.stderr
src/test/ui/unsafe/ranged_ints4_const.rs
src/test/ui/unsafe/ranged_ints4_const.stderr

index 4c5a21201d674707b7ff8418662c330880cc78cb..0fd7ccd55fb2dd76a765e7953519050178ad708e 100644 (file)
@@ -2,7 +2,6 @@
 
 #[macro_use] extern crate rustc_data_structures;
 extern crate rustc_serialize;
-use rustc_serialize::{Decodable, Decoder};
 
 use rustc_data_structures::indexed_vec::Idx;
 
index 0dba3a7de53781e83b2f10abff826e5fdcaa26b0..43ca9e75393095255de640fd75327cae146ab6c1 100644 (file)
@@ -78,9 +78,9 @@ const fn i32_ops2(c: i32, d: i32) -> bool { c < d }
 const fn i32_ops3(c: i32, d: i32) -> bool { c != d }
 const fn i32_ops4(c: i32, d: i32) -> i32 { c + d }
 const fn char_cast(u: u8) -> char { u as char }
-const unsafe fn foo4() -> i32 { 42 }
-const unsafe fn foo5<T>() -> *const T { 0 as *const T }
-const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
+const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
+const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { 0 as *const T }
+const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { 0 as *mut T }
 
 // not ok
 const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
index 02a357551df307a7a13c34a91e1d7496531441bb..f11b43dcd865ce54e407a2c7a5f537acebcdc818 100644 (file)
 // gate-test-min_const_unsafe_fn
 
 // ok
-const unsafe fn foo4() -> i32 { 42 }
-const unsafe fn foo5<T>() -> *const T { 0 as *const T }
-const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
+const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
+const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { 0 as *const T }
+const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { 0 as *mut T }
 const fn no_unsafe() { unsafe {} }
 
 // not ok
-const fn foo8() -> i32 {
-    unsafe { foo4() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
+const fn call_unsafe_const_fn() -> i32 {
+    unsafe { ret_i32_no_unsafe() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
 }
-const fn foo9() -> *const String {
-    unsafe { foo5::<String>() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
+const fn call_unsafe_generic_const_fn() -> *const String {
+    unsafe { ret_null_ptr_no_unsafe::<String>() }
+    //~^ ERROR calls to `const unsafe fn` in const fns are unstable
 }
-const fn foo10() -> *const Vec<std::cell::Cell<u32>> {
-    unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR calls to `const unsafe fn` in const fns
+const fn call_unsafe_generic_cell_const_fn() -> *const Vec<std::cell::Cell<u32>> {
+    unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() }
+    //~^ ERROR calls to `const unsafe fn` in const fns
 }
-const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
+const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
 //~^ dereferencing raw pointers in constant functions
 
 fn main() {}
index 0b8ff4717c128427049b44c7496549c8dc404c94..8d885545cde563913b0ada2222a6e0a3dc617a09 100644 (file)
@@ -1,13 +1,13 @@
 error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911)
-  --> $DIR/min_const_fn_unsafe.rs:29:51
+  --> $DIR/min_const_fn_unsafe.rs:31:59
    |
-LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
-   |                                                   ^^
+LL | const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
+   |                                                           ^^
    |
    = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
 
 error[E0658]: unions in const fn are unstable (see issue #51909)
-  --> $DIR/min_const_fn_unsafe.rs:36:5
+  --> $DIR/min_const_fn_unsafe.rs:38:5
    |
 LL |     Foo { x: () }.y //~ ERROR not allowed in const fn
    |     ^^^^^^^^^^^^^^^
@@ -17,37 +17,37 @@ LL |     Foo { x: () }.y //~ ERROR not allowed in const fn
 error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
   --> $DIR/min_const_fn_unsafe.rs:21:14
    |
-LL |     unsafe { foo4() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
-   |              ^^^^^^
+LL |     unsafe { ret_i32_no_unsafe() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
+   |              ^^^^^^^^^^^^^^^^^^^
    |
    = help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable
 
 error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
   --> $DIR/min_const_fn_unsafe.rs:24:14
    |
-LL |     unsafe { foo5::<String>() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
-   |              ^^^^^^^^^^^^^^^^
+LL |     unsafe { ret_null_ptr_no_unsafe::<String>() }
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable
 
 error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
-  --> $DIR/min_const_fn_unsafe.rs:27:14
+  --> $DIR/min_const_fn_unsafe.rs:28:14
    |
-LL |     unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR calls to `const unsafe fn` in const fns
-   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |     unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() }
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable
 
 error: dereference of raw pointer is unsafe and unsafe operations are not allowed in const fn
-  --> $DIR/min_const_fn_unsafe.rs:29:51
+  --> $DIR/min_const_fn_unsafe.rs:31:59
    |
-LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
-   |                                                   ^^ dereference of raw pointer
+LL | const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
+   |                                                           ^^ dereference of raw pointer
    |
    = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
 
 error: access to union field is unsafe and unsafe operations are not allowed in const fn
-  --> $DIR/min_const_fn_unsafe.rs:36:5
+  --> $DIR/min_const_fn_unsafe.rs:38:5
    |
 LL |     Foo { x: () }.y //~ ERROR not allowed in const fn
    |     ^^^^^^^^^^^^^^^ access to union field
index b66460d64089b4ce1c93fae4e9d55849bce625de..8a6884bc6b93c3207e5c09b4ff2cc942834c5cdb 100644 (file)
@@ -50,6 +50,9 @@ const fn foo10() -> *const Vec<std::cell::Cell<u32>> {
 const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR not allowed in const fn
 //~^ dereferencing raw pointers in constant functions
 
+const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ ERROR not allowed
+//~^ dereferencing raw pointers in constant functions
+
 fn main() {}
 
 const unsafe fn no_union() {
index d88ed1a5ad2cf2922c41e1eae0ca259c829213be..4336db65813b3e95753803e623fe8705bf3ccb7f 100644 (file)
@@ -14,8 +14,16 @@ LL | const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR
    |
    = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
 
+error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911)
+  --> $DIR/min_const_fn_unsafe_feature_gate.rs:53:62
+   |
+LL | const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ ERROR not allowed
+   |                                                              ^^^
+   |
+   = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
+
 error[E0658]: unions in const fn are unstable (see issue #51909)
-  --> $DIR/min_const_fn_unsafe_feature_gate.rs:57:5
+  --> $DIR/min_const_fn_unsafe_feature_gate.rs:60:5
    |
 LL |     Foo { x: () }.y //~ ERROR not allowed in const fn
    |     ^^^^^^^^^^^^^^^
@@ -62,14 +70,22 @@ LL | const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR
    |
    = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
 
+error: dereference of raw pointer is unsafe and unsafe operations are not allowed in const fn
+  --> $DIR/min_const_fn_unsafe_feature_gate.rs:53:62
+   |
+LL | const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ ERROR not allowed
+   |                                                              ^^^ dereference of raw pointer
+   |
+   = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
+
 error: access to union field is unsafe and unsafe operations are not allowed in const fn
-  --> $DIR/min_const_fn_unsafe_feature_gate.rs:57:5
+  --> $DIR/min_const_fn_unsafe_feature_gate.rs:60:5
    |
 LL |     Foo { x: () }.y //~ ERROR not allowed in const fn
    |     ^^^^^^^^^^^^^^^ access to union field
    |
    = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
 
-error: aborting due to 9 previous errors
+error: aborting due to 11 previous errors
 
 For more information about this error, try `rustc --explain E0658`.
index 09689579639e76193ada9ca543d38d6b513e0f51..f589e4739baf17145f7d3e09d0e1e68e086a95fb 100644 (file)
@@ -7,13 +7,13 @@ fn main() {}
 
 const fn foo() -> NonZero<u32> {
     let mut x = unsafe { NonZero(1) };
-    x.0 = 0; //~ ERROR statements in constant functions are unstable
+    x.0 = 0;
     //~^ ERROR mutation of layout constrained field is unsafe
     x
 }
 
 const fn bar() -> NonZero<u32> {
     let mut x = unsafe { NonZero(1) };
-    unsafe { x.0 = 0 }; //~ ERROR statements in constant functions are unstable
+    unsafe { x.0 = 0 }; // this is UB
     x
 }
index 284ba3603af2e3be222ad4251733c8a120f74a26..fe83b15ce5cec456b434aee6cf703a5c4ae52eeb 100644 (file)
@@ -1,28 +1,11 @@
-error[E0658]: statements in constant functions are unstable (see issue #48821)
-  --> $DIR/ranged_ints4_const.rs:10:5
-   |
-LL |     x.0 = 0; //~ ERROR statements in constant functions are unstable
-   |     ^^^^^^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in constant functions are unstable (see issue #48821)
-  --> $DIR/ranged_ints4_const.rs:17:14
-   |
-LL |     unsafe { x.0 = 0 }; //~ ERROR statements in constant functions are unstable
-   |              ^^^^^^^
-   |
-   = help: add #![feature(const_let)] to the crate attributes to enable
-
 error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
   --> $DIR/ranged_ints4_const.rs:10:5
    |
-LL |     x.0 = 0; //~ ERROR statements in constant functions are unstable
+LL |     x.0 = 0;
    |     ^^^^^^^ mutation of layout constrained field
    |
    = note: mutating layout constrained fields cannot statically be checked for valid values
 
-error: aborting due to 3 previous errors
+error: aborting due to previous error
 
-Some errors occurred: E0133, E0658.
-For more information about an error, try `rustc --explain E0133`.
+For more information about this error, try `rustc --explain E0133`.