diff options
| author | Ralf Jung <post@ralfj.de> | 2019-11-04 13:31:29 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2019-11-04 13:32:38 +0100 |
| commit | 21d284b6f0d62dfd284249a9e059b72e4fcfca87 (patch) | |
| tree | b7dbbec1d1851b8f9bd88733db619b6b5d7090bd /src | |
| parent | 3c944feb658575f0afae2e148e058ad3599926df (diff) | |
| download | rust-21d284b6f0d62dfd284249a9e059b72e4fcfca87.tar.gz rust-21d284b6f0d62dfd284249a9e059b72e4fcfca87.zip | |
also test different integers
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/consts/offset_from_ub.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/consts/offset_from_ub.stderr | 21 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/test/ui/consts/offset_from_ub.rs b/src/test/ui/consts/offset_from_ub.rs index c96d62cd923..c9030915620 100644 --- a/src/test/ui/consts/offset_from_ub.rs +++ b/src/test/ui/consts/offset_from_ub.rs @@ -39,4 +39,11 @@ pub const OFFSET_FROM_NULL: isize = { unsafe { ptr.offset_from(ptr) } }; +pub const DIFFERENT_INT: isize = { // offset_from with two different integers: like DIFFERENT_ALLOC + //~^ NOTE + let ptr1 = 8 as *const u8; + let ptr2 = 16 as *const u8; + unsafe { ptr2.offset_from(ptr1) } +}; + fn main() {} diff --git a/src/test/ui/consts/offset_from_ub.stderr b/src/test/ui/consts/offset_from_ub.stderr index 1015b9cf7fc..1bd09034bfc 100644 --- a/src/test/ui/consts/offset_from_ub.stderr +++ b/src/test/ui/consts/offset_from_ub.stderr @@ -75,5 +75,24 @@ LL | | unsafe { ptr.offset_from(ptr) } LL | | }; | |__- -error: aborting due to 4 previous errors +error: any use of this value will cause an error + --> $SRC_DIR/libcore/ptr/mod.rs:LL:COL + | +LL | intrinsics::ptr_offset_from(self, origin) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | a memory access tried to interpret some bytes as a pointer + | inside call to `std::ptr::<impl *const u8>::offset_from` at $DIR/offset_from_ub.rs:46:14 + | + ::: $DIR/offset_from_ub.rs:42:1 + | +LL | / pub const DIFFERENT_INT: isize = { // offset_from with two different integers: like DIFFERENT_ALLOC +LL | | +LL | | let ptr1 = 8 as *const u8; +LL | | let ptr2 = 16 as *const u8; +LL | | unsafe { ptr2.offset_from(ptr1) } +LL | | }; + | |__- + +error: aborting due to 5 previous errors |
