Skip to content

Commit 1b4e05c

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

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -276,24 +276,22 @@ impl CodegenResults {
276276
) -> Result<(Self, OutputFilenames), CodegenErrors> {
277277
// The Decodable machinery is not used here because it panics if the input data is invalid
278278
// and because its internal representation may change.
279-
if !data.starts_with(RLINK_MAGIC) {
279+
let Some(data) = data.strip_prefix(RLINK_MAGIC) else {
280280
return Err(CodegenErrors::WrongFileType);
281-
}
282-
let data = &data[RLINK_MAGIC.len()..];
283-
if data.len() < 4 {
281+
};
282+
283+
let Some((&version_array, data)) = data.split_first_chunk() else {
284284
return Err(CodegenErrors::EmptyVersionNumber);
285-
}
285+
};
286286

287-
let mut version_array: [u8; 4] = Default::default();
288-
version_array.copy_from_slice(&data[..4]);
289287
if u32::from_be_bytes(version_array) != RLINK_VERSION {
290288
return Err(CodegenErrors::EncodingVersionMismatch {
291289
version_array: String::from_utf8_lossy(&version_array).to_string(),
292290
rlink_version: RLINK_VERSION,
293291
});
294292
}
295293

296-
let Ok(mut decoder) = MemDecoder::new(&data[4..], 0) else {
294+
let Ok(mut decoder) = MemDecoder::new(data, 0) else {
297295
return Err(CodegenErrors::CorruptFile);
298296
};
299297
let rustc_version = decoder.read_str();

0 commit comments

Comments
 (0)