Skip to content

Commit 6e41031

Browse files
committed
fix assert_deps test code
1 parent ef42014 commit 6e41031

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/cargo/core/compiler/fingerprint/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,9 +2289,7 @@ impl EncodedDepInfo {
22892289
}
22902290

22912291
fn read_bool(bytes: &mut &[u8]) -> Option<bool> {
2292-
let ret = bytes.get(0).map(|b| *b != 0)?;
2293-
*bytes = &bytes[1..];
2294-
Some(ret)
2292+
read_u8(bytes).map(|b| b != 0)
22952293
}
22962294

22972295
fn read_u8(bytes: &mut &[u8]) -> Option<u8> {

tests/testsuite/dep_info.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ fn assert_deps(project: &Project, fingerprint: &str, test_cb: impl Fn(&Path, &[(
3131
let dep_info = &mut &dep_info[..];
3232
let deps = (0..read_usize(dep_info))
3333
.map(|_| {
34-
(
35-
read_u8(dep_info),
36-
str::from_utf8(read_bytes(dep_info)).unwrap(),
37-
)
34+
let ty = read_u8(dep_info);
35+
let path = str::from_utf8(read_bytes(dep_info)).unwrap();
36+
let checksum_present = read_bool(dep_info);
37+
if checksum_present {
38+
// Read out the checksum info without using it
39+
let _file_len = read_u64(dep_info);
40+
let _checksum = read_bytes(dep_info);
41+
}
42+
(ty, path)
3843
})
3944
.collect::<Vec<_>>();
4045
test_cb(&info_path, &deps);
@@ -52,6 +57,17 @@ fn assert_deps(project: &Project, fingerprint: &str, test_cb: impl Fn(&Path, &[(
5257
ret
5358
}
5459

60+
fn read_bool(bytes: &mut &[u8]) -> bool {
61+
read_u8(bytes) != 0
62+
}
63+
64+
fn read_u64(bytes: &mut &[u8]) -> u64 {
65+
let ret = &bytes[..8];
66+
*bytes = &bytes[8..];
67+
68+
u64::from_le_bytes(ret.try_into().unwrap())
69+
}
70+
5571
fn read_bytes<'a>(bytes: &mut &'a [u8]) -> &'a [u8] {
5672
let n = read_usize(bytes);
5773
let ret = &bytes[..n];

0 commit comments

Comments
 (0)