Skip to content

Commit aba93d1

Browse files
committed
analyze: update non_null_rewrites test
1 parent 6de384c commit aba93d1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

c2rust-analyze/tests/filecheck/non_null_rewrites.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ unsafe fn field_projection(cond: bool, mut p: *const S) -> i32 {
119119
// Ensure `p` is wrapped in `Option`.
120120
p = ptr::null();
121121
}
122-
// Do a field projection. This should become a `.map()` call.
123-
// TODO: Currently, we generate an incorrect rewrite for such projections
124-
// CHECK: let q: core::option::Option<&(i32)> =
125-
// CHECK-SAME: &(*(p).unwrap()).x
126-
let q: *const i32 = &(*p).x;
122+
123+
// Do a field projection. This becomes an `unwrap()` + project + `Some(_)`.
124+
// CHECK: let q: core::option::Option<&(i32)> = std::option::Option::Some(&((*(p).unwrap()).x));
125+
let q: *const i32 = ptr::addr_of!((*p).x);
126+
127+
// Same projection, but using `&` instead of `addr_of!`. This produces an equivalent but more
128+
// convoluted result due to the implicit `addr_of!(*_)` adjustment.
129+
// CHECK: let q: core::option::Option<&(i32)> = std::option::Option::Some(&*std::option::Option::Some((&((*(p).unwrap()).x))).unwrap());
130+
let q: *const i32 = &((*p).x);
131+
127132
*q
128133
}
129134

0 commit comments

Comments
 (0)