about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/mir/constant.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-18 19:41:21 +0000
committerbors <bors@rust-lang.org>2023-09-18 19:41:21 +0000
commitcebb9cfd4f0052fbb5e98f9b6f3a61dae8fd96a7 (patch)
tree8cab476d937833d4744831c22fd1d5493e857455 /compiler/rustc_codegen_ssa/src/mir/constant.rs
parentb1575cb72ef40459666f802af8636faf8428e3eb (diff)
parent9ac8b363e3227fdc08634ce445b7787aa0fa6bba (diff)
downloadrust-cebb9cfd4f0052fbb5e98f9b6f3a61dae8fd96a7.tar.gz
rust-cebb9cfd4f0052fbb5e98f9b6f3a61dae8fd96a7.zip
Auto merge of #115748 - RalfJung:post-mono, r=oli-obk
move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) https://github.com/rust-lang/rust/issues/115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/mir/constant.rs')
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/constant.rs28
1 files changed, 5 insertions, 23 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs
index 4d7bd60ceca..263b41ed880 100644
--- a/compiler/rustc_codegen_ssa/src/mir/constant.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs
@@ -14,34 +14,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
         &self,
         bx: &mut Bx,
         constant: &mir::Constant<'tcx>,
-    ) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> {
-        let val = self.eval_mir_constant(constant)?;
+    ) -> OperandRef<'tcx, Bx::Value> {
+        let val = self.eval_mir_constant(constant);
         let ty = self.monomorphize(constant.ty());
-        Ok(OperandRef::from_const(bx, val, ty))
+        OperandRef::from_const(bx, val, ty)
     }
 
-    pub fn eval_mir_constant(
-        &self,
-        constant: &mir::Constant<'tcx>,
-    ) -> Result<ConstValue<'tcx>, ErrorHandled> {
+    pub fn eval_mir_constant(&self, constant: &mir::Constant<'tcx>) -> ConstValue<'tcx> {
         self.monomorphize(constant.literal)
             .eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), Some(constant.span))
-            .map_err(|err| {
-                match err {
-                    ErrorHandled::Reported(_) => {
-                        self.cx
-                            .tcx()
-                            .sess
-                            .emit_err(errors::ErroneousConstant { span: constant.span });
-                    }
-                    ErrorHandled::TooGeneric => {
-                        self.cx.tcx().sess.diagnostic().emit_bug(
-                            errors::PolymorphicConstantTooGeneric { span: constant.span },
-                        );
-                    }
-                }
-                err
-            })
+            .expect("erroneous constant not captured by required_consts")
     }
 
     /// This is a convenience helper for `simd_shuffle_indices`. It has the precondition