Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ impl<'tcx> ThirBuildCx<'tcx> {
lit: ScalarInt::try_from_uint(val, Size::from_bits(32)).unwrap(),
user_ty: None,
};
let mk_usize_kind = |val: u64| ExprKind::NonHirLiteral {
lit: ScalarInt::try_from_target_usize(val, tcx).unwrap(),
user_ty: None,
};
let mk_call =
|thir: &mut Thir<'tcx>, ty: Ty<'tcx>, variant: VariantIdx, field: FieldIdx| {
let fun_ty =
Expand Down Expand Up @@ -842,7 +846,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
});
}

expr.unwrap_or(mk_u32_kind(0))
expr.unwrap_or_else(|| mk_usize_kind(0))
}

hir::ExprKind::ConstBlock(ref anon_const) => {
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/offset-of/offset-of-error-recovery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::mem::offset_of;

struct S {
x: (),
}

impl S {
fn a() {
offset_of!(Self, Self::x);
//~^ ERROR offset_of expects dot-separated field and variant names
}
}

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/offset-of/offset-of-error-recovery.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: offset_of expects dot-separated field and variant names
--> $DIR/offset-of-error-recovery.rs:9:26
|
LL | offset_of!(Self, Self::x);
| ^^^^^^^

error: aborting due to 1 previous error

Loading