Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various Clippy fixes #2781

Merged
merged 1 commit into from
Aug 1, 2024
Merged

Various Clippy fixes #2781

merged 1 commit into from
Aug 1, 2024

Conversation

Eligioo
Copy link
Member

@Eligioo Eligioo commented Jul 26, 2024

Various Clippy fixes with Rust 1.80.

Noticeable changes causing most new Clippy warnings:

The unexpected cfg condition value parallel will be addressed in a separate PR.

Copy link
Member

@hrxi hrxi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the names of the clippy warnings that you fix to the commit description?

@@ -98,7 +98,7 @@ macro_rules! as_db_bytes {
#[allow(clippy::size_of_in_element_count)]
Cow::Borrowed(slice::from_raw_parts(
self as *const $typ as *const u8,
mem::size_of::<$typ>(),
size_of::<$typ>(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the minimum required Rust version for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Sounds a bit annoying to bump up our MSRV just to silence a warning. Perhaps we can simply disable the warning for now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by allowing this Clippy lint

lib/src/extras/logging.rs Outdated Show resolved Hide resolved
@@ -18,13 +18,16 @@ use crate::{SignatureProof, Transaction, TransactionError};
/// * Create
/// * Update
/// * AddStake
/// The type of transaction, parameters and proof are given in the data field of the transaction.
///
/// The type of transaction, parameters and proof are given in the data field of the transaction.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix seems incorrect(?). It looks like it should belong inside the 1..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's part of 1. but being on the next line directly after * AddStake it thinks its part of the list thus needs to be indented up to the same level.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before: image.
After: image.

Both are incorrect, as far as I can tell.

Before, it was part of * AddStake which is clearly incorrect. Afterwards, it's now a free-standing text, but it should be part of the first enumeration item "1.".

I don't know if that can be fixed properly.

If not, perhaps we could reword the text so that

The type of transaction, parameters and proof are given in the data field of the transaction.

can right after the "1."?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

/// 2. Outgoing transactions, which include:
/// - Validator
/// * Delete
/// - Staker
/// * RemoveStake
/// The type of transaction, parameters and proof are given in the proof field of the transaction.
///
/// The type of transaction, parameters and proof are given in the proof field of the transaction.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

@@ -93,7 +93,7 @@ impl fmt::Display for CompressedSignature {
impl From<G1Projective> for CompressedSignature {
fn from(signature: G1Projective) -> Self {
let mut buffer = [0u8; SIZE];
CanonicalSerialize::serialize_compressed(&signature.into_affine(), &mut &mut buffer[..])
CanonicalSerialize::serialize_compressed(&signature.into_affine(), &mut buffer[..])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What warning does this fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the borrowed expression implements the required traits
  --> bls/src/types/compressed_signature.rs:96:76
   |
96 |         CanonicalSerialize::serialize_compressed(&signature.into_affine(), &mut &mut buffer[..])
   |                                                                            ^^^^^^^^^^^^^^^^^^^^ help: change this to: `&mut buffer[..]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
   = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default

@Eligioo Eligioo marked this pull request as ready for review July 26, 2024 12:54
@Eligioo Eligioo force-pushed the stefan/clippy-fixes branch 3 times, most recently from e223b8b to ac7a4f3 Compare July 31, 2024 12:18
Fixes: unexpected `cfg` condition name: `tokio_unstable` by setting `workspace.lints.rust.unexpected_cfgs`
Fixes: doc list item missing indentation
Ignore lint until MSVR 1.80: unnecessary qualification of `mem` in `mem::size_of`
Fixes: unnecessary qualification of `nimiq_database::mdbx` in `nimiq_database::mdbx::MdbxDatabase`
Fixes: the borrowed expression implements the required traits in case of `&mut &mut buffer`

The unexpected cfg condition value 'parallel' in the primitives crate will be addressed in a separate PR by @ii-cruz
Copy link
Member

@hrxi hrxi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@hrxi hrxi merged commit b0eff5c into albatross Aug 1, 2024
7 checks passed
@hrxi hrxi deleted the stefan/clippy-fixes branch August 1, 2024 14:40
@jsdanielh jsdanielh added this to the Nimiq PoS Mainnet milestone Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants