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

rust: setup clippy lints and fix existing lint issues #4455

Merged
merged 1 commit into from
Feb 4, 2022

Conversation

ptrus
Copy link
Member

@ptrus ptrus commented Jan 28, 2022

Fixes: #4170

@ptrus ptrus added the s:ready-ci Status: ready for CI label Jan 28, 2022
@ptrus ptrus force-pushed the ptrus/feature/rust-lints branch 8 times, most recently from d8c7b46 to 8fa4652 Compare January 31, 2022 13:26
@codecov
Copy link

codecov bot commented Jan 31, 2022

Codecov Report

Merging #4455 (cb18563) into master (795eb65) will increase coverage by 0.17%.
The diff coverage is 70.40%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4455      +/-   ##
==========================================
+ Coverage   68.66%   68.83%   +0.17%     
==========================================
  Files         415      415              
  Lines       46571    46799     +228     
==========================================
+ Hits        31976    32214     +238     
+ Misses      10635    10625      -10     
  Partials     3960     3960              
Impacted Files Coverage Δ
go/consensus/tendermint/abci/mux.go 59.15% <0.00%> (+3.28%) ⬆️
go/consensus/tendermint/api/app.go 0.00% <0.00%> (ø)
go/consensus/tendermint/apps/beacon/beacon.go 73.77% <0.00%> (ø)
...consensus/tendermint/apps/keymanager/keymanager.go 62.63% <0.00%> (ø)
go/consensus/tendermint/apps/registry/genesis.go 47.32% <0.00%> (ø)
...o/consensus/tendermint/apps/scheduler/scheduler.go 71.14% <0.00%> (ø)
...nt/apps/supplementarysanity/supplementarysanity.go 77.61% <0.00%> (ø)
go/roothash/api/api.go 80.00% <ø> (ø)
go/runtime/registry/host.go 71.88% <0.00%> (-4.81%) ⬇️
go/staking/api/api.go 62.33% <ø> (ø)
... and 46 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44b27c2...cb18563. Read the comment docs.

@ptrus ptrus marked this pull request as ready for review January 31, 2022 14:52
Copy link
Contributor

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

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

23/74

hold on let me empty out the linter

wordcloud

if data.len() < 1 + Self::size() {
panic!("key format: malformed input");
}
assert!(data.len() > Self::size(), "key format: malformed input");
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd somehow find this more understandable with data.len() >= 1 + Self::size()

Copy link
Member Author

Choose a reason for hiding this comment

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

Clippy disagrees: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one
but we can disable that rule if we prefer not to enforce it.

Copy link
Contributor

Choose a reason for hiding this comment

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

we could make it more formal

const VERSION_PREFIX_SIZE: usize = the_size_of_a_u8;
data.len() >= VERSION_PREFIX_SIZE + Self:size()

Copy link
Contributor

@pro-wh pro-wh Feb 1, 2022

Choose a reason for hiding this comment

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

or let's go with clippy's (probably less thoughtful) recommendation and add a comment about "must be strictly greater than because there must additionally be a version prefix thingy"

addendum: "and the prefix is exactly one byte, so it suffices only to use > instead of >=. marvel at our resourcefulness"

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I see, I thought you generally preferred the 1+ version. Yeah I can make this case clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the code with the VERSION_PREFIX_SIZE approach.

runtime/src/common/key_format.rs Show resolved Hide resolved
@ptrus ptrus force-pushed the ptrus/feature/rust-lints branch 2 times, most recently from d847286 to 6094e68 Compare February 1, 2022 15:51
Copy link
Contributor

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

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

50/74

runtime/src/consensus/tendermint/verifier.rs Show resolved Hide resolved
runtime/src/storage/mkvs/cache/cache.rs Show resolved Hide resolved
}

/// Callback type used for updating cache items after a commit.
pub type CacheUpdater<C> = Box<dyn Fn(&mut C)>;
Copy link
Contributor

Choose a reason for hiding this comment

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

ℹ️ -> () removed

runtime/src/storage/mkvs/sync/mod.rs Show resolved Hide resolved
Copy link
Contributor

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

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

74/74

emptying out the linter again

wordcloud2

}

/// Commit the options set so far into a newly constructed tree instance.
pub fn new_tree(self, read_syncer: Box<dyn ReadSync>) -> Tree {
Copy link
Contributor

Choose a reason for hiding this comment

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

ℹ️ this replaces new. and other minor doesn't-affect-interface changes below

  • couple of if { panic } changed to assert
  • field: field shorthand
  • vec ref to slice

if let NodeKind::Internal = classify_noderef!(nd_child) {
if let NodeBox::Internal(ref mut inode) = *nd_child.borrow_mut()
{
inode.label = noderef_as!(node_ref, Internal).label.merge(
Copy link
Contributor

Choose a reason for hiding this comment

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

lol this macro work is scary

@ptrus ptrus force-pushed the ptrus/feature/rust-lints branch 2 times, most recently from 3d73468 to 5280ba6 Compare February 3, 2022 15:22
runtime/src/common/crypto/signature.rs Outdated Show resolved Hide resolved
runtime/src/common/key_format.rs Outdated Show resolved Hide resolved
runtime/src/common/sgx/avr.rs Outdated Show resolved Hide resolved
runtime/src/consensus/registry.rs Outdated Show resolved Hide resolved
runtime/src/storage/mkvs/tree/iterator.rs Outdated Show resolved Hide resolved
runtime/src/storage/mkvs/tree/tree.rs Outdated Show resolved Hide resolved
@ptrus ptrus force-pushed the ptrus/feature/rust-lints branch 3 times, most recently from ee6bd85 to 154cce9 Compare February 4, 2022 16:21
@ptrus ptrus merged commit 80f8c9a into master Feb 4, 2022
@ptrus ptrus deleted the ptrus/feature/rust-lints branch February 4, 2022 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s:ready-ci Status: ready for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup rust code linting
4 participants