Skip to content

Commit 0b624d0

Browse files
committed
improve NullOp::FieldOffset handling of non-field types
1 parent 4bee06c commit 0b624d0

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
494494
NullOp::AlignOf => arg_layout.align.abi.bytes(),
495495
NullOp::FieldOffset => {
496496
let &ty::Field(container, field_path) = arg_ty.kind() else {
497-
bug!(
498-
"FIXME(field_projections): should we really bug here, or return `None`?"
499-
)
497+
return None;
500498
};
501499
let layout = self.ecx.layout_of(container).ok()?;
502500
self.ecx

compiler/rustc_mir_transform/src/known_panics_lint.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
627627
NullOp::AlignOf => op_layout.align.abi.bytes(),
628628
NullOp::FieldOffset => {
629629
let &ty::Field(container, field_path) = ty.kind() else {
630-
bug!(
631-
"FIXME(field_projections): should we really bug here, or return `None`?"
632-
)
630+
return None;
633631
};
634632
let layout = self.ecx.layout_of(container).ok()?;
635633
self.tcx

compiler/rustc_mir_transform/src/promote_consts.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,10 @@ impl<'tcx> Validator<'_, 'tcx> {
452452
self.validate_operand(operand)?;
453453
}
454454

455-
Rvalue::NullaryOp(op, ty) => match op {
455+
Rvalue::NullaryOp(op, _) => match op {
456456
NullOp::SizeOf => {}
457457
NullOp::AlignOf => {}
458-
NullOp::FieldOffset => match ty.kind() {
459-
ty::Field(..) => {}
460-
_ => bug!("FIXME(field_projections): should we report an error here?"),
461-
},
458+
NullOp::FieldOffset => {}
462459
NullOp::UbChecks => {}
463460
NullOp::ContractChecks => {}
464461
},

compiler/rustc_mir_transform/src/validate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
13431343
}
13441344
Rvalue::NullaryOp(NullOp::FieldOffset, ty) => {
13451345
let ty::Field(container, field_path) = ty.kind() else {
1346-
bug!("FIXME(field_projections): report error?")
1346+
span_bug!(
1347+
self.body.span,
1348+
"FIXME(field_projections): expected ty::Field, found {ty:?}"
1349+
)
13471350
};
13481351
let fail_out_of_bounds = |this: &mut Self, location, field, ty| {
13491352
this.fail(location, format!("Out of bounds field {field:?} for {ty}"));

0 commit comments

Comments
 (0)