Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Jul 27, 2021
1 parent 7bf791d commit 37af399
Show file tree
Hide file tree
Showing 34 changed files with 127 additions and 455 deletions.
2 changes: 1 addition & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
#![feature(const_cstr_unchecked)]
#![feature(const_fn_floating_point_arithmetic)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_fn_transmute)]
#![cfg_attr(bootstrap, feature(const_fn_transmute))]
#![feature(const_io_structs)]
#![feature(const_ip)]
#![feature(const_ipv4)]
Expand Down
4 changes: 1 addition & 3 deletions src/test/mir-opt/issues/issue-75439.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// EMIT_MIR issue_75439.foo.MatchBranchSimplification.diff

#![feature(const_fn_transmute)]

use std::mem::transmute;

pub fn foo(bytes: [u8; 16]) -> Option<[u8; 4]> {
Expand All @@ -16,5 +14,5 @@ pub fn foo(bytes: [u8; 16]) -> Option<[u8; 4]> {
}

fn main() {
let _ = foo([0; 16]);
let _ = foo([0; 16]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
+ // MIR for `foo` after MatchBranchSimplification

fn foo(_1: [u8; 16]) -> Option<[u8; 4]> {
debug bytes => _1; // in scope 0 at $DIR/issue-75439.rs:7:12: 7:17
let mut _0: std::option::Option<[u8; 4]>; // return place in scope 0 at $DIR/issue-75439.rs:7:32: 7:47
let _2: [u32; 4]; // in scope 0 at $DIR/issue-75439.rs:9:9: 9:15
let mut _3: [u8; 16]; // in scope 0 at $DIR/issue-75439.rs:9:47: 9:52
let mut _5: [u8; 4]; // in scope 0 at $DIR/issue-75439.rs:12:14: 12:38
let mut _6: u32; // in scope 0 at $DIR/issue-75439.rs:12:33: 12:35
debug bytes => _1; // in scope 0 at $DIR/issue-75439.rs:5:12: 5:17
let mut _0: std::option::Option<[u8; 4]>; // return place in scope 0 at $DIR/issue-75439.rs:5:32: 5:47
let _2: [u32; 4]; // in scope 0 at $DIR/issue-75439.rs:7:9: 7:15
let mut _3: [u8; 16]; // in scope 0 at $DIR/issue-75439.rs:7:47: 7:52
let mut _5: [u8; 4]; // in scope 0 at $DIR/issue-75439.rs:10:14: 10:38
let mut _6: u32; // in scope 0 at $DIR/issue-75439.rs:10:33: 10:35
scope 1 {
debug dwords => _2; // in scope 1 at $DIR/issue-75439.rs:9:9: 9:15
let _4: u32; // in scope 1 at $DIR/issue-75439.rs:11:27: 11:29
debug dwords => _2; // in scope 1 at $DIR/issue-75439.rs:7:9: 7:15
let _4: u32; // in scope 1 at $DIR/issue-75439.rs:9:27: 9:29
scope 3 {
debug ip => _4; // in scope 3 at $DIR/issue-75439.rs:11:27: 11:29
debug ip => _4; // in scope 3 at $DIR/issue-75439.rs:9:27: 9:29
scope 4 {
}
}
Expand All @@ -21,67 +21,67 @@
}

bb0: {
StorageLive(_2); // scope 0 at $DIR/issue-75439.rs:9:9: 9:15
StorageLive(_3); // scope 2 at $DIR/issue-75439.rs:9:47: 9:52
_3 = _1; // scope 2 at $DIR/issue-75439.rs:9:47: 9:52
_2 = transmute::<[u8; 16], [u32; 4]>(move _3) -> bb1; // scope 2 at $DIR/issue-75439.rs:9:37: 9:53
StorageLive(_2); // scope 0 at $DIR/issue-75439.rs:7:9: 7:15
StorageLive(_3); // scope 2 at $DIR/issue-75439.rs:7:47: 7:52
_3 = _1; // scope 2 at $DIR/issue-75439.rs:7:47: 7:52
_2 = transmute::<[u8; 16], [u32; 4]>(move _3) -> bb1; // scope 2 at $DIR/issue-75439.rs:7:37: 7:53
// mir::Constant
// + span: $DIR/issue-75439.rs:9:37: 9:46
// + span: $DIR/issue-75439.rs:7:37: 7:46
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn([u8; 16]) -> [u32; 4] {std::intrinsics::transmute::<[u8; 16], [u32; 4]>}, val: Value(Scalar(<ZST>)) }
}

bb1: {
StorageDead(_3); // scope 2 at $DIR/issue-75439.rs:9:52: 9:53
switchInt(_2[0 of 4]) -> [0_u32: bb2, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:11:13: 11:14
StorageDead(_3); // scope 2 at $DIR/issue-75439.rs:7:52: 7:53
switchInt(_2[0 of 4]) -> [0_u32: bb2, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:13: 9:14
}

bb2: {
switchInt(_2[1 of 4]) -> [0_u32: bb3, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:11:16: 11:17
switchInt(_2[1 of 4]) -> [0_u32: bb3, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:16: 9:17
}

bb3: {
switchInt(_2[2 of 4]) -> [0_u32: bb6, 4294901760_u32: bb7, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:11:19: 11:20
switchInt(_2[2 of 4]) -> [0_u32: bb6, 4294901760_u32: bb7, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:19: 9:20
}

bb4: {
discriminant(_0) = 0; // scope 1 at $DIR/issue-75439.rs:14:9: 14:13
goto -> bb9; // scope 1 at $DIR/issue-75439.rs:11:5: 15:6
discriminant(_0) = 0; // scope 1 at $DIR/issue-75439.rs:12:9: 12:13
goto -> bb9; // scope 1 at $DIR/issue-75439.rs:9:5: 13:6
}

bb5: {
StorageLive(_5); // scope 3 at $DIR/issue-75439.rs:12:14: 12:38
StorageLive(_6); // scope 4 at $DIR/issue-75439.rs:12:33: 12:35
_6 = _4; // scope 4 at $DIR/issue-75439.rs:12:33: 12:35
_5 = transmute::<u32, [u8; 4]>(move _6) -> bb8; // scope 4 at $DIR/issue-75439.rs:12:23: 12:36
StorageLive(_5); // scope 3 at $DIR/issue-75439.rs:10:14: 10:38
StorageLive(_6); // scope 4 at $DIR/issue-75439.rs:10:33: 10:35
_6 = _4; // scope 4 at $DIR/issue-75439.rs:10:33: 10:35
_5 = transmute::<u32, [u8; 4]>(move _6) -> bb8; // scope 4 at $DIR/issue-75439.rs:10:23: 10:36
// mir::Constant
// + span: $DIR/issue-75439.rs:12:23: 12:32
// + span: $DIR/issue-75439.rs:10:23: 10:32
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u32) -> [u8; 4] {std::intrinsics::transmute::<u32, [u8; 4]>}, val: Value(Scalar(<ZST>)) }
}

bb6: {
StorageLive(_4); // scope 1 at $DIR/issue-75439.rs:11:27: 11:29
_4 = _2[3 of 4]; // scope 1 at $DIR/issue-75439.rs:11:27: 11:29
goto -> bb5; // scope 1 at $DIR/issue-75439.rs:11:5: 15:6
StorageLive(_4); // scope 1 at $DIR/issue-75439.rs:9:27: 9:29
_4 = _2[3 of 4]; // scope 1 at $DIR/issue-75439.rs:9:27: 9:29
goto -> bb5; // scope 1 at $DIR/issue-75439.rs:9:5: 13:6
}

bb7: {
StorageLive(_4); // scope 1 at $DIR/issue-75439.rs:11:27: 11:29
_4 = _2[3 of 4]; // scope 1 at $DIR/issue-75439.rs:11:27: 11:29
goto -> bb5; // scope 1 at $DIR/issue-75439.rs:11:5: 15:6
StorageLive(_4); // scope 1 at $DIR/issue-75439.rs:9:27: 9:29
_4 = _2[3 of 4]; // scope 1 at $DIR/issue-75439.rs:9:27: 9:29
goto -> bb5; // scope 1 at $DIR/issue-75439.rs:9:5: 13:6
}

bb8: {
StorageDead(_6); // scope 4 at $DIR/issue-75439.rs:12:35: 12:36
((_0 as Some).0: [u8; 4]) = move _5; // scope 3 at $DIR/issue-75439.rs:12:9: 12:39
discriminant(_0) = 1; // scope 3 at $DIR/issue-75439.rs:12:9: 12:39
StorageDead(_5); // scope 3 at $DIR/issue-75439.rs:12:38: 12:39
StorageDead(_4); // scope 1 at $DIR/issue-75439.rs:13:5: 13:6
goto -> bb9; // scope 1 at $DIR/issue-75439.rs:11:5: 15:6
StorageDead(_6); // scope 4 at $DIR/issue-75439.rs:10:35: 10:36
((_0 as Some).0: [u8; 4]) = move _5; // scope 3 at $DIR/issue-75439.rs:10:9: 10:39
discriminant(_0) = 1; // scope 3 at $DIR/issue-75439.rs:10:9: 10:39
StorageDead(_5); // scope 3 at $DIR/issue-75439.rs:10:38: 10:39
StorageDead(_4); // scope 1 at $DIR/issue-75439.rs:11:5: 11:6
goto -> bb9; // scope 1 at $DIR/issue-75439.rs:9:5: 13:6
}

bb9: {
StorageDead(_2); // scope 0 at $DIR/issue-75439.rs:16:1: 16:2
return; // scope 0 at $DIR/issue-75439.rs:16:2: 16:2
StorageDead(_2); // scope 0 at $DIR/issue-75439.rs:14:1: 14:2
return; // scope 0 at $DIR/issue-75439.rs:14:2: 14:2
}
}

1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/const_transmute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-pass

#![feature(const_fn_union)]
#![allow(dead_code)]

#[repr(C)]
Expand Down
11 changes: 0 additions & 11 deletions src/test/ui/consts/const-eval/feature-gate-const_fn_union.rs

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/ui/consts/const-eval/feature-gate-const_fn_union.stderr

This file was deleted.

1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/issue-49296.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// issue-49296: Unsafe shenigans in constants can result in missing errors

#![feature(const_fn_union)]
#![feature(const_fn_trait_bound)]

const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/issue-49296.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0080]: evaluation of constant value failed
--> $DIR/issue-49296.rs:19:16
--> $DIR/issue-49296.rs:18:16
|
LL | const X: u64 = *wat(42);
| ^^^^^^^^ pointer to alloc2 was dereferenced after this allocation got freed
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/consts/const-eval/promoted_const_fn_fail.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(const_fn_union)]

#![allow(const_err)]

#[repr(C)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/promoted_const_fn_fail.rs:21:27
--> $DIR/promoted_const_fn_fail.rs:19:27
|
LL | let x: &'static u8 = &(bar() + 1);
| ----------- ^^^^^^^^^^^ creates a temporary which is freed while still in use
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(const_fn_union)]

#![deny(const_err)]

#[repr(C)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:22:27
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:20:27
|
LL | let x: &'static u8 = &(bar() + 1);
| ----------- ^^^^^^^^^^^ creates a temporary which is freed while still in use
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/consts/const-eval/ref_to_int_match.32bit.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/ref_to_int_match.rs:26:1
--> $DIR/ref_to_int_match.rs:25:1
|
LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc3, but expected initialized plain (non-pointer) bytes
Expand All @@ -10,13 +10,13 @@ LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
}

error: could not evaluate constant pattern
--> $DIR/ref_to_int_match.rs:8:14
--> $DIR/ref_to_int_match.rs:7:14
|
LL | 10..=BAR => {},
| ^^^

error: could not evaluate constant pattern
--> $DIR/ref_to_int_match.rs:8:14
--> $DIR/ref_to_int_match.rs:7:14
|
LL | 10..=BAR => {},
| ^^^
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/consts/const-eval/ref_to_int_match.64bit.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/ref_to_int_match.rs:26:1
--> $DIR/ref_to_int_match.rs:25:1
|
LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc3, but expected initialized plain (non-pointer) bytes
Expand All @@ -10,13 +10,13 @@ LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
}

error: could not evaluate constant pattern
--> $DIR/ref_to_int_match.rs:8:14
--> $DIR/ref_to_int_match.rs:7:14
|
LL | 10..=BAR => {},
| ^^^

error: could not evaluate constant pattern
--> $DIR/ref_to_int_match.rs:8:14
--> $DIR/ref_to_int_match.rs:7:14
|
LL | 10..=BAR => {},
| ^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/ref_to_int_match.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// stderr-per-bitwidth
#![feature(const_fn_union)]

fn main() {
let n: Int = 40;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0080]: evaluation of constant value failed
--> $DIR/validate_uninhabited_zsts.rs:5:14
--> $DIR/validate_uninhabited_zsts.rs:4:14
|
LL | unsafe { std::mem::transmute(()) }
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| transmuting to uninhabited type
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:5:14
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:4:14
...
LL | const FOO: [Empty; 3] = [foo(); 3];
| ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:14:26
| ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:13:26

error[E0080]: it is undefined behavior to use this value
--> $DIR/validate_uninhabited_zsts.rs:17:1
--> $DIR/validate_uninhabited_zsts.rs:16:1
|
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at [0]: encountered a value of uninhabited type Empty
Expand All @@ -20,7 +20,7 @@ LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
= note: the raw bytes of the constant (size: 0, align: 1) {}

warning: the type `!` does not permit zero-initialization
--> $DIR/validate_uninhabited_zsts.rs:5:14
--> $DIR/validate_uninhabited_zsts.rs:4:14
|
LL | unsafe { std::mem::transmute(()) }
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -32,7 +32,7 @@ LL | unsafe { std::mem::transmute(()) }
= note: the `!` type has no valid value

warning: the type `Empty` does not permit zero-initialization
--> $DIR/validate_uninhabited_zsts.rs:17:35
--> $DIR/validate_uninhabited_zsts.rs:16:35
|
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0080]: evaluation of constant value failed
--> $DIR/validate_uninhabited_zsts.rs:5:14
--> $DIR/validate_uninhabited_zsts.rs:4:14
|
LL | unsafe { std::mem::transmute(()) }
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| transmuting to uninhabited type
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:5:14
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:4:14
...
LL | const FOO: [Empty; 3] = [foo(); 3];
| ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:14:26
| ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:13:26

error[E0080]: it is undefined behavior to use this value
--> $DIR/validate_uninhabited_zsts.rs:17:1
--> $DIR/validate_uninhabited_zsts.rs:16:1
|
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at [0]: encountered a value of uninhabited type Empty
Expand All @@ -20,7 +20,7 @@ LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
= note: the raw bytes of the constant (size: 0, align: 1) {}

warning: the type `!` does not permit zero-initialization
--> $DIR/validate_uninhabited_zsts.rs:5:14
--> $DIR/validate_uninhabited_zsts.rs:4:14
|
LL | unsafe { std::mem::transmute(()) }
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -32,7 +32,7 @@ LL | unsafe { std::mem::transmute(()) }
= note: the `!` type has no valid value

warning: the type `Empty` does not permit zero-initialization
--> $DIR/validate_uninhabited_zsts.rs:17:35
--> $DIR/validate_uninhabited_zsts.rs:16:35
|
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// stderr-per-bitwidth
#![feature(const_fn_transmute)]

const fn foo() -> ! {
unsafe { std::mem::transmute(()) }
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/consts/const-fn-not-safe-for-const.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Test that we can't call random fns in a const fn or do other bad things.

#![feature(const_fn_transmute)]

use std::mem::transmute;

fn random() -> u32 { 0 }
fn random() -> u32 {
0
}

const fn sub(x: &u32) -> usize {
unsafe { transmute(x) }
Expand All @@ -18,12 +18,12 @@ static Y: u32 = 0;

const fn get_Y() -> u32 {
Y
//~^ ERROR E0013
//~^ ERROR E0013
}

const fn get_Y_addr() -> &'static u32 {
&Y
//~^ ERROR E0013
//~^ ERROR E0013
}

const fn get() -> u32 {
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/issue-69532.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// run-pass
#![feature(const_fn_transmute)]

const fn make_nans() -> (f64, f64, f32, f32) {
let nan1: f64 = unsafe { std::mem::transmute(0x7FF0_0001_0000_0001u64) };
Expand Down
Loading

0 comments on commit 37af399

Please sign in to comment.