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

fix new 1.81.0 warning and clippy error #760

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/propolis-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ async fn migrate_instance(
.collect::<Result<Vec<_>, _>>()?
// Then any errors from polling the source/destination
.into_iter()
.collect::<anyhow::Result<_>>()?;
.collect::<anyhow::Result<()>>()?;

Ok(())
}
Expand Down
14 changes: 7 additions & 7 deletions bin/propolis-utils/src/bin/cpuid-gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ fn create_vm() -> anyhow::Result<VmmFd> {
let ctl = VmmCtlFd::open()?;
let _ = unsafe { ctl.ioctl(bhyve_api::VMM_CREATE_VM, &mut req) }?;

let vm = VmmFd::open(&name).map_err(|e| {
let vm = VmmFd::open(&name).inspect_err(|_e| {
// Attempt to manually destroy the VM if we cannot open it
Copy link
Member Author

Choose a reason for hiding this comment

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

this suggestion kinda makes my skin crawl. "inspect_err" sounds a lot like you should expect println!() or something boring to follow, but on the next like we are destroying a resource because of the error. i'm not interested in adding #![allow(clippy::manual_inspect)] in an ad-hoc manner at crate roots though, so.. this what the suggested fix looks like.

Copy link
Contributor

Choose a reason for hiding this comment

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

Optional, just noodling on the problem a bit: does it look any better to write it out by hand?

let vm = VmmFd::open(&name);
if vm.is_err() {
    let _ = ctl.vm_destroy(name.as_bytes());
}
let vm = vm?;

Or we could just write out the ? match explicitly. I don't have especially strong feelings here--it does seem like inspect is not quite the right verb for what we're trying to do here, but I'm not too sure map was either, since this wasn't transforming the error at all. Up to you in any case.

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'd given that one a try and realized i was having a hard time reading it after the fact, since the ? and exit control flow is separated away from .is_err(). an explicit match would probably read fine though, i'll do that in a sec

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for the drive-by comment, but might this be or_else?

let vm = VmmFd::open(&name).or_else(|e| {
    let _ = ctl.vm_destroy(name.as_bytes());
    Err(e)
})?;

To me, the or_else says "we're doing something if this fails."

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'd have liked or_else a lot but it turns out that is also on the path to inspect_err: that results in Clippy offering "using Result.or_else(|x| Err(y)), which is more succinctly expressed as map_err(|x| y). it's right, but then with that transform Clippy points towards inspect_err. 🙃

anyway, i've adjusted this to be an explicit match on both cases. seems fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aww Clippy, why ya gotta be like that? :-/

let _ = ctl.vm_destroy(name.as_bytes());
e
})?;

vm.ioctl_usize(bhyve_api::ioctls::VM_SET_AUTODESTRUCT, 1).map_err(|e| {
// Destroy instance if auto-destruct cannot be set
let _ = vm.ioctl_usize(bhyve_api::VM_DESTROY_SELF, 0);
e
})?;
vm.ioctl_usize(bhyve_api::ioctls::VM_SET_AUTODESTRUCT, 1).inspect_err(
|_e| {
// Destroy instance if auto-destruct cannot be set
let _ = vm.ioctl_usize(bhyve_api::VM_DESTROY_SELF, 0);
},
)?;

Ok(vm)
}
Expand Down
4 changes: 4 additions & 0 deletions lib/propolis/src/firmware/smbios/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ pub(crate) struct Type1 {
}
raw_table_impl!(Type1, 1);

// We don't create type 2 tables yet, but it's nice to have the definition on hand.
/// Type 2 (Baseboard Information)
#[derive(Copy, Clone)]
#[repr(C, packed)]
#[allow(dead_code)]
pub(crate) struct Type2 {
pub header: StructureHeader,
pub manufacturer: u8,
Expand All @@ -159,9 +161,11 @@ pub(crate) struct Type2 {
}
raw_table_impl!(Type2, 2);

// We don't create type 3 tables yet, but it's nice to have the definition on hand.
/// Type 3 (System Enclosure) - Version 2.7
#[derive(Copy, Clone)]
#[repr(C, packed)]
#[allow(dead_code)]
pub(crate) struct Type3 {
pub header: StructureHeader,
pub manufacturer: u8,
Expand Down
Loading