Skip to content

Commit

Permalink
update test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 28, 2020
1 parent 76240d7 commit 6a3a321
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/ub-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
//~^ ERROR it is undefined behavior to use this value

const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute(&[&0] as &[_]) };
//~^ ERROR it is undefined behavior to use this value

const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/consts/const-eval/ub-ref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref.rs:29:1
|
LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<deref>, but expected plain (non-pointer) bytes
LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute(&[&0] as &[_]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<deref>, but expected plain (non-pointer) bytes
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// run-pass

#![allow(unused)]
#![allow(unused, incomplete_features)]
#![feature(const_in_array_repeat_expressions)]
#![feature(inline_const)]

// Some type that is not copyable.
struct Bar;
Expand All @@ -16,8 +17,6 @@ const fn type_copy() -> u32 {

const _: [u32; 2] = [type_copy(); 2];

// This is allowed because all promotion contexts use the explicit rules for promotability when
// inside an explicit const context.
const _: [Option<Bar>; 2] = [type_no_copy(); 2];
const _: [Option<Bar>; 2] = [const { type_no_copy() }; 2];

fn main() {}

0 comments on commit 6a3a321

Please sign in to comment.