From bdd79b849e9db3024c8b5a0426e6a08af20edd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 4 Aug 2019 12:23:05 -0700 Subject: [PATCH] tweak output and tests --- src/librustc/mir/interpret/error.rs | 4 +++- src/librustc_codegen_llvm/context.rs | 5 +---- src/librustc_codegen_ssa/mir/analyze.rs | 27 +++++++++++++++++-------- src/test/ui/consts/issue-55878.stderr | 2 +- src/test/ui/huge-enum.rs | 12 +++++------ src/test/ui/huge-enum.stderr | 6 +++++- src/test/ui/huge-struct.rs | 2 ++ src/test/ui/huge-struct.stderr | 4 ++++ src/test/ui/issues/issue-56762.stderr | 4 ++-- 9 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index fb6f74397fc..b8759776587 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -165,7 +165,9 @@ impl<'tcx> ConstEvalErr<'tcx> { } else { struct_error(tcx, message) }; - err.span_label(self.span, self.error.to_string()); + if !must_error { + err.span_label(self.span, self.error.to_string()); + } // Skip the last, which is just the environment of the constant. The stacktrace // is sometimes empty because we create "fake" eval contexts in CTFE to do work // on constant values. diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index ee8f1843c1a..a2aaaddf093 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -867,10 +867,7 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> { fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyLayout { self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) .unwrap_or_else(|e| if let LayoutError::SizeOverflow(_) = e { - match span { - Some(span) => self.sess().span_fatal(span, &e.to_string()), - None => self.sess().fatal(&e.to_string()), - } + self.sess().span_fatal(span, &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 5dc050cbb36..cc0c733c224 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -9,6 +9,7 @@ use rustc::mir::visit::{Visitor, PlaceContext, MutatingUseContext, NonMutatingUs use rustc::mir::traversal; use rustc::ty; use rustc::ty::layout::{LayoutOf, HasTyCtxt}; +use syntax_pos::DUMMY_SP; use super::FunctionCx; use crate::traits::*; @@ -20,10 +21,13 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( analyzer.visit_body(mir); - for (index, ty) in mir.local_decls.iter().map(|l| l.ty).enumerate() { + for (index, (ty, span)) in mir.local_decls.iter() + .map(|l| (l.ty, l.source_info.span)) + .enumerate() + { let ty = fx.monomorphize(&ty); debug!("local {} has type {:?}", index, ty); - let layout = fx.cx.layout_of(ty); + let layout = fx.cx.spanned_layout_of(ty, span); if fx.cx.is_backend_immediate(layout) { // These sorts of types are immediates that we can store // in an Value without an alloca. @@ -93,10 +97,12 @@ impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { } } - fn process_place(&mut self, - place_ref: &mir::PlaceRef<'_, 'tcx>, - context: PlaceContext, - location: Location) { + fn process_place( + &mut self, + place_ref: &mir::PlaceRef<'_, 'tcx>, + context: PlaceContext, + location: Location, + ) { let cx = self.fx.cx; if let Some(proj) = place_ref.projection { @@ -116,12 +122,17 @@ impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { .projection_ty(cx.tcx(), &proj.elem) .ty; let elem_ty = self.fx.monomorphize(&elem_ty); - if cx.layout_of(elem_ty).is_zst() { + let span = if let mir::PlaceBase::Local(index) = place_ref.base { + self.fx.mir.local_decls[*index].source_info.span + } else { + DUMMY_SP + }; + if cx.spanned_layout_of(elem_ty, span).is_zst() { return; } if let mir::ProjectionElem::Field(..) = proj.elem { - let layout = cx.layout_of(base_ty.ty); + let layout = cx.spanned_layout_of(base_ty.ty, span); if cx.is_backend_immediate(layout) || cx.is_backend_scalar_pair(layout) { // Recurse with the same context, instead of `Projection`, // potentially stopping at non-operand projections, diff --git a/src/test/ui/consts/issue-55878.stderr b/src/test/ui/consts/issue-55878.stderr index 184c6d0e292..aa4dfb719f9 100644 --- a/src/test/ui/consts/issue-55878.stderr +++ b/src/test/ui/consts/issue-55878.stderr @@ -2,7 +2,7 @@ error[E0080]: the type `[u8; 18446744073709551615]` is too big for the current a --> $SRC_DIR/libcore/mem/mod.rs:LL:COL | LL | intrinsics::size_of::() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 18446744073709551615]` is too big for the current architecture + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ::: $DIR/issue-55878.rs:3:26 | diff --git a/src/test/ui/huge-enum.rs b/src/test/ui/huge-enum.rs index 2492afbdc8f..8ac15f3156b 100644 --- a/src/test/ui/huge-enum.rs +++ b/src/test/ui/huge-enum.rs @@ -1,16 +1,14 @@ -// normalize-stderr-test "std::option::Option<\[u32; \d+\]>" -> "TYPE" -// normalize-stderr-test "\[u32; \d+\]" -> "TYPE" - // 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" -> "" #[cfg(target_pointer_width = "32")] -fn main() { - let big: Option<[u32; (1<<29)-1]> = None; -} +type BIG = Option<[u32; (1<<29)-1]>; #[cfg(target_pointer_width = "64")] +type BIG = Option<[u32; (1<<45)-1]>; + fn main() { - let big: Option<[u32; (1<<45)-1]> = None; + let big: BIG = None; + //~^ ERROR is too big for the current architecture } diff --git a/src/test/ui/huge-enum.stderr b/src/test/ui/huge-enum.stderr index 67cae3d52ed..94349f475e9 100644 --- a/src/test/ui/huge-enum.stderr +++ b/src/test/ui/huge-enum.stderr @@ -1,4 +1,8 @@ -error: the type `TYPE` is too big for the current architecture +error: the type `std::option::Option<[u32; 35184372088831]>` is too big for the current architecture + --> $DIR/huge-enum.rs:12:9 + | +LL | let big: BIG = None; + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/huge-struct.rs b/src/test/ui/huge-struct.rs index dc7d75a6f02..e120cae7fdd 100644 --- a/src/test/ui/huge-struct.rs +++ b/src/test/ui/huge-struct.rs @@ -47,4 +47,6 @@ struct S1M { val: S1k> } fn main() { let fat: Option>>> = None; + //~^ ERROR the type `S32>>` is too big for the current architecture + } diff --git a/src/test/ui/huge-struct.stderr b/src/test/ui/huge-struct.stderr index 06b084bdc3a..5c2140df481 100644 --- a/src/test/ui/huge-struct.stderr +++ b/src/test/ui/huge-struct.stderr @@ -1,4 +1,8 @@ error: the type `SXX>>` is too big for the current architecture + --> $DIR/huge-struct.rs:49:9 + | +LL | let fat: Option>>> = None; + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-56762.stderr b/src/test/ui/issues/issue-56762.stderr index e74904f1f68..69626d4bc7a 100644 --- a/src/test/ui/issues/issue-56762.stderr +++ b/src/test/ui/issues/issue-56762.stderr @@ -2,13 +2,13 @@ error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current ar --> $DIR/issue-56762.rs:19:1 | LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 2305843009213693951]` is too big for the current architecture + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture --> $DIR/issue-56762.rs:21:1 | LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 2305843009213693951]` is too big for the current architecture + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors