Skip to content

Commit ac6e239

Browse files
authored
Rollup merge of #84262 - camelid:sized-ice, r=estebank
Fix ICE during type layout when there's a `[type error]` Fixes #84108. Based on estebank's [comment], except I used `delay_span_bug` because it should work in more cases, and I think it expresses its intent more clearly. r? `@estebank` [comment]: #84108 (comment)
2 parents cc9610b + c30eac5 commit ac6e239

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

compiler/rustc_middle/src/ty/layout.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
367367
for &i in &inverse_memory_index {
368368
let field = fields[i as usize];
369369
if !sized {
370-
bug!("univariant: field #{} of `{}` comes after unsized field", offsets.len(), ty);
370+
self.tcx.sess.delay_span_bug(
371+
DUMMY_SP,
372+
&format!(
373+
"univariant: field #{} of `{}` comes after unsized field",
374+
offsets.len(),
375+
ty
376+
),
377+
);
371378
}
372379

373380
if field.is_unsized() {

src/test/ui/layout/issue-84108.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// See issue #84108 -- this is a test to ensure we do not ICE
2+
// on this invalid code.
3+
4+
#![crate_type = "lib"]
5+
6+
static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
7+
//~^ ERROR cannot find type `OsStr` in this scope
8+
9+
const BAR: (&Path, [u8], usize) = ("hello", [], 42);
10+
//~^ ERROR cannot find type `Path` in this scope
11+
//~| ERROR the size for values of type `[u8]` cannot be known at compilation time
12+
13+
static BAZ: ([u8], usize) = ([], 0);
14+
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time

src/test/ui/layout/issue-84108.stderr

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error[E0412]: cannot find type `OsStr` in this scope
2+
--> $DIR/issue-84108.rs:6:24
3+
|
4+
LL | static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
5+
| ^^^^^ not found in this scope
6+
|
7+
help: consider importing this struct
8+
|
9+
LL | use std::ffi::OsStr;
10+
|
11+
12+
error[E0412]: cannot find type `Path` in this scope
13+
--> $DIR/issue-84108.rs:9:14
14+
|
15+
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
16+
| ^^^^ not found in this scope
17+
|
18+
help: consider importing this struct
19+
|
20+
LL | use std::path::Path;
21+
|
22+
23+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
24+
--> $DIR/issue-84108.rs:9:12
25+
|
26+
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
27+
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
28+
|
29+
= help: the trait `Sized` is not implemented for `[u8]`
30+
= note: only the last element of a tuple may have a dynamically sized type
31+
32+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
33+
--> $DIR/issue-84108.rs:13:13
34+
|
35+
LL | static BAZ: ([u8], usize) = ([], 0);
36+
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
37+
|
38+
= help: the trait `Sized` is not implemented for `[u8]`
39+
= note: only the last element of a tuple may have a dynamically sized type
40+
41+
error: aborting due to 4 previous errors
42+
43+
Some errors have detailed explanations: E0277, E0412.
44+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)