Skip to content

Commit 84f7dcd

Browse files
authored
Fix clippy errors on nightly (2021-09-29) (#691)
Most of the changes are for the new if-then-panic lint added in rust-lang/rust-clippy#7669.
1 parent 7095a5d commit 84f7dcd

File tree

6 files changed

+26
-32
lines changed

6 files changed

+26
-32
lines changed

control_plane/src/compute.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,7 @@ impl PostgresNode {
452452
.output()
453453
.expect("failed to execute whoami");
454454

455-
if !output.status.success() {
456-
panic!("whoami failed");
457-
}
455+
assert!(output.status.success(), "whoami failed");
458456

459457
String::from_utf8(output.stdout).unwrap().trim().to_string()
460458
}

pageserver/src/layered_repository.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,13 +1247,12 @@ impl LayeredTimeline {
12471247
assert!(lsn.is_aligned());
12481248

12491249
let last_record_lsn = self.get_last_record_lsn();
1250-
if lsn <= last_record_lsn {
1251-
panic!(
1252-
"cannot modify relation after advancing last_record_lsn (incoming_lsn={}, last_record_lsn={})",
1253-
lsn,
1254-
last_record_lsn
1255-
);
1256-
}
1250+
assert!(
1251+
lsn > last_record_lsn,
1252+
"cannot modify relation after advancing last_record_lsn (incoming_lsn={}, last_record_lsn={})",
1253+
lsn,
1254+
last_record_lsn,
1255+
);
12571256

12581257
// Do we have a layer open for writing already?
12591258
let layer;

pageserver/src/layered_repository/interval_tree.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ mod tests {
283283
write!(f, "{}", self.val)
284284
}
285285
}
286+
#[rustfmt::skip]
286287
fn assert_search(
287288
tree: &IntervalTree<MockItem>,
288289
key: u32,
@@ -291,24 +292,20 @@ mod tests {
291292
if let Some(v) = tree.search(key) {
292293
let vstr = v.to_string();
293294

294-
if expected.is_empty() {
295-
panic!("search with {} returned {}, expected None", key, v);
296-
}
295+
assert!(!expected.is_empty(), "search with {} returned {}, expected None", key, v);
296+
assert!(
297+
expected.contains(&vstr.as_str()),
298+
"search with {} returned {}, expected one of: {:?}",
299+
key, v, expected,
300+
);
297301

298-
if !expected.contains(&vstr.as_str()) {
299-
panic!(
300-
"search with {} returned {}, expected one of: {:?}",
301-
key, v, expected
302-
);
303-
}
304302
Some(v)
305303
} else {
306-
if !expected.is_empty() {
307-
panic!(
308-
"search with {} returned None, expected one of {:?}",
309-
key, expected
310-
);
311-
}
304+
assert!(
305+
expected.is_empty(),
306+
"search with {} returned None, expected one of {:?}",
307+
key, expected
308+
);
312309
None
313310
}
314311
}

pageserver/src/tenant_mgr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn insert_repository_for_tenant(tenantid: ZTenantId, repo: Arc<dyn Repositor
7070
pub fn get_repository_for_tenant(tenantid: ZTenantId) -> Result<Arc<dyn Repository>> {
7171
let o = &REPOSITORY.lock().unwrap();
7272
o.get(&tenantid)
73-
.map(|repo| Arc::clone(repo))
73+
.map(Arc::clone)
7474
.ok_or_else(|| anyhow!("repository not found for tenant name {}", tenantid))
7575
}
7676

pageserver/src/walredo.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,11 @@ impl PostgresRedoManager {
298298
// Transaction manager stuff
299299
let rec_segno = match rel {
300300
RelishTag::Slru { slru, segno } => {
301-
if slru != SlruKind::Clog {
302-
panic!("Not valid XACT relish tag {:?}", rel);
303-
}
301+
assert!(
302+
slru == SlruKind::Clog,
303+
"Not valid XACT relish tag {:?}",
304+
rel
305+
);
304306
segno
305307
}
306308
_ => panic!("Not valid XACT relish tag {:?}", rel),

zenith_utils/src/lsn.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ impl AtomicLsn {
192192
/// This operation will panic on overflow.
193193
pub fn fetch_add(&self, val: u64) -> Lsn {
194194
let prev = self.inner.fetch_add(val, Ordering::AcqRel);
195-
if prev.checked_add(val).is_none() {
196-
panic!("AtomicLsn overflow");
197-
}
195+
assert!(prev.checked_add(val).is_some(), "AtomicLsn overflow");
198196
Lsn(prev)
199197
}
200198

0 commit comments

Comments
 (0)