diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff | 19 | ||||
| -rw-r--r-- | tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff | 15 | ||||
| -rw-r--r-- | tests/mir-opt/instsimplify/casts.rs | 6 | ||||
| -rw-r--r-- | tests/ui/cast/ptr-to-ptr-different-regions.rs | 24 |
4 files changed, 49 insertions, 15 deletions
diff --git a/tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff b/tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff index 1c417d4346d..9e1bce1ee20 100644 --- a/tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff +++ b/tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff @@ -6,22 +6,27 @@ let mut _0: *const &u8; let mut _2: *const &u8; let mut _3: *const &u8; + let mut _4: *const &u8; scope 1 (inlined generic_cast::<&u8, &u8>) { - debug x => _3; - let mut _4: *const &u8; + debug x => _4; + let mut _5: *const &u8; } bb0: { StorageLive(_2); StorageLive(_3); - _3 = _1; StorageLive(_4); - _4 = _3; -- _2 = move _4 as *const &u8 (PtrToPtr); -+ _2 = move _4; + _4 = _1; + StorageLive(_5); + _5 = _4; +- _3 = move _5 as *const &u8 (PtrToPtr); ++ _3 = move _5; + StorageDead(_5); StorageDead(_4); - StorageDead(_3); +- _2 = move _3 as *const &u8 (PtrToPtr); ++ _2 = move _3; _0 = _2; + StorageDead(_3); StorageDead(_2); return; } diff --git a/tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff b/tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff index 1ae9d45e66c..a6d68cd4e4b 100644 --- a/tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff +++ b/tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff @@ -4,16 +4,21 @@ fn roundtrip(_1: *const u8) -> *const u8 { debug x => _1; let mut _0: *const u8; - let mut _2: *mut u8; - let mut _3: *const u8; + let mut _2: *const u8; + let mut _3: *mut u8; + let mut _4: *const u8; bb0: { StorageLive(_2); StorageLive(_3); - _3 = _1; - _2 = move _3 as *mut u8 (PtrToPtr); - _0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer)); + StorageLive(_4); + _4 = _1; + _3 = move _4 as *mut u8 (PtrToPtr); + _2 = move _3 as *const u8 (PointerCoercion(MutToConstPointer)); + StorageDead(_4); StorageDead(_3); +- _0 = move _2 as *const u8 (PtrToPtr); ++ _0 = move _2; StorageDead(_2); return; } diff --git a/tests/mir-opt/instsimplify/casts.rs b/tests/mir-opt/instsimplify/casts.rs index 18bab524c64..86f9b34ea04 100644 --- a/tests/mir-opt/instsimplify/casts.rs +++ b/tests/mir-opt/instsimplify/casts.rs @@ -18,8 +18,8 @@ pub fn redundant<'a, 'b: 'a>(x: *const &'a u8) -> *const &'a u8 { // EMIT_MIR casts.roundtrip.InstSimplify.diff pub fn roundtrip(x: *const u8) -> *const u8 { // CHECK-LABEL: fn roundtrip( - // CHECK: _3 = _1; - // CHECK: _2 = move _3 as *mut u8 (PtrToPtr); - // CHECK: _0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer)); + // CHECK: _4 = _1; + // CHECK: _3 = move _4 as *mut u8 (PtrToPtr); + // CHECK: _2 = move _3 as *const u8 (PointerCoercion(MutToConstPointer)); x as *mut u8 as *const u8 } diff --git a/tests/ui/cast/ptr-to-ptr-different-regions.rs b/tests/ui/cast/ptr-to-ptr-different-regions.rs new file mode 100644 index 00000000000..5592e613ac1 --- /dev/null +++ b/tests/ui/cast/ptr-to-ptr-different-regions.rs @@ -0,0 +1,24 @@ +// check-pass + +// https://github.com/rust-lang/rust/issues/113257 + +#![deny(trivial_casts)] // The casts here are not trivial. + +struct Foo<'a> { a: &'a () } + +fn extend_lifetime_very_very_safely<'a>(v: *const Foo<'a>) -> *const Foo<'static> { + // This should pass because raw pointer casts can do anything they want. + v as *const Foo<'static> +} + +trait Trait {} + +fn assert_static<'a>(ptr: *mut (dyn Trait + 'a)) -> *mut (dyn Trait + 'static) { + ptr as _ +} + +fn main() { + let unit = (); + let foo = Foo { a: &unit }; + let _long: *const Foo<'static> = extend_lifetime_very_very_safely(&foo); +} |
