rust/tests/ui/ptr_ops/issue-80309-safe.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

17 lines
296 B
Rust
Raw Normal View History

2022-02-04 14:11:51 +00:00
// run-pass
2022-02-22 01:53:16 +00:00
// compile-flags: -O
2022-02-04 14:11:51 +00:00
// Regression test for issue #80309
pub fn zero(x: usize) -> usize {
std::ptr::null::<i8>().wrapping_add(x) as usize - x
}
pub fn qux(x: &[i8]) -> i8 {
x[zero(x.as_ptr() as usize)]
}
fn main() {
let z = vec![42, 43];
println!("{}", qux(&z));
}