From: Oliver Scherer Date: Mon, 19 Nov 2018 14:24:23 +0000 (+0100) Subject: Add and update tests X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=ae0b00cadace32fd85c6786df24a20d6b55a87d2;p=rust.git Add and update tests --- diff --git a/src/test/run-pass-fulldeps/newtype_index.rs b/src/test/run-pass-fulldeps/newtype_index.rs index 4c5a21201d6..0fd7ccd55fb 100644 --- a/src/test/run-pass-fulldeps/newtype_index.rs +++ b/src/test/run-pass-fulldeps/newtype_index.rs @@ -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; diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.rs b/src/test/ui/consts/min_const_fn/min_const_fn.rs index 0dba3a7de53..43ca9e75393 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn.rs +++ b/src/test/ui/consts/min_const_fn/min_const_fn.rs @@ -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() -> *const T { 0 as *const T } -const unsafe fn foo6() -> *mut T { 0 as *mut T } +const unsafe fn ret_i32_no_unsafe() -> i32 { 42 } +const unsafe fn ret_null_ptr_no_unsafe() -> *const T { 0 as *const T } +const unsafe fn ret_null_mut_ptr_no_unsafe() -> *mut T { 0 as *mut T } // not ok const fn foo11(t: T) -> T { t } diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs index 02a357551df..f11b43dcd86 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs +++ b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs @@ -11,22 +11,24 @@ // gate-test-min_const_unsafe_fn // ok -const unsafe fn foo4() -> i32 { 42 } -const unsafe fn foo5() -> *const T { 0 as *const T } -const unsafe fn foo6() -> *mut T { 0 as *mut T } +const unsafe fn ret_i32_no_unsafe() -> i32 { 42 } +const unsafe fn ret_null_ptr_no_unsafe() -> *const T { 0 as *const T } +const unsafe fn ret_null_mut_ptr_no_unsafe() -> *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::() } //~ 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::() } + //~^ ERROR calls to `const unsafe fn` in const fns are unstable } -const fn foo10() -> *const Vec> { - unsafe { foo6::>>() } //~ ERROR calls to `const unsafe fn` in const fns +const fn call_unsafe_generic_cell_const_fn() -> *const Vec> { + unsafe { ret_null_mut_ptr_no_unsafe::>>() } + //~^ 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() {} diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr index 0b8ff4717c1..8d885545cde 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr @@ -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::() } //~ ERROR calls to `const unsafe fn` in const fns are unstable - | ^^^^^^^^^^^^^^^^ +LL | unsafe { ret_null_ptr_no_unsafe::() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = 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::>>() } //~ ERROR calls to `const unsafe fn` in const fns - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | unsafe { ret_null_mut_ptr_no_unsafe::>>() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = 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 diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs index b66460d6408..8a6884bc6b9 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs +++ b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs @@ -50,6 +50,9 @@ const fn foo10() -> *const Vec> { 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() { diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.stderr index d88ed1a5ad2..4336db65813 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.stderr @@ -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`. diff --git a/src/test/ui/unsafe/ranged_ints4_const.rs b/src/test/ui/unsafe/ranged_ints4_const.rs index 09689579639..f589e4739ba 100644 --- a/src/test/ui/unsafe/ranged_ints4_const.rs +++ b/src/test/ui/unsafe/ranged_ints4_const.rs @@ -7,13 +7,13 @@ fn main() {} const fn foo() -> NonZero { 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 { 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 } diff --git a/src/test/ui/unsafe/ranged_ints4_const.stderr b/src/test/ui/unsafe/ranged_ints4_const.stderr index 284ba3603af..fe83b15ce5c 100644 --- a/src/test/ui/unsafe/ranged_ints4_const.stderr +++ b/src/test/ui/unsafe/ranged_ints4_const.stderr @@ -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`.