Skip to content

Commit db099fb

Browse files
committed
Point to local place span on "type too big" error
1 parent 2c56842 commit db099fb

File tree

14 files changed

+65
-9
lines changed

14 files changed

+65
-9
lines changed

src/librustc/lint/context.rs

+3
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,9 @@ impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> {
901901
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
902902
self.tcx.layout_of(self.param_env.and(ty))
903903
}
904+
fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
905+
self.layout_of(ty)
906+
}
904907
}
905908

906909
impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> {

src/librustc/ty/layout.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions};
33

44
use syntax::ast::{self, Ident, IntTy, UintTy};
55
use syntax::attr;
6-
use syntax_pos::DUMMY_SP;
6+
use syntax_pos::{DUMMY_SP, Span};
77

88
use std::cmp;
99
use std::fmt;
@@ -1943,6 +1943,9 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> {
19431943

19441944
Ok(layout)
19451945
}
1946+
fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
1947+
self.layout_of(ty)
1948+
}
19461949
}
19471950

19481951
impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
@@ -1974,6 +1977,9 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
19741977

19751978
Ok(layout)
19761979
}
1980+
fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
1981+
self.layout_of(ty)
1982+
}
19771983
}
19781984

19791985
// Helper (inherent) `layout_of` methods to avoid pushing `LayoutCx` to users.

src/librustc_codegen_llvm/builder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::type_::Type;
66
use crate::type_of::LayoutLlvmExt;
77
use crate::value::Value;
88
use syntax::symbol::LocalInternedString;
9+
use syntax::source_map::Span;
910
use rustc_codegen_ssa::common::{IntPredicate, TypeKind, RealPredicate};
1011
use rustc_codegen_ssa::MemFlags;
1112
use libc::{c_uint, c_char};
@@ -90,6 +91,9 @@ impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> {
9091
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
9192
self.cx.layout_of(ty)
9293
}
94+
fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
95+
self.cx.layout_of(ty)
96+
}
9397
}
9498

9599
impl Deref for Builder<'_, 'll, 'tcx> {

src/librustc_codegen_llvm/context.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use std::iter;
3030
use std::str;
3131
use std::sync::Arc;
3232
use syntax::symbol::LocalInternedString;
33+
use syntax::source_map::Span;
3334
use crate::abi::Abi;
3435

3536
/// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
@@ -860,9 +861,16 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> {
860861
type TyLayout = TyLayout<'tcx>;
861862

862863
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
864+
self.spanned_layout_of(ty, None)
865+
}
866+
867+
fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Option<Span>) -> Self::TyLayout {
863868
self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
864869
.unwrap_or_else(|e| if let LayoutError::SizeOverflow(_) = e {
865-
self.sess().fatal(&e.to_string())
870+
match span {
871+
Some(span) => self.sess().span_fatal(span, &e.to_string()),
872+
None => self.sess().fatal(&e.to_string()),
873+
}
866874
} else {
867875
bug!("failed to get layout for `{}`: {}", ty, e)
868876
})

src/librustc_codegen_ssa/mir/analyze.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,19 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
182182
rvalue: &mir::Rvalue<'tcx>,
183183
location: Location) {
184184
debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue);
185+
let mut decl_span = None;
186+
if let mir::PlaceBase::Local(local) = &place.base {
187+
if let Some(decl) = self.fx.mir.local_decls.get(*local) {
188+
decl_span = Some(decl.source_info.span);
189+
}
190+
}
185191

186192
if let mir::Place {
187193
base: mir::PlaceBase::Local(index),
188194
projection: None,
189195
} = *place {
190196
self.assign(index, location);
191-
if !self.fx.rvalue_creates_operand(rvalue) {
197+
if !self.fx.rvalue_creates_operand(rvalue, decl_span) {
192198
self.not_ssa(index);
193199
}
194200
} else {

src/librustc_codegen_ssa/mir/rvalue.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc::middle::lang_items::ExchangeMallocFnLangItem;
66
use rustc_apfloat::{ieee, Float, Status, Round};
77
use std::{u128, i128};
88
use syntax::symbol::sym;
9+
use syntax::source_map::Span;
910

1011
use crate::base;
1112
use crate::MemFlags;
@@ -136,7 +137,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
136137
}
137138

138139
_ => {
139-
assert!(self.rvalue_creates_operand(rvalue));
140+
assert!(self.rvalue_creates_operand(rvalue, None));
140141
let (mut bx, temp) = self.codegen_rvalue_operand(bx, rvalue);
141142
temp.val.store(&mut bx, dest);
142143
bx
@@ -169,7 +170,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
169170
mut bx: Bx,
170171
rvalue: &mir::Rvalue<'tcx>
171172
) -> (Bx, OperandRef<'tcx, Bx::Value>) {
172-
assert!(self.rvalue_creates_operand(rvalue), "cannot codegen {:?} to operand", rvalue);
173+
assert!(
174+
self.rvalue_creates_operand(rvalue, None),
175+
"cannot codegen {:?} to operand",
176+
rvalue,
177+
);
173178

174179
match *rvalue {
175180
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> {
691696
}
692697

693698
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
694-
pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>) -> bool {
699+
pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Option<Span>) -> bool {
695700
match *rvalue {
696701
mir::Rvalue::Ref(..) |
697702
mir::Rvalue::Len(..) |
@@ -707,7 +712,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
707712
mir::Rvalue::Aggregate(..) => {
708713
let ty = rvalue.ty(self.mir, self.cx.tcx());
709714
let ty = self.monomorphize(&ty);
710-
self.cx.layout_of(ty).is_zst()
715+
self.cx.spanned_layout_of(ty, span).is_zst()
716+
// self.cx.layout_of(ty).is_zst()
711717
}
712718
}
713719

src/librustc_mir/interpret/eval_context.rs

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
193193
.layout_of(self.param_env.and(ty))
194194
.map_err(|layout| err_inval!(Layout(layout)).into())
195195
}
196+
fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
197+
self.layout_of(ty)
198+
}
196199
}
197200

198201
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

src/librustc_mir/transform/const_prop.rs

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ impl<'mir, 'tcx> LayoutOf for ConstPropagator<'mir, 'tcx> {
134134
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
135135
self.tcx.layout_of(self.param_env.and(ty))
136136
}
137+
fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
138+
self.layout_of(ty)
139+
}
137140
}
138141

139142
impl<'mir, 'tcx> HasDataLayout for ConstPropagator<'mir, 'tcx> {

src/librustc_passes/layout_test.rs

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc::ty::Ty;
1313
use rustc::ty::TyCtxt;
1414
use syntax::ast::Attribute;
1515
use syntax::symbol::sym;
16+
use syntax::source_map::Span;
1617

1718
pub fn test_layout(tcx: TyCtxt<'_>) {
1819
if tcx.features().rustc_attrs {
@@ -116,6 +117,9 @@ impl LayoutOf for UnwrapLayoutCx<'tcx> {
116117
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
117118
self.tcx.layout_of(self.param_env.and(ty)).unwrap()
118119
}
120+
fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option<Span>) -> Self::TyLayout {
121+
self.layout_of(ty)
122+
}
119123
}
120124

121125
impl HasTyCtxt<'tcx> for UnwrapLayoutCx<'tcx> {

src/librustc_target/abi/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
99
use rustc_data_structures::newtype_index;
1010
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1111
use syntax_pos::symbol::{sym, Symbol};
12+
use syntax_pos::Span;
1213

1314
pub mod call;
1415

@@ -1012,6 +1013,7 @@ pub trait LayoutOf {
10121013
type TyLayout;
10131014

10141015
fn layout_of(&self, ty: Self::Ty) -> Self::TyLayout;
1016+
fn spanned_layout_of(&self, ty: Self::Ty, span: Option<Span>) -> Self::TyLayout;
10151017
}
10161018

10171019
#[derive(Copy, Clone, PartialEq, Eq)]

src/test/ui/huge-array-simple.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
error: the type `[u8; N]` is too big for the current architecture
2+
--> $DIR/huge-array-simple.rs:12:9
3+
|
4+
LL | let _fat : [u8; (1<<61)+(1<<31)] =
5+
| ^^^^
26

37
error: aborting due to previous error
48

src/test/ui/huge-array.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// error-pattern:; 1518600000
2-
31
// FIXME https://github.com/rust-lang/rust/issues/59774
42
// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> ""
53
// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> ""
64

75
fn generic<T: Copy>(t: T) {
86
let s: [T; 1518600000] = [t; 1518600000];
7+
//~^ ERROR the type `[[u8; 1518599999]; 1518600000]` is too big for the current architecture
98
}
109

1110
fn main() {

src/test/ui/huge-array.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
error: the type `[[u8; 1518599999]; 1518600000]` is too big for the current architecture
2+
--> $DIR/huge-array.rs:6:9
3+
|
4+
LL | let s: [T; 1518600000] = [t; 1518600000];
5+
| ^
26

37
error: aborting due to previous error
48

src/test/ui/issues/issue-15919.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
error: the type `[usize; N]` is too big for the current architecture
2+
--> $DIR/issue-15919.rs:15:9
3+
|
4+
LL | let x = [0usize; 0xffff_ffff_ffff_ffff];
5+
| ^
26

37
error: aborting due to previous error
48

0 commit comments

Comments
 (0)