-
Notifications
You must be signed in to change notification settings - Fork 115
Clippy test warnings #365
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
base: main
Are you sure you want to change the base?
Clippy test warnings #365
Conversation
cd2b9b0 to
3145d36
Compare
XanClic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just some nit picks, mainly:
- If we’re asserting a value in an address that’s been part of the previous code, it should have the same form as previously, i.e. assert on
usize::MAXinstead of18446744073709551615and on0x600instead of1536if the value was previously given as0x600. Especially so in examples that end up in documentation. - I’m not sure about dropping
assert!(foo.is_ok())from documentation examples just because it’s immediately followed byfoo.unwrap(). I’m all for replacing.is_ok()by.unwrap()in tests, but in examples,.is_ok()adds an explicit “We’re not just unwrapping for simplicity’s sake, but this example is actually supposed to show that this operation will returnOk(_)”.
| assert_matches!( | ||
| slice.subslice(0, 101).unwrap_err(), | ||
| Error::OutOfBounds { addr: 101 } | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not up to this PR but a general question to everyone: Why does this (and the ones below) report 101? That address is not part of the requested subslice, instead it should be 100 in my understanding…
I think compute_end_offset() should use addr: cmp::max(self.len(), base) instead of addr: mem_end, and VolatileSlice::offset() should use addr: self.addr + self.size (or something like that) instead of addr: new_addr.
(As for this PR, this is a nice example why using this assertion style is better :))
3145d36 to
7fd16cb
Compare
|
Hi @XanClic thank you for taking the time to review this, I have addressed your comments :) |
Signed-off-by: Daniel Vallance <[email protected]>
Signed-off-by: Daniel Vallance <[email protected]>
111dcae to
2a05c9c
Compare
XanClic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! :)
This PR enables clippy::assertions_on_result_states, because asserting that a Result is_ok(), or is_err() causes the unit test failure messages to be quite unhelpful (as described in issue 337 #337).
It also addresses a couple of other clippy warnings.