]> git.lizzy.rs Git - rust.git/commitdiff
Point to local place span on "type too big" error
authorEsteban Küber <esteban@kuber.com.ar>
Sat, 3 Aug 2019 22:59:25 +0000 (15:59 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Sun, 4 Aug 2019 04:59:51 +0000 (21:59 -0700)
14 files changed:
src/librustc/lint/context.rs
src/librustc/ty/layout.rs
src/librustc_codegen_llvm/builder.rs
src/librustc_codegen_llvm/context.rs
src/librustc_codegen_ssa/mir/analyze.rs
src/librustc_codegen_ssa/mir/rvalue.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/transform/const_prop.rs
src/librustc_passes/layout_test.rs
src/librustc_target/abi/mod.rs
src/test/ui/huge-array-simple.stderr
src/test/ui/huge-array.rs
src/test/ui/huge-array.stderr
src/test/ui/issues/issue-15919.stderr

index de812410e8bd83260f66925bcabbe285fbc0ee7d..7d9653a9a55b15d6b2447673962fee56f5dffdc4 100644 (file)
@@ -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> {
index 3b4b814c92a90fff9d37846b58db408df5af67bc..14d35fd4ce891b86a572b838bf29df8038b62999 100644 (file)
@@ -3,7 +3,7 @@
 
 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 @@ fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
 
         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 @@ fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
 
         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.
index 894e5c2fd3d93049d53f513039659813952b593b..c01ba728034ced9b93460b3196cc691b5c173e82 100644 (file)
@@ -6,6 +6,7 @@
 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> {
index 2b68eb53a4ab96a27195a938dda8d5aede0c720f..18d82c27d8cc93eb52f9f324cf67f862228fdc1c 100644 (file)
@@ -30,6 +30,7 @@
 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)
             })
index 907689541f97884ba0d60d8e662b24a56eb31070..1ce3dbc4fe3b6587a71f83d30a4422f331d6dd43 100644 (file)
@@ -182,13 +182,19 @@ fn visit_assign(&mut self,
                     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 {
index 202cf147f1fcbcefa8fce6fe83555acd4235399a..56c76cdc026f733733e7ab5d4d555ad413a2a986 100644 (file)
@@ -6,6 +6,7 @@
 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 @@ pub fn codegen_rvalue(
             }
 
             _ => {
-                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 @@ pub fn codegen_rvalue_operand(
         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 @@ pub fn codegen_scalar_checked_binop(
 }
 
 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 @@ pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>) -> bool {
             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()
             }
         }
 
index f10d7fb96511601cddbb4f79e60ec9fc0cbe3c26..605afa7b3681021a3f995faee684cdb1315e4076 100644 (file)
@@ -193,6 +193,9 @@ fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
             .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> {
index a450ec32e1a478410a432d9c971c7d9b32f6dbab..18b6f408fe12c0089a9cd140a08f72af89b0dbae 100644 (file)
@@ -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> {
index 95cb8de70675d12c604572560870fe51fb006c9f..8c4635f3566ca316a2588f9af9de2e3ed6291427 100644 (file)
@@ -13,6 +13,7 @@
 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> {
index 80fcb45d0b9bc0157347b90a80c8c745120767d5..c4f38f4a7f4c385a536797b3dd9969bec2016728 100644 (file)
@@ -9,6 +9,7 @@
 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)]
index 3e9c86296cec2ecdd74b1f022001b76d73dfd927..71d3f62bbe53b5ea3f48fb5e02ea3631e9871dac 100644 (file)
@@ -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
 
index f58dcd580676199e17b2780649a72c91553ea793..1ecf012e04be4cb1a1695b6e9b5b953cc0e2a66a 100644 (file)
@@ -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() {
index 38d9effcfb5270ae8f6a7141f9865812ae2eaa4a..823d974f4290ee4e8912900ca4fee36a37a79a64 100644 (file)
@@ -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
 
index e4e88cc47cfe7d11d13ba3ed8e56425729bf41c0..66c768537843c780c2313248e40988632c3ea7fb 100644 (file)
@@ -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