Skip to content

Commit 96803b4

Browse files
committed
Delete as u64 from usize-returning offsetof
1 parent 92e2e20 commit 96803b4

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3088,7 +3088,7 @@ bool Converter::VisitOffsetOfExpr(clang::OffsetOfExpr *expr) {
30883088
member_path += GetNamedDeclAsString(node.getField());
30893089
}
30903090
StrCat(
3091-
std::format("::std::mem::offset_of!({}, {}) as u64",
3091+
std::format("::std::mem::offset_of!({}, {})",
30923092
GetUnsafeTypeAsString(expr->getTypeSourceInfo()->getType()),
30933093
member_path));
30943094
computed_expr_type_ = ComputedExprType::FreshValue;

tests/unit/out/unsafe/offsetof.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ pub fn main() {
3131
}
3232
}
3333
unsafe fn main_0() -> i32 {
34-
assert!(((::std::mem::offset_of!(Layout, a) as u64) == (0_u64)));
35-
assert!(((::std::mem::offset_of!(Layout, b) as u64) == (4_u64)));
36-
assert!(((::std::mem::offset_of!(Layout, c) as u64) == (8_u64)));
37-
assert!(((::std::mem::offset_of!(Outer, inner.y) as u64) == (8_u64)));
34+
assert!(((::std::mem::offset_of!(Layout, a)) == (0_usize)));
35+
assert!(((::std::mem::offset_of!(Layout, b)) == (4_usize)));
36+
assert!(((::std::mem::offset_of!(Layout, c)) == (8_usize)));
37+
assert!(((::std::mem::offset_of!(Outer, inner.y)) == (8_usize)));
3838
let mut v: Layout = Layout {
3939
a: 0_u8,
4040
b: 0_u32,
@@ -43,7 +43,7 @@ unsafe fn main_0() -> i32 {
4343
v.b = 3735928559_u32;
4444
let mut base: *mut u8 = ((&mut v as *mut Layout) as *mut u8);
4545
let mut bp: *mut u32 =
46-
((base.offset((::std::mem::offset_of!(Layout, b) as u64) as isize)) as *mut u32);
46+
((base.offset((::std::mem::offset_of!(Layout, b)) as isize)) as *mut u32);
4747
assert!(((*bp) == (3735928559_u32)));
4848
return 0;
4949
}

0 commit comments

Comments
 (0)