Skip to content

Commit a3c2d75

Browse files
committed
add test for ICE: failed to get layout for [type error] #92979
Fixes #92979
1 parent 6fe5555 commit a3c2d75

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// ICE: failed to get layout for [type error]
2+
// issue: rust-lang/rust#92979
3+
4+
use std::fs;
5+
use std::fs::File;
6+
use std::io::Read;
7+
use std::convert::TryInto;
8+
9+
fn get_file_as_byte_vec(filename: &String) -> Vec<u8> {
10+
let mut f = File::open(&filename).expect("no file found");
11+
let metadata = fs::metadata(&filename).expect("unable to read metadata");
12+
let mut buffer = vec![0; metadata.len() as usize];
13+
f.read(&mut buffer).expect("buffer overflow");
14+
15+
buffer
16+
}
17+
18+
19+
20+
fn demo<T, const N: usize>(v: Vec<T>) -> [T; N] {
21+
v.try_into()
22+
.unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len()))
23+
}
24+
25+
26+
fn main() {
27+
28+
// Specify filepath
29+
let file: &String = &String::from("SomeBinaryDataFileWith4ByteHeaders_f32s_and_u32s");
30+
31+
// Read file into a vector of bytes
32+
let file_data = get_file_as_byte_vec(file);
33+
34+
// Print length of vector and first few values
35+
let length = file_data.len();
36+
println!("The read function read {} bytes", length);
37+
println!("The first few bytes:");
38+
for i in 0..20{
39+
println!("{}", file_data[i]);
40+
}
41+
42+
// Manually count just to make sure
43+
let mut n: u64 = 0;
44+
for data in file_data{
45+
n += 1;
46+
}
47+
println!("We counted {} bytes", n);
48+
assert!(n as usize == length, "Manual counting does not equal len method");
49+
50+
// Simulation parameters
51+
const N: usize = 49627502; // Number of Particles
52+
const bs: f64 = 125.0; // Box Size
53+
const HEADER_INCREMENT: u64 = 4*1;
54+
55+
// Initialize index and counter variables
56+
let (mut j, mut pos, mut vel, mut id, mut mass): (u64, u64, u64, u64, u64) = (0, 0, 0, 0, 0);
57+
58+
// Unpack Position Data
59+
j += HEADER_INCREMENT;
60+
let mut position: Vec<f32> = Vec::new();
61+
while position.len() < N*3 {
62+
63+
let p: Vec<u8> = Vec::new();
64+
for item in 0i8..4 {
65+
let item = item;
66+
p.push(file_data[j as usize]);
67+
j += 1;
68+
}
69+
&mut position[position.len()] = f32::from_be_bytes(demo(p));
70+
//~^ ERROR invalid left-hand side of assignment
71+
}
72+
73+
// Ensure position data is indeed position by checking values
74+
for p in position {
75+
assert!((p > 0.) & (p < 125.), "Not in box")
76+
}
77+
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0070]: invalid left-hand side of assignment
2+
--> $DIR/failed-to-get-layout-for-type-error-ice-92979.rs:69:39
3+
|
4+
LL | &mut position[position.len()] = f32::from_be_bytes(demo(p));
5+
| ----------------------------- ^
6+
| |
7+
| cannot assign to this expression
8+
|
9+
help: consider dereferencing here to assign to the mutably borrowed value
10+
|
11+
LL | *&mut position[position.len()] = f32::from_be_bytes(demo(p));
12+
| +
13+
14+
error: aborting due to 1 previous error
15+
16+
For more information about this error, try `rustc --explain E0070`.

0 commit comments

Comments
 (0)