Skip to content

Commit b9117e8

Browse files
committed
Use some modern slice operations in favor of manually writing them
1 parent 2c6a12e commit b9117e8

File tree

1 file changed

+6
-8
lines changed
  • compiler/rustc_codegen_ssa/src

1 file changed

+6
-8
lines changed

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,24 +297,22 @@ impl CodegenResults {
297297
) -> Result<(Self, OutputFilenames), CodegenErrors> {
298298
// The Decodable machinery is not used here because it panics if the input data is invalid
299299
// and because its internal representation may change.
300-
if !data.starts_with(RLINK_MAGIC) {
300+
let Some(data) = data.strip_prefix(RLINK_MAGIC) else {
301301
return Err(CodegenErrors::WrongFileType);
302-
}
303-
let data = &data[RLINK_MAGIC.len()..];
304-
if data.len() < 4 {
302+
};
303+
304+
let Some((&version_array, data)) = data.split_first_chunk() else {
305305
return Err(CodegenErrors::EmptyVersionNumber);
306-
}
306+
};
307307

308-
let mut version_array: [u8; 4] = Default::default();
309-
version_array.copy_from_slice(&data[..4]);
310308
if u32::from_be_bytes(version_array) != RLINK_VERSION {
311309
return Err(CodegenErrors::EncodingVersionMismatch {
312310
version_array: String::from_utf8_lossy(&version_array).to_string(),
313311
rlink_version: RLINK_VERSION,
314312
});
315313
}
316314

317-
let Ok(mut decoder) = MemDecoder::new(&data[4..], 0) else {
315+
let Ok(mut decoder) = MemDecoder::new(data, 0) else {
318316
return Err(CodegenErrors::CorruptFile);
319317
};
320318
let rustc_version = decoder.read_str();

0 commit comments

Comments
 (0)