Skip to content

Commit 61fd7e3

Browse files
committed
Auto merge of #1032 - RalfJung:offset-from, r=RalfJung
test offset_from This currently fails and needs a rustc fix: rust-lang/rust#66083
2 parents 9f0b99b + 3847334 commit 61fd7e3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6c1b220fd747bf244f04b380e4d4ae005068f706
1+
3a1b3b30c6cdd674049b144a3ced7b711de962b2

tests/run-pass/ptr_offset_from.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(ptr_offset_from)]
2+
3+
fn test_raw() { unsafe {
4+
let buf = [0u32; 4];
5+
6+
let x = buf.as_ptr() as *const u8;
7+
let y = x.offset(12);
8+
9+
assert_eq!(y.offset_from(x), 12);
10+
assert_eq!(x.offset_from(y), -12);
11+
assert_eq!((y as *const u32).offset_from(x as *const u32), 12/4);
12+
assert_eq!((x as *const u32).offset_from(y as *const u32), -12/4);
13+
14+
let x = (((x as usize) * 2) / 2) as *const u8;
15+
assert_eq!(y.offset_from(x), 12);
16+
assert_eq!(x.offset_from(y), -12);
17+
} }
18+
19+
// This also internally uses offset_from.
20+
fn test_vec_into_iter() {
21+
let v = Vec::<i32>::new();
22+
let i = v.into_iter();
23+
i.size_hint();
24+
}
25+
26+
fn main() {
27+
test_raw();
28+
test_vec_into_iter();
29+
}

0 commit comments

Comments
 (0)