Skip to content

Commit

Permalink
Rollup merge of #79158 - lcnr:lazy-norm-coerce, r=oli-obk
Browse files Browse the repository at this point in the history
type is too big -> values of the type are too big

strictly speaking, `[u8; usize::MAX]` or even `[[[u128; usize::MAX]; usize::MAX]; usize::MAX]` are absolutely fine types as long as you don't try to deal with any values of it.

This error message seems to cause some confusion imo, for example in #79135 (comment) so I would prefer us to be more precise here.

See the added test case which uses one of these types without causing an error.

r? `@oli-obk`
  • Loading branch information
m-ou-se committed Nov 18, 2020
2 parents 74e6442 + 88584d5 commit 97cd4c4
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
match *self {
LayoutError::Unknown(ty) => write!(f, "the type `{}` has an unknown layout", ty),
LayoutError::SizeOverflow(ty) => {
write!(f, "the type `{}` is too big for the current architecture", ty)
write!(f, "values of the type `{}` are too big for the current architecture", ty)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
self.infcx.tcx
}

#[instrument(skip(self))]
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if !ty.has_projections() {
return ty;
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/consts/issue-55878.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// normalize-stderr-64bit "18446744073709551615" -> "SIZE"
// normalize-stderr-32bit "4294967295" -> "SIZE"

// error-pattern: is too big for the current architecture
// error-pattern: are too big for the current architecture
fn main() {
println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
}
2 changes: 1 addition & 1 deletion src/test/ui/huge-array-simple-32.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the type `[u8; 2147516416]` is too big for the current architecture
error: values of the type `[u8; 2147516416]` are too big for the current architecture
--> $DIR/huge-array-simple-32.rs:10:9
|
LL | let _fat: [u8; (1<<31)+(1<<15)] =
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/huge-array-simple-64.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the type `[u8; 2305843011361177600]` is too big for the current architecture
error: values of the type `[u8; 2305843011361177600]` are too big for the current architecture
--> $DIR/huge-array-simple-64.rs:10:9
|
LL | let _fat: [u8; (1<<61)+(1<<31)] =
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/huge-array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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
//~^ ERROR values of the type `[[u8; 1518599999]; 1518600000]` are too big
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/huge-array.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the type `[[u8; 1518599999]; 1518600000]` is too big for the current architecture
error: values of the type `[[u8; 1518599999]; 1518600000]` are too big for the current architecture
--> $DIR/huge-array.rs:8:9
|
LL | let s: [T; 1518600000] = [t; 1518600000];
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/huge-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ type BIG = Option<[u32; (1<<45)-1]>;

fn main() {
let big: BIG = None;
//~^ ERROR is too big for the current architecture
//~^ ERROR are too big for the current architecture
}
2 changes: 1 addition & 1 deletion src/test/ui/huge-enum.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the type `Option<TYPE>` is too big for the current architecture
error: values of the type `Option<TYPE>` are too big for the current architecture
--> $DIR/huge-enum.rs:16:9
|
LL | let big: BIG = None;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/huge-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ struct S1M<T> { val: S1k<S1k<T>> }

fn main() {
let fat: Option<S1M<S1M<S1M<u32>>>> = None;
//~^ ERROR is too big for the current architecture
//~^ ERROR are too big for the current architecture

}
2 changes: 1 addition & 1 deletion src/test/ui/huge-struct.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the type `SXX<SXX<SXX<u32>>>` is too big for the current architecture
error: values of the type `SXX<SXX<SXX<u32>>>` are too big for the current architecture
--> $DIR/huge-struct.rs:50:9
|
LL | let fat: Option<SXX<SXX<SXX<u32>>>> = None;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-15919-32.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the type `[usize; 4294967295]` is too big for the current architecture
error: values of the type `[usize; 4294967295]` are too big for the current architecture
--> $DIR/issue-15919-32.rs:9:9
|
LL | let x = [0usize; 0xffff_ffff];
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-15919-64.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the type `[usize; 18446744073709551615]` is too big for the current architecture
error: values of the type `[usize; 18446744073709551615]` are too big for the current architecture
--> $DIR/issue-15919-64.rs:9:9
|
LL | let x = [0usize; 0xffff_ffff_ffff_ffff];
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-17913.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the type `[&usize; N]` is too big for the current architecture
error: values of the type `[&usize; N]` are too big for the current architecture

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-56762.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ impl TooBigArray {
}

static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
//~^ ERROR the type `[u8; 2305843009213693951]` is too big for the current architecture
//~^ ERROR values of the type `[u8; 2305843009213693951]` are too big
static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE];
//~^ ERROR the type `[u8; 2305843009213693951]` is too big for the current architecture
//~^ ERROR values of the type `[u8; 2305843009213693951]` are too big

fn main() { }
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-56762.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture
error[E0080]: values of the type `[u8; 2305843009213693951]` are too big for the current architecture
--> $DIR/issue-56762.rs:19:1
|
LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture
error[E0080]: values of the type `[u8; 2305843009213693951]` are 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];
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/layout/big-type-no-err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Enormous types are allowed if they are never actually instantiated.
// run-pass
trait Foo {
type Assoc;
}

impl Foo for [u16; usize::MAX] {
type Assoc = u32;
}

fn main() {
let _a: Option<<[u16; usize::MAX] as Foo>::Assoc> = None;
}
2 changes: 1 addition & 1 deletion src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// compile-flags: -Zmir-opt-level=0

fn main() {
Bug::V([0; !0]); //~ ERROR is too big for the current
Bug::V([0; !0]); //~ ERROR are too big for the current
}

enum Bug {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the type `[u8; 18446744073709551615]` is too big for the current architecture
error: values of the type `[u8; 18446744073709551615]` are too big for the current architecture
--> $DIR/issue-69485-var-size-diffs-too-large.rs:6:12
|
LL | Bug::V([0; !0]);
Expand Down

0 comments on commit 97cd4c4

Please sign in to comment.