From db099fb491fa2e713047af4f22d4139a71a21dbc Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sat, 3 Aug 2019 15:59:25 -0700 Subject: Point to local place span on "type too big" error --- src/librustc_codegen_llvm/builder.rs | 4 ++++ src/librustc_codegen_llvm/context.rs | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/librustc_codegen_llvm') 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) -> 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) -> 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) }) -- cgit 1.4.1-3-g733a5