about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-10-26 11:05:00 +0000
committerbors <bors@rust-lang.org>2018-10-26 11:05:00 +0000
commit694cf752988728ba5da85c36c2deaeefeb49c05e (patch)
treef2501734f55b37ac50bf5604a897c939ccfdc996 /src/librustc_codegen_llvm
parent82239b04dc9cea1d54422c2fb223ff5321ccafdd (diff)
parent13d94ee1154770caa8e027394fa2221db2dfe5c3 (diff)
downloadrust-694cf752988728ba5da85c36c2deaeefeb49c05e.tar.gz
rust-694cf752988728ba5da85c36c2deaeefeb49c05e.zip
Auto merge of #53821 - oli-obk:sanity_query, r=RalfJung
Report const eval error inside the query

Functional changes: We no longer warn about bad constants embedded in unused types. This relied on being able to report just a warning, not a hard error on that case, which we cannot do any more now that error reporting is consistently centralized.

r? @RalfJung

fixes #53561
Diffstat (limited to 'src/librustc_codegen_llvm')
-rw-r--r--src/librustc_codegen_llvm/mir/constant.rs19
-rw-r--r--src/librustc_codegen_llvm/mir/operand.rs16
2 files changed, 18 insertions, 17 deletions
diff --git a/src/librustc_codegen_llvm/mir/constant.rs b/src/librustc_codegen_llvm/mir/constant.rs
index 9f0f7443890..1f66ee36170 100644
--- a/src/librustc_codegen_llvm/mir/constant.rs
+++ b/src/librustc_codegen_llvm/mir/constant.rs
@@ -9,12 +9,11 @@
 // except according to those terms.
 
 use llvm;
-use rustc::mir::interpret::{ConstEvalErr, read_target_uint};
+use rustc::mir::interpret::{ErrorHandled, read_target_uint};
 use rustc_mir::const_eval::const_field;
 use rustc::hir::def_id::DefId;
 use rustc::mir;
 use rustc_data_structures::indexed_vec::Idx;
-use rustc_data_structures::sync::Lrc;
 use rustc::mir::interpret::{GlobalId, Pointer, Scalar, Allocation, ConstValue, AllocType};
 use rustc::ty::{self, Ty};
 use rustc::ty::layout::{self, HasDataLayout, LayoutOf, Size};
@@ -124,7 +123,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll
 pub fn codegen_static_initializer(
     cx: &CodegenCx<'ll, 'tcx>,
     def_id: DefId,
-) -> Result<(&'ll Value, &'tcx Allocation), Lrc<ConstEvalErr<'tcx>>> {
+) -> Result<(&'ll Value, &'tcx Allocation), ErrorHandled> {
     let instance = ty::Instance::mono(cx.tcx, def_id);
     let cid = GlobalId {
         instance,
@@ -145,7 +144,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
         &mut self,
         bx: &Builder<'a, 'll, 'tcx>,
         constant: &'tcx ty::Const<'tcx>,
-    ) -> Result<&'tcx ty::Const<'tcx>, Lrc<ConstEvalErr<'tcx>>> {
+    ) -> Result<&'tcx ty::Const<'tcx>, ErrorHandled> {
         match constant.val {
             ConstValue::Unevaluated(def_id, ref substs) => {
                 let tcx = bx.tcx();
@@ -165,7 +164,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
         &mut self,
         bx: &Builder<'a, 'll, 'tcx>,
         constant: &mir::Constant<'tcx>,
-    ) -> Result<&'tcx ty::Const<'tcx>, Lrc<ConstEvalErr<'tcx>>> {
+    ) -> Result<&'tcx ty::Const<'tcx>, ErrorHandled> {
         let c = self.monomorphize(&constant.literal);
         self.fully_evaluate(bx, c)
     }
@@ -176,7 +175,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
         bx: &Builder<'a, 'll, 'tcx>,
         span: Span,
         ty: Ty<'tcx>,
-        constant: Result<&'tcx ty::Const<'tcx>, Lrc<ConstEvalErr<'tcx>>>,
+        constant: Result<&'tcx ty::Const<'tcx>, ErrorHandled>,
     ) -> (&'ll Value, Ty<'tcx>) {
         constant
             .and_then(|c| {
@@ -185,7 +184,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
                     ty::Array(_, n) => n.unwrap_usize(bx.tcx()),
                     ref other => bug!("invalid simd shuffle type: {}", other),
                 };
-                let values: Result<Vec<_>, Lrc<_>> = (0..fields).map(|field| {
+                let values: Result<Vec<_>, ErrorHandled> = (0..fields).map(|field| {
                     let field = const_field(
                         bx.tcx(),
                         ty::ParamEnv::reveal_all(),
@@ -211,9 +210,9 @@ impl FunctionCx<'a, 'll, 'tcx> {
                 let llval = C_struct(bx.cx, &values?, false);
                 Ok((llval, c.ty))
             })
-            .unwrap_or_else(|e| {
-                e.report_as_error(
-                    bx.tcx().at(span),
+            .unwrap_or_else(|_| {
+                bx.tcx().sess.span_err(
+                    span,
                     "could not evaluate shuffle_indices at compile time",
                 );
                 // We've errored, so we don't have to produce working code.
diff --git a/src/librustc_codegen_llvm/mir/operand.rs b/src/librustc_codegen_llvm/mir/operand.rs
index ab43531240f..d1b6aa7fc42 100644
--- a/src/librustc_codegen_llvm/mir/operand.rs
+++ b/src/librustc_codegen_llvm/mir/operand.rs
@@ -8,11 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use rustc::mir::interpret::{ConstValue, ConstEvalErr};
+use rustc::mir::interpret::{ConstValue, ErrorHandled};
 use rustc::mir;
 use rustc::ty;
 use rustc::ty::layout::{self, Align, LayoutOf, TyLayout};
-use rustc_data_structures::sync::Lrc;
 
 use base;
 use common::{CodegenCx, C_undef, C_usize};
@@ -79,7 +78,7 @@ impl OperandRef<'ll, 'tcx> {
 
     pub fn from_const(bx: &Builder<'a, 'll, 'tcx>,
                       val: &'tcx ty::Const<'tcx>)
-                      -> Result<OperandRef<'ll, 'tcx>, Lrc<ConstEvalErr<'tcx>>> {
+                      -> Result<OperandRef<'ll, 'tcx>, ErrorHandled> {
         let layout = bx.cx.layout_of(val.ty);
 
         if layout.is_zst() {
@@ -424,10 +423,13 @@ impl FunctionCx<'a, 'll, 'tcx> {
                 self.eval_mir_constant(bx, constant)
                     .and_then(|c| OperandRef::from_const(bx, c))
                     .unwrap_or_else(|err| {
-                        err.report_as_error(
-                            bx.tcx().at(constant.span),
-                            "could not evaluate constant operand",
-                        );
+                        match err {
+                            // errored or at least linted
+                            ErrorHandled::Reported => {},
+                            ErrorHandled::TooGeneric => {
+                                bug!("codgen encountered polymorphic constant")
+                            },
+                        }
                         // Allow RalfJ to sleep soundly knowing that even refactorings that remove
                         // the above error (or silence it under some conditions) will not cause UB
                         let fnname = bx.cx.get_intrinsic(&("llvm.trap"));