mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Add and update tests
This commit is contained in:
parent
137a640d61
commit
ae0b00cada
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#[macro_use] extern crate rustc_data_structures;
|
#[macro_use] extern crate rustc_data_structures;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
use rustc_serialize::{Decodable, Decoder};
|
|
||||||
|
|
||||||
use rustc_data_structures::indexed_vec::Idx;
|
use rustc_data_structures::indexed_vec::Idx;
|
||||||
|
|
||||||
|
@ -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_ops3(c: i32, d: i32) -> bool { c != d }
|
||||||
const fn i32_ops4(c: i32, d: i32) -> i32 { c + d }
|
const fn i32_ops4(c: i32, d: i32) -> i32 { c + d }
|
||||||
const fn char_cast(u: u8) -> char { u as char }
|
const fn char_cast(u: u8) -> char { u as char }
|
||||||
const unsafe fn foo4() -> i32 { 42 }
|
const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
|
||||||
const unsafe fn foo5<T>() -> *const T { 0 as *const T }
|
const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { 0 as *const T }
|
||||||
const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
|
const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { 0 as *mut T }
|
||||||
|
|
||||||
// not ok
|
// not ok
|
||||||
const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
|
const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
|
||||||
|
@ -11,22 +11,24 @@
|
|||||||
// gate-test-min_const_unsafe_fn
|
// gate-test-min_const_unsafe_fn
|
||||||
|
|
||||||
// ok
|
// ok
|
||||||
const unsafe fn foo4() -> i32 { 42 }
|
const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
|
||||||
const unsafe fn foo5<T>() -> *const T { 0 as *const T }
|
const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { 0 as *const T }
|
||||||
const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
|
const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { 0 as *mut T }
|
||||||
const fn no_unsafe() { unsafe {} }
|
const fn no_unsafe() { unsafe {} }
|
||||||
|
|
||||||
// not ok
|
// not ok
|
||||||
const fn foo8() -> i32 {
|
const fn call_unsafe_const_fn() -> i32 {
|
||||||
unsafe { foo4() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
|
unsafe { ret_i32_no_unsafe() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
|
||||||
}
|
}
|
||||||
const fn foo9() -> *const String {
|
const fn call_unsafe_generic_const_fn() -> *const String {
|
||||||
unsafe { foo5::<String>() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
|
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>> {
|
const fn call_unsafe_generic_cell_const_fn() -> *const Vec<std::cell::Cell<u32>> {
|
||||||
unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR calls to `const unsafe fn` in const fns
|
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
|
//~^ dereferencing raw pointers in constant functions
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911)
|
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
|
= help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
|
||||||
|
|
||||||
error[E0658]: unions in const fn are unstable (see issue #51909)
|
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
|
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)
|
error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
|
||||||
--> $DIR/min_const_fn_unsafe.rs:21:14
|
--> $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
|
= 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)
|
error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
|
||||||
--> $DIR/min_const_fn_unsafe.rs:24:14
|
--> $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
|
= 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)
|
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
|
= 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
|
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
|
LL | const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
|
||||||
| ^^ dereference of raw pointer
|
| ^^ 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
|
= 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
|
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
|
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
|
||||||
| ^^^^^^^^^^^^^^^ access to union field
|
| ^^^^^^^^^^^^^^^ access to union field
|
||||||
|
@ -50,6 +50,9 @@ const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in
|
|||||||
const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR not allowed in const fn
|
const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR not allowed in const fn
|
||||||
//~^ dereferencing raw pointers in constant functions
|
//~^ 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() {}
|
fn main() {}
|
||||||
|
|
||||||
const unsafe fn no_union() {
|
const unsafe fn no_union() {
|
||||||
|
@ -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
|
= 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)
|
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
|
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
|
= 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
|
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
|
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
|
||||||
| ^^^^^^^^^^^^^^^ access to union field
|
| ^^^^^^^^^^^^^^^ access to union field
|
||||||
|
|
|
|
||||||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
|
= 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`.
|
For more information about this error, try `rustc --explain E0658`.
|
||||||
|
@ -7,13 +7,13 @@ fn main() {}
|
|||||||
|
|
||||||
const fn foo() -> NonZero<u32> {
|
const fn foo() -> NonZero<u32> {
|
||||||
let mut x = unsafe { NonZero(1) };
|
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
|
//~^ ERROR mutation of layout constrained field is unsafe
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn bar() -> NonZero<u32> {
|
const fn bar() -> NonZero<u32> {
|
||||||
let mut x = unsafe { NonZero(1) };
|
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
|
x
|
||||||
}
|
}
|
||||||
|
@ -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
|
error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
|
||||||
--> $DIR/ranged_ints4_const.rs:10:5
|
--> $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
|
| ^^^^^^^ mutation of layout constrained field
|
||||||
|
|
|
|
||||||
= note: mutating layout constrained fields cannot statically be checked for valid values
|
= 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 this error, try `rustc --explain E0133`.
|
||||||
For more information about an error, try `rustc --explain E0133`.
|
|
||||||
|
Loading…
Reference in New Issue
Block a user