|
1 | 1 | use rustc_span::DUMMY_SP;
|
2 | 2 |
|
| 3 | +use rustc_errors::ErrorReported; |
3 | 4 | use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
4 | 5 | use rustc_middle::mir::interpret::{
|
5 |
| - read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Pointer, Scalar, |
| 6 | + read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Pointer, Scalar, |
6 | 7 | };
|
7 | 8 | use rustc_middle::ty::{Const, ConstKind};
|
8 | 9 | use rustc_target::abi::Align;
|
@@ -34,6 +35,29 @@ impl ConstantCx {
|
34 | 35 | }
|
35 | 36 | }
|
36 | 37 |
|
| 38 | +pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Backend>) { |
| 39 | + for constant in &fx.mir.required_consts { |
| 40 | + let const_ = fx.monomorphize(&constant.literal); |
| 41 | + match const_.val { |
| 42 | + ConstKind::Value(_) => {} |
| 43 | + ConstKind::Unevaluated(def, ref substs, promoted) => { |
| 44 | + if let Err(err) = fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) { |
| 45 | + match err { |
| 46 | + ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted => { |
| 47 | + fx.tcx.sess.span_err(constant.span, "erroneous constant encountered"); |
| 48 | + } |
| 49 | + ErrorHandled::TooGeneric => { |
| 50 | + span_bug!(constant.span, "codgen encountered polymorphic constant: {:?}", err); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + ConstKind::Param(_) | ConstKind::Infer(_) | ConstKind::Bound(_, _) |
| 56 | + | ConstKind::Placeholder(_) | ConstKind::Error(_) => unreachable!("{:?}", const_), |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
37 | 61 | pub(crate) fn codegen_static(constants_cx: &mut ConstantCx, def_id: DefId) {
|
38 | 62 | constants_cx.todo.push(TodoItem::Static(def_id));
|
39 | 63 | }
|
|
0 commit comments