Skip to content

Commit fe5608a

Browse files
committed
rustc_const_eval: improve error handling
1 parent 847000f commit fe5608a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, read_target_uint, write_targ
1010
use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic, NullOp};
1111
use rustc_middle::ty::layout::TyAndLayout;
1212
use rustc_middle::ty::{Ty, TyCtxt};
13-
use rustc_middle::{bug, err_inval, ty};
13+
use rustc_middle::{bug, err_inval, span_bug, ty};
1414
use rustc_span::{Symbol, sym};
1515
use tracing::trace;
1616

@@ -663,12 +663,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
663663
dest: &PlaceTy<'tcx, M::Provenance>,
664664
) -> InterpResult<'tcx, ()> {
665665
assert_eq!(instance.args.len(), 1);
666-
match instance.args.type_at(0).kind() {
666+
let ty = instance.args.type_at(0);
667+
match ty.kind() {
667668
&ty::Field(container, field_path) => {
668669
let offset = self.nullary_op(NullOp::OffsetOf(field_path), container)?;
669670
self.write_immediate(*offset, dest)
670671
}
671-
_ => Err(err_inval!(TooGeneric)).into(),
672+
ty::Alias(..) | ty::Param(..) | ty::Placeholder(..) | ty::Infer(..) => {
673+
Err(err_inval!(TooGeneric)).into()
674+
}
675+
_ => span_bug!(self.cur_span(), "expected field representing type, found {ty}"),
672676
}
673677
}
674678

0 commit comments

Comments
 (0)