Ban all unwrap usage in codebase

This commit is contained in:
topjohnwu
2025-12-08 17:35:52 -08:00
committed by John Wu
parent 200665c48a
commit ff4ca74cfe
24 changed files with 138 additions and 89 deletions
+3
View File
@@ -7,6 +7,9 @@ edition.workspace = true
crate-type = ["staticlib"]
path = "lib.rs"
[lints]
workspace = true
[build-dependencies]
cxx-gen = { workspace = true }
pb-rs = { workspace = true }
+1
View File
@@ -6,6 +6,7 @@ use crate::codegen::gen_cxx_binding;
#[path = "../include/codegen.rs"]
mod codegen;
#[allow(clippy::unwrap_used)]
fn main() {
println!("cargo:rerun-if-changed=proto/update_metadata.proto");
+1 -1
View File
@@ -248,7 +248,7 @@ pub fn get_encoder<'a, W: Write + 'a>(
FileFormat::ZOPFLI => {
// These options are already better than gzip -9
let opt = ZopfliOptions {
iteration_count: NonZeroU64::new(1).unwrap(),
iteration_count: unsafe { NonZeroU64::new_unchecked(1) },
maximum_block_splits: 1,
..Default::default()
};
+32 -24
View File
@@ -484,10 +484,9 @@ impl Cpio {
};
for (name, entry) in &self.entries {
let p = "/".to_string() + name.as_str();
if !p.starts_with(&path) {
let Some(p) = p.strip_prefix(&path) else {
continue;
}
let p = p.strip_prefix(&path).unwrap();
};
if !p.is_empty() && !p.starts_with('/') {
continue;
}
@@ -614,8 +613,11 @@ impl Cpio {
o.rm(".backup", true);
self.rm(".backup", true);
let mut lhs = o.entries.into_iter().peekable();
let mut rhs = self.entries.iter().peekable();
let mut left_iter = o.entries.into_iter();
let mut right_iter = self.entries.iter();
let mut lhs = left_iter.next();
let mut rhs = right_iter.next();
loop {
enum Action<'a> {
@@ -623,32 +625,38 @@ impl Cpio {
Record(&'a String),
Noop,
}
let action = match (lhs.peek(), rhs.peek()) {
(Some((l, _)), Some((r, re))) => match l.as_str().cmp(r.as_str()) {
// Move the iterator forward if needed
if lhs.is_none() {
lhs = left_iter.next();
}
if rhs.is_none() {
rhs = right_iter.next();
}
let action = match (lhs.take(), rhs.take()) {
(Some((ln, le)), Some((rn, re))) => match ln.as_str().cmp(rn.as_str()) {
Ordering::Less => {
let (l, le) = lhs.next().unwrap();
Action::Backup(l, le)
// Put rhs back
rhs = Some((rn, re));
Action::Backup(ln, le)
}
Ordering::Greater => {
// Put lhs back
lhs = Some((ln, le));
Action::Record(rn)
}
Ordering::Greater => Action::Record(rhs.next().unwrap().0),
Ordering::Equal => {
let (l, le) = lhs.next().unwrap();
let action = if re.data != le.data {
Action::Backup(l, le)
if re.data != le.data {
Action::Backup(ln, le)
} else {
Action::Noop
};
rhs.next();
action
}
}
},
(Some(_), None) => {
let (l, le) = lhs.next().unwrap();
Action::Backup(l, le)
}
(None, Some(_)) => Action::Record(rhs.next().unwrap().0),
(None, None) => {
break;
}
(Some((ln, le)), None) => Action::Backup(ln, le),
(None, Some((rn, _))) => Action::Record(rn),
(None, None) => break,
};
match action {
Action::Backup(name, mut entry) => {