about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-08-03 15:59:25 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-08-03 21:59:51 -0700
commitdb099fb491fa2e713047af4f22d4139a71a21dbc (patch)
treecb001370005afb2792cf1eaa048e0e5634f8a3a9
parent2c5684208c6f951b2cbe90df26a6691a95099e93 (diff)
Point to local place span on "type too big" error
-rw-r--r--src/librustc/lint/context.rs3
-rw-r--r--src/librustc/ty/layout.rs8
-rw-r--r--src/librustc_codegen_llvm/builder.rs4
-rw-r--r--src/librustc_codegen_llvm/context.rs10
-rw-r--r--src/librustc_codegen_ssa/mir/analyze.rs8
-rw-r--r--src/librustc_codegen_ssa/mir/rvalue.rs14
-rw-r--r--src/librustc_mir/interpret/eval_context.rs3
-rw-r--r--src/librustc_mir/transform/const_prop.rs3
-rw-r--r--src/librustc_passes/layout_test.rs4
-rw-r--r--src/librustc_target/abi/mod.rs2
-rw-r--r--src/test/ui/huge-array-simple.stderr4
-rw-r--r--src/test/ui/huge-array.rs3
-rw-r--r--src/test/ui/huge-array.stderr4
-rw-r--r--src/test/ui/issues/issue-15919.stderr4
14 files changed, 65 insertions, 9 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs
index de812410e8b..7d9653a9a55 100644
--- a/src/librustc/lint/context.rs
+++ b/src/librustc/lint/context.rs
@@ -901,6 +901,9 @@ impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> {
     fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
         self.tcx.layout_of(self.param_env.and(ty))
     }
+    fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
+        self.layout_of(ty)
+    }
 }
 
 impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> {
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs
index 3b4b814c92a..14d35fd4ce8 100644
--- a/src/librustc/ty/layout.rs
+++ b/src/librustc/ty/layout.rs
@@ -3,7 +3,7 @@ use crate::ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions};
 
 use syntax::ast::{self, Ident, IntTy, UintTy};
 use syntax::attr;
-use syntax_pos::DUMMY_SP;
+use syntax_pos::{DUMMY_SP, Span};
 
 use std::cmp;
 use std::fmt;
@@ -1943,6 +1943,9 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> {
 
         Ok(layout)
     }
+    fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
+        self.layout_of(ty)
+    }
 }
 
 impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
@@ -1974,6 +1977,9 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
 
         Ok(layout)
     }
+    fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
+        self.layout_of(ty)
+    }
 }
 
 // Helper (inherent) `layout_of` methods to avoid pushing `LayoutCx` to users.
diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs
index 894e5c2fd3d..c01ba728034 100644
--- a/src/librustc_codegen_llvm/builder.rs
+++ b/src/librustc_codegen_llvm/builder.rs
@@ -6,6 +6,7 @@ use crate::type_::Type;
 use crate::type_of::LayoutLlvmExt;
 use crate::value::Value;
 use syntax::symbol::LocalInternedString;
+use syntax::source_map::Span;
 use rustc_codegen_ssa::common::{IntPredicate, TypeKind, RealPredicate};
 use rustc_codegen_ssa::MemFlags;
 use libc::{c_uint, c_char};
@@ -90,6 +91,9 @@ impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> {
     fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
         self.cx.layout_of(ty)
     }
+    fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
+        self.cx.layout_of(ty)
+    }
 }
 
 impl Deref for Builder<'_, 'll, 'tcx> {
diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs
index 2b68eb53a4a..18d82c27d8c 100644
--- a/src/librustc_codegen_llvm/context.rs
+++ b/src/librustc_codegen_llvm/context.rs
@@ -30,6 +30,7 @@ use std::iter;
 use std::str;
 use std::sync::Arc;
 use syntax::symbol::LocalInternedString;
+use syntax::source_map::Span;
 use crate::abi::Abi;
 
 /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
@@ -860,9 +861,16 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> {
     type TyLayout = TyLayout<'tcx>;
 
     fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
+        self.spanned_layout_of(ty, None)
+    }
+
+    fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Option<Span>) -> Self::TyLayout {
         self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
             .unwrap_or_else(|e| if let LayoutError::SizeOverflow(_) = e {
-                self.sess().fatal(&e.to_string())
+                match span {
+                    Some(span) => self.sess().span_fatal(span, &e.to_string()),
+                    None => self.sess().fatal(&e.to_string()),
+                }
             } else {
                 bug!("failed to get layout for `{}`: {}", ty, e)
             })
diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs
index 907689541f9..1ce3dbc4fe3 100644
--- a/src/librustc_codegen_ssa/mir/analyze.rs
+++ b/src/librustc_codegen_ssa/mir/analyze.rs
@@ -182,13 +182,19 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
                     rvalue: &mir::Rvalue<'tcx>,
                     location: Location) {
         debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue);
+        let mut decl_span = None;
+        if let mir::PlaceBase::Local(local) = &place.base {
+            if let Some(decl) = self.fx.mir.local_decls.get(*local) {
+                decl_span = Some(decl.source_info.span);
+            }
+        }
 
         if let mir::Place {
             base: mir::PlaceBase::Local(index),
             projection: None,
         } = *place {
             self.assign(index, location);
-            if !self.fx.rvalue_creates_operand(rvalue) {
+            if !self.fx.rvalue_creates_operand(rvalue, decl_span) {
                 self.not_ssa(index);
             }
         } else {
diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs
index 202cf147f1f..56c76cdc026 100644
--- a/src/librustc_codegen_ssa/mir/rvalue.rs
+++ b/src/librustc_codegen_ssa/mir/rvalue.rs
@@ -6,6 +6,7 @@ use rustc::middle::lang_items::ExchangeMallocFnLangItem;
 use rustc_apfloat::{ieee, Float, Status, Round};
 use std::{u128, i128};
 use syntax::symbol::sym;
+use syntax::source_map::Span;
 
 use crate::base;
 use crate::MemFlags;
@@ -136,7 +137,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
             }
 
             _ => {
-                assert!(self.rvalue_creates_operand(rvalue));
+                assert!(self.rvalue_creates_operand(rvalue, None));
                 let (mut bx, temp) = self.codegen_rvalue_operand(bx, rvalue);
                 temp.val.store(&mut bx, dest);
                 bx
@@ -169,7 +170,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
         mut bx: Bx,
         rvalue: &mir::Rvalue<'tcx>
     ) -> (Bx, OperandRef<'tcx, Bx::Value>) {
-        assert!(self.rvalue_creates_operand(rvalue), "cannot codegen {:?} to operand", rvalue);
+        assert!(
+            self.rvalue_creates_operand(rvalue, None),
+            "cannot codegen {:?} to operand",
+            rvalue,
+        );
 
         match *rvalue {
             mir::Rvalue::Cast(ref kind, ref source, mir_cast_ty) => {
@@ -691,7 +696,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
 }
 
 impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
-    pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>) -> bool {
+    pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Option<Span>) -> bool {
         match *rvalue {
             mir::Rvalue::Ref(..) |
             mir::Rvalue::Len(..) |
@@ -707,7 +712,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
             mir::Rvalue::Aggregate(..) => {
                 let ty = rvalue.ty(self.mir, self.cx.tcx());
                 let ty = self.monomorphize(&ty);
-                self.cx.layout_of(ty).is_zst()
+                self.cx.spanned_layout_of(ty, span).is_zst()
+                // self.cx.layout_of(ty).is_zst()
             }
         }
 
diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs
index f10d7fb9651..605afa7b368 100644
--- a/src/librustc_mir/interpret/eval_context.rs
+++ b/src/librustc_mir/interpret/eval_context.rs
@@ -193,6 +193,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
             .layout_of(self.param_env.and(ty))
             .map_err(|layout| err_inval!(Layout(layout)).into())
     }
+    fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
+        self.layout_of(ty)
+    }
 }
 
 impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index a450ec32e1a..18b6f408fe1 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -134,6 +134,9 @@ impl<'mir, 'tcx> LayoutOf for ConstPropagator<'mir, 'tcx> {
     fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
         self.tcx.layout_of(self.param_env.and(ty))
     }
+    fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
+        self.layout_of(ty)
+    }
 }
 
 impl<'mir, 'tcx> HasDataLayout for ConstPropagator<'mir, 'tcx> {
diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs
index 95cb8de7067..8c4635f3566 100644
--- a/src/librustc_passes/layout_test.rs
+++ b/src/librustc_passes/layout_test.rs
@@ -13,6 +13,7 @@ use rustc::ty::Ty;
 use rustc::ty::TyCtxt;
 use syntax::ast::Attribute;
 use syntax::symbol::sym;
+use syntax::source_map::Span;
 
 pub fn test_layout(tcx: TyCtxt<'_>) {
     if tcx.features().rustc_attrs {
@@ -116,6 +117,9 @@ impl LayoutOf for UnwrapLayoutCx<'tcx> {
     fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
         self.tcx.layout_of(self.param_env.and(ty)).unwrap()
     }
+    fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
+        self.layout_of(ty)
+    }
 }
 
 impl HasTyCtxt<'tcx> for UnwrapLayoutCx<'tcx> {
diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs
index 80fcb45d0b9..c4f38f4a7f4 100644
--- a/src/librustc_target/abi/mod.rs
+++ b/src/librustc_target/abi/mod.rs
@@ -9,6 +9,7 @@ use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
 use rustc_data_structures::newtype_index;
 use rustc_data_structures::indexed_vec::{Idx, IndexVec};
 use syntax_pos::symbol::{sym, Symbol};
+use syntax_pos::Span;
 
 pub mod call;
 
@@ -1012,6 +1013,7 @@ pub trait LayoutOf {
     type TyLayout;
 
     fn layout_of(&self, ty: Self::Ty) -> Self::TyLayout;
+    fn spanned_layout_of(&self, ty: Self::Ty, span: Option<Span>) -> Self::TyLayout;
 }
 
 #[derive(Copy, Clone, PartialEq, Eq)]
diff --git a/src/test/ui/huge-array-simple.stderr b/src/test/ui/huge-array-simple.stderr
index 3e9c86296ce..71d3f62bbe5 100644
--- a/src/test/ui/huge-array-simple.stderr
+++ b/src/test/ui/huge-array-simple.stderr
@@ -1,4 +1,8 @@
 error: the type `[u8; N]` is too big for the current architecture
+  --> $DIR/huge-array-simple.rs:12:9
+   |
+LL |     let _fat : [u8; (1<<61)+(1<<31)] =
+   |         ^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/huge-array.rs b/src/test/ui/huge-array.rs
index f58dcd58067..1ecf012e04b 100644
--- a/src/test/ui/huge-array.rs
+++ b/src/test/ui/huge-array.rs
@@ -1,11 +1,10 @@
-// error-pattern:; 1518600000
-
 // FIXME https://github.com/rust-lang/rust/issues/59774
 // normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> ""
 // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> ""
 
 fn generic<T: Copy>(t: T) {
     let s: [T; 1518600000] = [t; 1518600000];
+    //~^ ERROR the type `[[u8; 1518599999]; 1518600000]` is too big for the current architecture
 }
 
 fn main() {
diff --git a/src/test/ui/huge-array.stderr b/src/test/ui/huge-array.stderr
index 38d9effcfb5..823d974f429 100644
--- a/src/test/ui/huge-array.stderr
+++ b/src/test/ui/huge-array.stderr
@@ -1,4 +1,8 @@
 error: the type `[[u8; 1518599999]; 1518600000]` is too big for the current architecture
+  --> $DIR/huge-array.rs:6:9
+   |
+LL |     let s: [T; 1518600000] = [t; 1518600000];
+   |         ^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-15919.stderr b/src/test/ui/issues/issue-15919.stderr
index e4e88cc47cf..66c76853784 100644
--- a/src/test/ui/issues/issue-15919.stderr
+++ b/src/test/ui/issues/issue-15919.stderr
@@ -1,4 +1,8 @@
 error: the type `[usize; N]` is too big for the current architecture
+  --> $DIR/issue-15919.rs:15:9
+   |
+LL |     let x = [0usize; 0xffff_ffff_ffff_ffff];
+   |         ^
 
 error: aborting due to previous error