Unverified Commit c50f93ce authored by Michael Müller's avatar Michael Müller Committed by GitHub
Browse files

Fix nightly clippy errors (#760)

* Fix `clippy:wrong_self_convention`

error: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value
   --> crates/primitives/src/key.rs:172:21
    |
172 |     pub fn to_bytes(&self) -> [u8; 32] {
    |                     ^^^^^
    |
    = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
    = help: consider choosing a less ambiguous name
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention

error: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value
   --> crates/primitives/src/key.rs:186:29
    |
186 |     fn to_bytes_be_fallback(&self) -> [u8; 32] {
    |                             ^^^^^
    |
    = help: consider choosing a less ambiguous name
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention

* Fix `clippy:branches_sharing_code` for `bitvec`

error: all if blocks contain the same code at the end
   --> crates/storage/src/collections/bitvec/mod.rs:280:9
    |
280 | /             *self.len += 1;
281 | |             if value {
282 | |                 self.last_mut()
283 | |                     .expect("must have at least a valid bit in this case")
284 | |                     .set()
285 | |             }
286 | |         }
    | |_________^
    |
    = note: `-D clippy::branches-sharing-code` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code

* Fix `clippy:branches_sharing_code` for `stash`

error: all if blocks contain the same code at the start
   --> crates/storage/src/collections/stash/mod.rs:308:9
    |
308 | /         if prev_vacant == next_vacant {
309 | |             // There is only one other vacant entry left.
310 | |             // We can update the single vacant entry in a single look-up.
311 | |             let entry = self
...   |
315 | |                 .flatten()
316 | |                 .expect("`prev` must point to an existing entry at this point");
    | |________________________________________________________________________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code

* Add benchmark for "Fix `clippy:wrong_self_convention`"

* Revert "Add benchmark for "Fix `clippy:wrong_self_convention`""

This reverts commit 9fabbfd1.

* Remove empty line
parent 1f184b61
Pipeline #134787 passed with stages
in 43 minutes and 45 seconds
......@@ -169,7 +169,7 @@ impl scale::Decode for Key {
impl Key {
/// Returns the bytes that are representing the key.
#[inline]
pub fn to_bytes(&self) -> [u8; 32] {
pub fn to_bytes(self) -> [u8; 32] {
if cfg!(target_endian = "little") {
// SAFETY: This pointer cast is possible since the outer struct
// (Key) is `repr(transparent)` and since we restrict
......@@ -183,7 +183,7 @@ impl Key {
}
/// Fallback big-endian procedure to return the underlying bytes of `self`.
fn to_bytes_be_fallback(&self) -> [u8; 32] {
fn to_bytes_be_fallback(self) -> [u8; 32] {
let mut result = [0x00; 32];
for i in 0..4 {
let o = i * 8;
......
......@@ -272,17 +272,17 @@ impl Bitvec {
};
self.bits.push(bits256);
*self.len += 1;
} else {
// Case: The last 256-bit pack has unused bits:
// - Set last bit of last 256-bit pack to the given value.
// - Opt.: Since bits are initialized as 0 we only need
// to mutate this value if `value` is `true`.
*self.len += 1;
if value {
self.last_mut()
.expect("must have at least a valid bit in this case")
.set()
}
return
}
// Case: The last 256-bit pack has unused bits:
// - Set last bit of last 256-bit pack to the given value.
// - Opt.: Since bits are initialized as 0 we only need
// to mutate this value if `value` is `true`.
*self.len += 1;
if value {
self.last_mut()
.expect("must have at least a valid bit in this case")
.set()
}
}
......
......@@ -305,27 +305,21 @@ where
self.header.last_vacant = self.header.len;
return
}
let prev = self
.entries
.get_mut(prev_vacant)
.map(Entry::try_to_vacant_mut)
.flatten()
.expect("`prev` must point to an existing entry at this point");
if prev_vacant == next_vacant {
// There is only one other vacant entry left.
// We can update the single vacant entry in a single look-up.
let entry = self
.entries
.get_mut(prev_vacant)
.map(Entry::try_to_vacant_mut)
.flatten()
.expect("`prev` must point to an existing entry at this point");
debug_assert_eq!(entry.prev, removed_index);
debug_assert_eq!(entry.next, removed_index);
entry.prev = prev_vacant;
entry.next = prev_vacant;
debug_assert_eq!(prev.prev, removed_index);
debug_assert_eq!(prev.next, removed_index);
prev.prev = prev_vacant;
prev.next = prev_vacant;
} else {
// There are multiple other vacant entries left.
let prev = self
.entries
.get_mut(prev_vacant)
.map(Entry::try_to_vacant_mut)
.flatten()
.expect("`prev` must point to an existing entry at this point");
debug_assert_eq!(prev.next, removed_index);
prev.next = next_vacant;
let next = self
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment