Skip to content

Commit 70d440e

Browse files
committed
Address shadow_unrelated and other clippy issues
1 parent e365ba2 commit 70d440e

File tree

9 files changed

+53
-71
lines changed

9 files changed

+53
-71
lines changed

src/config.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,6 @@ impl Config {
705705
let guard = pin();
706706
let old = self.global_error.swap(Shared::default(), SeqCst, &guard);
707707
if !old.is_null() {
708-
let guard = pin();
709708
#[allow(unsafe_code)]
710709
unsafe {
711710
guard.defer_destroy(old);
@@ -781,12 +780,12 @@ impl RunningConfig {
781780
// returns the snapshot file paths for this system
782781
#[doc(hidden)]
783782
pub fn get_snapshot_files(&self) -> io::Result<Vec<PathBuf>> {
784-
let path = self.get_path().join("snap.");
783+
let conf_path = self.get_path().join("snap.");
785784

786-
let absolute_path: PathBuf = if Path::new(&path).is_absolute() {
787-
path
785+
let absolute_path: PathBuf = if Path::new(&conf_path).is_absolute() {
786+
conf_path
788787
} else {
789-
std::env::current_dir()?.join(path)
788+
std::env::current_dir()?.join(conf_path)
790789
};
791790

792791
let filter = |dir_entry: io::Result<fs::DirEntry>| {

src/db.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ impl Db {
107107
/// accessible from the `Db` via the provided identifier.
108108
pub fn open_tree<V: AsRef<[u8]>>(&self, name: V) -> Result<Tree> {
109109
let name_ref = name.as_ref();
110-
let tenants = self.tenants.read();
111-
if let Some(tree) = tenants.get(name_ref) {
112-
return Ok(tree.clone());
110+
111+
{
112+
let tenants = self.tenants.read();
113+
if let Some(tree) = tenants.get(name_ref) {
114+
return Ok(tree.clone());
115+
}
116+
drop(tenants);
113117
}
114-
drop(tenants);
115118

116119
let guard = pin();
117120

src/ebr/atomic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ impl<T: ?Sized + Pointable> Atomic<T> {
361361
ord.failure(),
362362
)
363363
.map(|_| unsafe { Shared::from_usize(new) })
364-
.map_err(|current| unsafe {
364+
.map_err(|cur| unsafe {
365365
CompareAndSetError {
366-
current: Shared::from_usize(current),
366+
current: Shared::from_usize(cur),
367367
new: P::from_usize(new),
368368
}
369369
})
@@ -402,9 +402,9 @@ impl<T: ?Sized + Pointable> Atomic<T> {
402402
ord.failure(),
403403
)
404404
.map(|_| unsafe { Shared::from_usize(new) })
405-
.map_err(|current| unsafe {
405+
.map_err(|cur| unsafe {
406406
CompareAndSetError {
407-
current: Shared::from_usize(current),
407+
current: Shared::from_usize(cur),
408408
new: P::from_usize(new),
409409
}
410410
})

src/event_log.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ impl EventLog {
118118
let locations_after_restart: Vec<_> = par
119119
.get(&pid)
120120
.unwrap_or_else(|| panic!("pid {} no longer present after restart", pid))
121-
.iter()
122-
.copied()
123-
.collect();
121+
.to_vec();
124122
assert_eq!(
125123
locations_before_restart,
126124
locations_after_restart,

src/histogram.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ impl Default for Histogram {
6767
// Avoid calling Vec::resize_with with a large length because its
6868
// internals cause stacked borrows tracking information to add an
6969
// item for each element of the vector.
70-
let mut vals = std::mem::ManuallyDrop::new(vec![0_usize; BUCKETS]);
71-
let ptr: *mut usize = vals.as_mut_ptr();
72-
let len = vals.len();
73-
let capacity = vals.capacity();
70+
let mut raw_vals =
71+
std::mem::ManuallyDrop::new(vec![0_usize; BUCKETS]);
72+
let ptr: *mut usize = raw_vals.as_mut_ptr();
73+
let len = raw_vals.len();
74+
let capacity = raw_vals.capacity();
7475

7576
let vals: Vec<AtomicUsize> = unsafe {
7677
Vec::from_raw_parts(ptr as *mut AtomicUsize, len, capacity)
@@ -142,8 +143,7 @@ impl Histogram {
142143
let mut sum = 0.;
143144

144145
for (idx, val) in self.vals.iter().enumerate() {
145-
let count = val.load(Ordering::Acquire);
146-
sum += count as f64;
146+
sum += val.load(Ordering::Acquire) as f64;
147147

148148
if sum >= target {
149149
return decompress(idx as u16);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
clippy::path_buf_push_overwrite,
140140
clippy::print_stdout,
141141
clippy::redundant_closure_for_method_calls,
142-
clippy::shadow_reuse,
142+
// clippy::shadow_reuse,
143143
clippy::shadow_same,
144144
clippy::shadow_unrelated,
145145
clippy::single_match_else,

src/lru.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ impl Lru {
307307
let to_evict = shard.accessed(item);
308308
// map shard internal offsets to global items ids
309309
for pos in to_evict {
310-
let item =
310+
let address =
311311
(PageId::from(pos) << SHARD_BITS) + shard_idx;
312-
ret.push(item);
312+
ret.push(address);
313313
}
314314
}
315315
}

src/metrics.rs

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,21 @@ impl Metrics {
209209
"count",
210210
"sum (s)"
211211
));
212-
ret.push_str(&format!(
213-
"{}\n",
214-
"-".repeat(134)
215-
));
212+
ret.push_str(&format!("{}\n", "-".repeat(134)));
216213

217214
let p =
218215
|mut tuples: Vec<(String, _, _, _, _, _, _, _, _, _)>| -> String {
219216
tuples.sort_by_key(|t| (t.9 * -1. * 1e3) as i64);
220-
let mut ret = String::new();
217+
let mut to_ret = String::new();
221218
for v in tuples {
222-
ret.push_str(&format!(
223-
"{0: >17} | {1: >10.1} | {2: >10.1} | {3: >10.1} \
219+
to_ret.push_str(&format!(
220+
"{0: >17} | {1: >10.1} | {2: >10.1} | {3: >10.1} \
224221
| {4: >10.1} | {5: >10.1} | {6: >10.1} | {7: >10.1} \
225222
| {8: >10.1} | {9: >10.1}\n",
226-
v.0, v.1, v.2, v.3, v.4, v.5, v.6, v.7, v.8, v.9,
227-
));
223+
v.0, v.1, v.2, v.3, v.4, v.5, v.6, v.7, v.8, v.9,
224+
));
228225
}
229-
ret
226+
to_ret
230227
};
231228

232229
let lat = |name: &str, histo: &Histogram| {
@@ -241,7 +238,7 @@ impl Metrics {
241238
histo.percentile(100.) / 1e3,
242239
histo.count(),
243240
histo.sum() as f64 / 1e9,
244-
)
241+
)
245242
};
246243

247244
let sz = |name: &str, histo: &Histogram| {
@@ -256,20 +253,20 @@ impl Metrics {
256253
histo.percentile(100.),
257254
histo.count(),
258255
histo.sum() as f64,
259-
)
256+
)
260257
};
261258

262259
ret.push_str("tree:\n");
263260

264261
ret.push_str(&p(vec![
265-
lat("traverse", &self.tree_traverse),
266-
lat("get", &self.tree_get),
267-
lat("set", &self.tree_set),
268-
lat("merge", &self.tree_merge),
269-
lat("del", &self.tree_del),
270-
lat("cas", &self.tree_cas),
271-
lat("scan", &self.tree_scan),
272-
lat("rev scan", &self.tree_reverse_scan),
262+
lat("traverse", &self.tree_traverse),
263+
lat("get", &self.tree_get),
264+
lat("set", &self.tree_set),
265+
lat("merge", &self.tree_merge),
266+
lat("del", &self.tree_del),
267+
lat("cas", &self.tree_cas),
268+
lat("scan", &self.tree_scan),
269+
lat("rev scan", &self.tree_reverse_scan),
273270
]));
274271
let total_loops = self.tree_loops.load(Acquire);
275272
let total_ops = self.tree_get.count()
@@ -281,9 +278,9 @@ impl Metrics {
281278
+ self.tree_reverse_scan.count();
282279
let loop_pct = total_loops * 100 / (total_ops + 1);
283280
ret.push_str(&format!(
284-
"tree contention loops: {} ({}% retry rate)\n",
285-
total_loops, loop_pct
286-
));
281+
"tree contention loops: {} ({}% retry rate)\n",
282+
total_loops, loop_pct
283+
));
287284
ret.push_str(&format!(
288285
"tree split success rates: child({}/{}) parent({}/{}) root({}/{})\n",
289286
self.tree_child_split_success.load(Acquire)
@@ -306,10 +303,7 @@ impl Metrics {
306303
,
307304
));
308305

309-
ret.push_str(&format!(
310-
"{}\n",
311-
"-".repeat(134)
312-
));
306+
ret.push_str(&format!("{}\n", "-".repeat(134)));
313307
ret.push_str("pagecache:\n");
314308
ret.push_str(&p(vec![
315309
lat("get", &self.get_page),
@@ -325,10 +319,7 @@ impl Metrics {
325319
/ (self.get_page.count() + 1);
326320
ret.push_str(&format!("hit ratio: {}%\n", hit_ratio));
327321

328-
ret.push_str(&format!(
329-
"{}\n",
330-
"-".repeat(134)
331-
));
322+
ret.push_str(&format!("{}\n", "-".repeat(134)));
332323
ret.push_str("serialization and compression:\n");
333324
ret.push_str(&p(vec![
334325
lat("serialize", &self.serialize),
@@ -339,10 +330,7 @@ impl Metrics {
339330
lat("decompress", &self.decompress),
340331
]));
341332

342-
ret.push_str(&format!(
343-
"{}\n",
344-
"-".repeat(134)
345-
));
333+
ret.push_str(&format!("{}\n", "-".repeat(134)));
346334
ret.push_str("log:\n");
347335
ret.push_str(&p(vec![
348336
lat("make_stable", &self.make_stable),
@@ -401,10 +389,7 @@ impl Metrics {
401389
.to_formatted_string(&Locale::en)
402390
));
403391

404-
ret.push_str(&format!(
405-
"{}\n",
406-
"-".repeat(134)
407-
));
392+
ret.push_str(&format!("{}\n", "-".repeat(134)));
408393
ret.push_str("segment accountant:\n");
409394
ret.push_str(&p(vec![
410395
lat("acquire", &self.accountant_lock),
@@ -415,10 +400,7 @@ impl Metrics {
415400
lat("link", &self.accountant_mark_link),
416401
]));
417402

418-
ret.push_str(&format!(
419-
"{}\n",
420-
"-".repeat(134)
421-
));
403+
ret.push_str(&format!("{}\n", "-".repeat(134)));
422404
ret.push_str("recovery:\n");
423405
ret.push_str(&p(vec![
424406
lat("start", &self.tree_start),

src/node.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'a> From<&KeyRef<'a>> for IVec {
183183
}
184184

185185
impl<'a> KeyRef<'a> {
186-
fn unwrap_slice(&self) -> &[u8] {
186+
const fn unwrap_slice(&self) -> &[u8] {
187187
if let KeyRef::Slice(s) = self {
188188
s
189189
} else {
@@ -332,7 +332,7 @@ impl Ord for KeyRef<'_> {
332332

333333
match shared_cmp {
334334
Equal => a.len().cmp(&b.len()),
335-
other => other,
335+
other2 => other2,
336336
}
337337
}
338338
(KeyRef::Computed { .. }, KeyRef::Slice(b)) => {
@@ -1437,7 +1437,7 @@ impl Inner {
14371437
};
14381438

14391439
let total_node_storage_size = size_of::<Header>()
1440-
+ hi.map(|h| h.len()).unwrap_or(0)
1440+
+ hi.map(<[u8]>::len).unwrap_or(0)
14411441
+ lo.len()
14421442
+ key_storage_size
14431443
+ value_storage_size

0 commit comments

Comments
 (0)