diff --git a/Cargo.toml b/Cargo.toml index f7fe0e733..a0cb1a171 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,11 +13,11 @@ members = [ [workspace.package] authors = ["The Rust OSDev team"] categories = ["embedded", "no-std", "api-bindings"] -edition = "2021" +edition = "2024" keywords = ["uefi", "efi"] license = "MIT OR Apache-2.0" repository = "https://github.com/rust-osdev/uefi-rs" -rust-version = "1.81" +rust-version = "1.85.1" [workspace.dependencies] bitflags = "2.0.0" diff --git a/flake.lock b/flake.lock index e97a8b0f2..4f80b7a3e 100644 --- a/flake.lock +++ b/flake.lock @@ -43,11 +43,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1740882709, - "narHash": "sha256-VC+8GxWK4p08jjIbmsNfeFQajW2lsiOR/XQiOOvqgvs=", + "lastModified": 1742697269, + "narHash": "sha256-Lpp0XyAtIl1oGJzNmTiTGLhTkcUjwSkEb0gOiNzYFGM=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "f4d5a693c18b389f0d58f55b6f7be6ef85af186f", + "rev": "01973c84732f9275c50c5f075dd1f54cc04b3316", "type": "github" }, "original": { diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000..f396ceb51 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,8 @@ +# We keep this file explicitley to ensure that direct invocations of `rustfmt` +# also use the proper style edition. Unlike `cargo fmt`, which forwards the +# Rust edition specified in Cargo.toml to `rustfmt`, `rustfmt` still defaults to +# the 2021 edition and is unaware of `Cargo.toml`. +# +# We use a direct invocation of `rustfmt` in our device path generation code. + +style_edition = "2024" diff --git a/template/Cargo.toml b/template/Cargo.toml index fb010881d..1f264f662 100644 --- a/template/Cargo.toml +++ b/template/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "uefi_app" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/uefi-macros/CHANGELOG.md b/uefi-macros/CHANGELOG.md index 7b50262b8..334e74c32 100644 --- a/uefi-macros/CHANGELOG.md +++ b/uefi-macros/CHANGELOG.md @@ -1,5 +1,8 @@ # uefi-macros - [Unreleased] +## Changed + +- **Breaking:** The MSRV is now 1.85.1 and the crate uses the Rust 2024 edition. # uefi-macros - 0.18.0 (2025-02-07) diff --git a/uefi-macros/src/lib.rs b/uefi-macros/src/lib.rs index 94bb01f0d..56357b8e1 100644 --- a/uefi-macros/src/lib.rs +++ b/uefi-macros/src/lib.rs @@ -7,11 +7,11 @@ extern crate proc_macro; use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, quote_spanned, TokenStreamExt}; +use quote::{TokenStreamExt, quote, quote_spanned}; use syn::spanned::Spanned; use syn::{ - parse_macro_input, parse_quote, parse_quote_spanned, Error, Expr, ExprLit, ExprPath, ItemFn, - ItemStruct, Lit, Visibility, + Error, Expr, ExprLit, ExprPath, ItemFn, ItemStruct, Lit, Visibility, parse_macro_input, + parse_quote, parse_quote_spanned, }; macro_rules! err { @@ -74,7 +74,7 @@ pub fn unsafe_protocol(args: TokenStream, input: TokenStream) -> TokenStream { expr, "macro input must be either a string literal or path to a constant" ) - .into() + .into(); } }; @@ -215,7 +215,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { let result = quote! { #fn_type_check - #[export_name = "efi_main"] + #[unsafe(export_name = "efi_main")] #f }; diff --git a/uefi-raw/CHANGELOG.md b/uefi-raw/CHANGELOG.md index 590735292..d27ae215d 100644 --- a/uefi-raw/CHANGELOG.md +++ b/uefi-raw/CHANGELOG.md @@ -10,6 +10,10 @@ - Added `DiskInfoProtocol`. - Added `ExtScsiPassThruProtocol`. +## Changed + +- **Breaking:** The MSRV is now 1.85.1 and the crate uses the Rust 2024 edition. + # uefi-raw - 0.10.0 (2025-02-07) diff --git a/uefi-raw/Cargo.toml b/uefi-raw/Cargo.toml index 6bb736118..ca9338c7d 100644 --- a/uefi-raw/Cargo.toml +++ b/uefi-raw/Cargo.toml @@ -16,7 +16,7 @@ license.workspace = true repository.workspace = true # uefi-raw is much less likely to need the latest bleeding-edge features. # Hence, it is okay to not use the workspace MSRV. -rust-version = "1.77" +rust-version = "1.85.1" [dependencies] bitflags.workspace = true diff --git a/uefi-raw/src/lib.rs b/uefi-raw/src/lib.rs index 7f8050b56..a67ac564d 100644 --- a/uefi-raw/src/lib.rs +++ b/uefi-raw/src/lib.rs @@ -34,7 +34,7 @@ pub mod time; mod status; pub use status::Status; -pub use uguid::{guid, Guid}; +pub use uguid::{Guid, guid}; use core::ffi::c_void; use core::fmt::{self, Debug, Formatter}; diff --git a/uefi-raw/src/protocol/block.rs b/uefi-raw/src/protocol/block.rs index 571aa71a4..fb6a98fa4 100644 --- a/uefi-raw/src/protocol/block.rs +++ b/uefi-raw/src/protocol/block.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{guid, Boolean, Guid, Status}; +use crate::{Boolean, Guid, Status, guid}; use core::ffi::c_void; /// Logical block address. diff --git a/uefi-raw/src/protocol/console.rs b/uefi-raw/src/protocol/console.rs index 86b2332dd..c34f7c0ae 100644 --- a/uefi-raw/src/protocol/console.rs +++ b/uefi-raw/src/protocol/console.rs @@ -2,7 +2,7 @@ pub mod serial; -use crate::{guid, Boolean, Char16, Event, Guid, PhysicalAddress, Status}; +use crate::{Boolean, Char16, Event, Guid, PhysicalAddress, Status, guid}; use bitflags::bitflags; use core::ptr; diff --git a/uefi-raw/src/protocol/console/serial.rs b/uefi-raw/src/protocol/console/serial.rs index 0050f209a..675f5570d 100644 --- a/uefi-raw/src/protocol/console/serial.rs +++ b/uefi-raw/src/protocol/console/serial.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{guid, Guid, Status}; +use crate::{Guid, Status, guid}; use bitflags::bitflags; bitflags! { diff --git a/uefi-raw/src/protocol/device_path.rs b/uefi-raw/src/protocol/device_path.rs index 0cf3eae81..8febf7dc8 100644 --- a/uefi-raw/src/protocol/device_path.rs +++ b/uefi-raw/src/protocol/device_path.rs @@ -2,7 +2,7 @@ mod device_path_gen; -use crate::{guid, Boolean, Char16, Guid}; +use crate::{Boolean, Char16, Guid, guid}; pub use device_path_gen::{acpi, bios_boot_spec, end, hardware, media, messaging}; diff --git a/uefi-raw/src/protocol/device_path/device_path_gen.rs b/uefi-raw/src/protocol/device_path/device_path_gen.rs index 9914779c4..825a27929 100644 --- a/uefi-raw/src/protocol/device_path/device_path_gen.rs +++ b/uefi-raw/src/protocol/device_path/device_path_gen.rs @@ -10,7 +10,7 @@ #![allow(missing_debug_implementations)] use crate::protocol::device_path; use crate::table::boot::MemoryType; -use crate::{guid, Guid, IpAddress}; +use crate::{Guid, IpAddress, guid}; use bitflags::bitflags; use device_path::DevicePathProtocol as DevicePathHeader; #[cfg(doc)] diff --git a/uefi-raw/src/protocol/disk.rs b/uefi-raw/src/protocol/disk.rs index a9ff3b6bf..f43590774 100644 --- a/uefi-raw/src/protocol/disk.rs +++ b/uefi-raw/src/protocol/disk.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{guid, Event, Guid, Status}; +use crate::{Event, Guid, Status, guid}; use core::ffi::c_void; #[derive(Debug)] diff --git a/uefi-raw/src/protocol/driver.rs b/uefi-raw/src/protocol/driver.rs index 9e16d7890..119a6f65c 100644 --- a/uefi-raw/src/protocol/driver.rs +++ b/uefi-raw/src/protocol/driver.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::protocol::device_path::DevicePathProtocol; -use crate::{guid, Guid, Handle, Status}; +use crate::{Guid, Handle, Status, guid}; #[derive(Debug)] #[repr(C)] diff --git a/uefi-raw/src/protocol/file_system.rs b/uefi-raw/src/protocol/file_system.rs index 71a06de18..f6d1cb403 100644 --- a/uefi-raw/src/protocol/file_system.rs +++ b/uefi-raw/src/protocol/file_system.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::time::Time; -use crate::{guid, Boolean, Char16, Event, Guid, Status}; +use crate::{Boolean, Char16, Event, Guid, Status, guid}; use bitflags::bitflags; use core::ffi::c_void; diff --git a/uefi-raw/src/protocol/firmware_volume.rs b/uefi-raw/src/protocol/firmware_volume.rs index 2dfd98916..9184700f1 100644 --- a/uefi-raw/src/protocol/firmware_volume.rs +++ b/uefi-raw/src/protocol/firmware_volume.rs @@ -2,7 +2,7 @@ use crate::firmware_storage::FirmwareVolumeAttributes; use crate::protocol::block::Lba; -use crate::{guid, Guid, Handle, PhysicalAddress, Status}; +use crate::{Guid, Handle, PhysicalAddress, Status, guid}; use core::ffi::c_void; use core::ops::RangeInclusive; diff --git a/uefi-raw/src/protocol/hii/database.rs b/uefi-raw/src/protocol/hii/database.rs index 054f81e54..a701f9914 100644 --- a/uefi-raw/src/protocol/hii/database.rs +++ b/uefi-raw/src/protocol/hii/database.rs @@ -3,7 +3,7 @@ //! Bindings for HII Database Protocol use super::{HiiHandle, HiiPackageHeader, HiiPackageListHeader, KeyDescriptor}; -use crate::{guid, Guid, Handle, Status}; +use crate::{Guid, Handle, Status, guid}; /// EFI_HII_KEYBOARD_LAYOUT #[derive(Debug)] diff --git a/uefi-raw/src/protocol/loaded_image.rs b/uefi-raw/src/protocol/loaded_image.rs index 7ba4ada6a..fff5ece06 100644 --- a/uefi-raw/src/protocol/loaded_image.rs +++ b/uefi-raw/src/protocol/loaded_image.rs @@ -3,7 +3,7 @@ use crate::protocol::device_path::DevicePathProtocol; use crate::table::boot::MemoryType; use crate::table::system::SystemTable; -use crate::{guid, Guid, Handle, Status}; +use crate::{Guid, Handle, Status, guid}; use core::ffi::c_void; #[derive(Clone, Copy, Debug)] diff --git a/uefi-raw/src/protocol/media.rs b/uefi-raw/src/protocol/media.rs index 2d1fe5d40..6baffb108 100644 --- a/uefi-raw/src/protocol/media.rs +++ b/uefi-raw/src/protocol/media.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::protocol::device_path::DevicePathProtocol; -use crate::{guid, Boolean, Guid, Status}; +use crate::{Boolean, Guid, Status, guid}; use core::ffi::c_void; #[derive(Debug)] diff --git a/uefi-raw/src/protocol/memory_protection.rs b/uefi-raw/src/protocol/memory_protection.rs index 8e3198990..21c9defdb 100644 --- a/uefi-raw/src/protocol/memory_protection.rs +++ b/uefi-raw/src/protocol/memory_protection.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::table::boot::MemoryAttribute; -use crate::{guid, Guid, PhysicalAddress, Status}; +use crate::{Guid, PhysicalAddress, Status, guid}; #[derive(Debug)] #[repr(C)] diff --git a/uefi-raw/src/protocol/misc.rs b/uefi-raw/src/protocol/misc.rs index a6048c471..2fb9c4982 100644 --- a/uefi-raw/src/protocol/misc.rs +++ b/uefi-raw/src/protocol/misc.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::table::runtime; -use crate::{guid, Guid, Status}; +use crate::{Guid, Status, guid}; #[derive(Debug)] #[repr(C)] diff --git a/uefi-raw/src/protocol/network/dhcp4.rs b/uefi-raw/src/protocol/network/dhcp4.rs index 9f26dc0ef..c8ee47098 100644 --- a/uefi-raw/src/protocol/network/dhcp4.rs +++ b/uefi-raw/src/protocol/network/dhcp4.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{guid, Boolean, Char8, Event, Guid, Ipv4Address, MacAddress, Status}; +use crate::{Boolean, Char8, Event, Guid, Ipv4Address, MacAddress, Status, guid}; use core::ffi::c_void; newtype_enum! { diff --git a/uefi-raw/src/protocol/network/http.rs b/uefi-raw/src/protocol/network/http.rs index 99ff1220b..115f5fe18 100644 --- a/uefi-raw/src/protocol/network/http.rs +++ b/uefi-raw/src/protocol/network/http.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{guid, Boolean, Char16, Char8, Event, Guid, Ipv4Address, Ipv6Address, Status}; +use crate::{Boolean, Char8, Char16, Event, Guid, Ipv4Address, Ipv6Address, Status, guid}; use core::ffi::c_void; use core::fmt::{self, Debug, Formatter}; use core::ptr; diff --git a/uefi-raw/src/protocol/network/ip4_config2.rs b/uefi-raw/src/protocol/network/ip4_config2.rs index 41f334b05..2bed6937d 100644 --- a/uefi-raw/src/protocol/network/ip4_config2.rs +++ b/uefi-raw/src/protocol/network/ip4_config2.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::protocol::network::ip4::Ip4RouteTable; -use crate::{guid, Char16, Event, Guid, Ipv4Address, MacAddress, Status}; +use crate::{Char16, Event, Guid, Ipv4Address, MacAddress, Status, guid}; use core::ffi::c_void; newtype_enum! { diff --git a/uefi-raw/src/protocol/network/pxe.rs b/uefi-raw/src/protocol/network/pxe.rs index a0bdc6a6f..15d1a39b6 100644 --- a/uefi-raw/src/protocol/network/pxe.rs +++ b/uefi-raw/src/protocol/network/pxe.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{guid, Boolean, Char8, Guid, IpAddress, MacAddress, Status}; +use crate::{Boolean, Char8, Guid, IpAddress, MacAddress, Status, guid}; use bitflags::bitflags; use core::ffi::c_void; use core::fmt::{self, Debug, Formatter}; diff --git a/uefi-raw/src/protocol/network/tls.rs b/uefi-raw/src/protocol/network/tls.rs index 905c57b48..fc7c7f569 100644 --- a/uefi-raw/src/protocol/network/tls.rs +++ b/uefi-raw/src/protocol/network/tls.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{guid, Guid, Status}; +use crate::{Guid, Status, guid}; use core::ffi::c_void; newtype_enum! { diff --git a/uefi-raw/src/protocol/rng.rs b/uefi-raw/src/protocol/rng.rs index b1efc5489..40984f051 100644 --- a/uefi-raw/src/protocol/rng.rs +++ b/uefi-raw/src/protocol/rng.rs @@ -2,7 +2,7 @@ //! `Rng` protocol. -use crate::{guid, Guid, Status}; +use crate::{Guid, Status, guid}; newtype_enum! { /// The algorithms listed are optional, not meant to be exhaustive diff --git a/uefi-raw/src/protocol/scsi.rs b/uefi-raw/src/protocol/scsi.rs index d3c1537e4..1d8cdad39 100644 --- a/uefi-raw/src/protocol/scsi.rs +++ b/uefi-raw/src/protocol/scsi.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use super::device_path::DevicePathProtocol; -use crate::{guid, Event, Guid, Status}; +use crate::{Event, Guid, Status, guid}; use core::ffi::c_void; pub const SCSI_TARGET_MAX_BYTES: usize = 0x10; diff --git a/uefi-raw/src/protocol/shell_params.rs b/uefi-raw/src/protocol/shell_params.rs index 70671a748..4b5b8bf46 100644 --- a/uefi-raw/src/protocol/shell_params.rs +++ b/uefi-raw/src/protocol/shell_params.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{guid, Char16, Guid}; +use crate::{Char16, Guid, guid}; use core::ffi::c_void; pub type ShellFileHandle = *const c_void; diff --git a/uefi-raw/src/protocol/string.rs b/uefi-raw/src/protocol/string.rs index 9c792d4fd..37b9695ca 100644 --- a/uefi-raw/src/protocol/string.rs +++ b/uefi-raw/src/protocol/string.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{guid, Char16, Char8, Guid}; +use crate::{Char8, Char16, Guid, guid}; #[derive(Debug)] #[repr(C)] diff --git a/uefi-raw/src/protocol/tcg/v1.rs b/uefi-raw/src/protocol/tcg/v1.rs index 32bcb3b96..40c06012f 100644 --- a/uefi-raw/src/protocol/tcg/v1.rs +++ b/uefi-raw/src/protocol/tcg/v1.rs @@ -10,7 +10,7 @@ //! [TCG]: https://trustedcomputinggroup.org/ //! [TPM]: https://en.wikipedia.org/wiki/Trusted_Platform_Module -use crate::{guid, Guid, PhysicalAddress, Status}; +use crate::{Guid, PhysicalAddress, Status, guid}; use core::ffi::c_void; /// Information about the protocol and the TPM device. diff --git a/uefi-raw/src/protocol/tcg/v2.rs b/uefi-raw/src/protocol/tcg/v2.rs index 7021ffccb..a92c8c9b4 100644 --- a/uefi-raw/src/protocol/tcg/v2.rs +++ b/uefi-raw/src/protocol/tcg/v2.rs @@ -13,7 +13,7 @@ //! [TPM]: https://en.wikipedia.org/wiki/Trusted_Platform_Module use super::EventType; -use crate::{guid, Guid, PhysicalAddress, Status}; +use crate::{Guid, PhysicalAddress, Status, guid}; use bitflags::bitflags; use core::ffi::c_void; diff --git a/uefi-raw/src/table/runtime.rs b/uefi-raw/src/table/runtime.rs index e2f60202d..2738e5b8e 100644 --- a/uefi-raw/src/table/runtime.rs +++ b/uefi-raw/src/table/runtime.rs @@ -3,10 +3,10 @@ //! UEFI services available at runtime, even after the OS boots. use crate::capsule::CapsuleHeader; -use crate::table::boot::MemoryDescriptor; use crate::table::Header; +use crate::table::boot::MemoryDescriptor; use crate::time::Time; -use crate::{guid, Boolean, Char16, Guid, PhysicalAddress, Status}; +use crate::{Boolean, Char16, Guid, PhysicalAddress, Status, guid}; use bitflags::bitflags; use core::ffi::c_void; diff --git a/uefi-raw/src/table/system.rs b/uefi-raw/src/table/system.rs index 3faaee536..0a6d94273 100644 --- a/uefi-raw/src/table/system.rs +++ b/uefi-raw/src/table/system.rs @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::protocol::console::{SimpleTextInputProtocol, SimpleTextOutputProtocol}; +use crate::table::Header; use crate::table::boot::BootServices; use crate::table::configuration::ConfigurationTable; use crate::table::runtime::RuntimeServices; -use crate::table::Header; use crate::{Char16, Handle}; use core::mem::size_of; use core::ptr; diff --git a/uefi-std-example/Cargo.toml b/uefi-std-example/Cargo.toml index 5a2e3e293..9ec083c34 100644 --- a/uefi-std-example/Cargo.toml +++ b/uefi-std-example/Cargo.toml @@ -3,7 +3,7 @@ name = "uefi-std-example" version = "0.1.0" authors = ["The Rust OSDev team"] publish = false -edition = "2021" +edition = "2024" [dependencies] # Attention: Don't activate the panic_handler feature, as it will clash with diff --git a/uefi-test-runner/Cargo.toml b/uefi-test-runner/Cargo.toml index f52406776..d608362a4 100644 --- a/uefi-test-runner/Cargo.toml +++ b/uefi-test-runner/Cargo.toml @@ -3,7 +3,7 @@ name = "uefi-test-runner" version = "0.2.0" authors = ["The Rust OSDev team"] publish = false -edition = "2021" +edition = "2024" [dependencies] uefi-raw = { path = "../uefi-raw" } diff --git a/uefi-test-runner/examples/sierpinski.rs b/uefi-test-runner/examples/sierpinski.rs index 92a7b7450..b4514c470 100644 --- a/uefi-test-runner/examples/sierpinski.rs +++ b/uefi-test-runner/examples/sierpinski.rs @@ -11,7 +11,7 @@ use alloc::vec::Vec; use uefi::prelude::*; use uefi::proto::console::gop::{BltOp, BltPixel, BltRegion, GraphicsOutput}; use uefi::proto::rng::Rng; -use uefi::{boot, Result}; +use uefi::{Result, boot}; #[derive(Clone, Copy)] struct Point { diff --git a/uefi-test-runner/src/bin/shell_launcher.rs b/uefi-test-runner/src/bin/shell_launcher.rs index edd8aa89b..f48e28c2d 100644 --- a/uefi-test-runner/src/bin/shell_launcher.rs +++ b/uefi-test-runner/src/bin/shell_launcher.rs @@ -17,10 +17,10 @@ use alloc::vec::Vec; use log::info; use uefi::boot::{self, LoadImageSource}; use uefi::prelude::*; +use uefi::proto::BootPolicy; use uefi::proto::device_path::build::{self, DevicePathBuilder}; use uefi::proto::device_path::{DevicePath, DeviceSubType, DeviceType, LoadedImageDevicePath}; use uefi::proto::loaded_image::LoadedImage; -use uefi::proto::BootPolicy; /// Get the device path of the shell app. This is the same as the /// currently-loaded image's device path, but with the file path part changed. diff --git a/uefi-test-runner/src/boot/misc.rs b/uefi-test-runner/src/boot/misc.rs index 04b14ccd1..a4f0e3689 100644 --- a/uefi-test-runner/src/boot/misc.rs +++ b/uefi-test-runner/src/boot/misc.rs @@ -8,7 +8,7 @@ use uefi::boot::{ }; use uefi::mem::memory_map::MemoryType; use uefi::proto::unsafe_protocol; -use uefi::{boot, guid, system, Event, Guid, Identify}; +use uefi::{Event, Guid, Identify, boot, guid, system}; pub fn test() { test_tpl(); diff --git a/uefi-test-runner/src/boot/mod.rs b/uefi-test-runner/src/boot/mod.rs index 7fbbaccfd..420a6116a 100644 --- a/uefi-test-runner/src/boot/mod.rs +++ b/uefi-test-runner/src/boot/mod.rs @@ -3,11 +3,11 @@ use alloc::string::ToString; use uefi::boot::{LoadImageSource, SearchType}; use uefi::fs::FileSystem; +use uefi::proto::BootPolicy; use uefi::proto::console::text::Output; use uefi::proto::device_path::media::FilePath; use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath}; -use uefi::proto::BootPolicy; -use uefi::{boot, CString16, Identify}; +use uefi::{CString16, Identify, boot}; mod memory; mod misc; diff --git a/uefi-test-runner/src/fs/mod.rs b/uefi-test-runner/src/fs/mod.rs index c487912ed..fed2f1b6f 100644 --- a/uefi-test-runner/src/fs/mod.rs +++ b/uefi-test-runner/src/fs/mod.rs @@ -7,7 +7,7 @@ use alloc::vec::Vec; use uefi::boot::ScopedProtocol; use uefi::fs::{FileSystem, IoError, IoErrorContext, PathBuf}; use uefi::proto::media::fs::SimpleFileSystem; -use uefi::{cstr16, fs, Status}; +use uefi::{Status, cstr16, fs}; /// Tests functionality from the `uefi::fs` module. This test relies on a /// working File System Protocol, which is tested at a dedicated place. diff --git a/uefi-test-runner/src/main.rs b/uefi-test-runner/src/main.rs index bcbbb0f8e..a4948fbd9 100644 --- a/uefi-test-runner/src/main.rs +++ b/uefi-test-runner/src/main.rs @@ -15,7 +15,7 @@ use uefi::prelude::*; use uefi::proto::console::serial::Serial; use uefi::proto::device_path::build::{self, DevicePathBuilder}; use uefi::proto::device_path::messaging::Vendor; -use uefi::{print, println, system, Result}; +use uefi::{Result, print, println, system}; mod boot; mod fs; diff --git a/uefi-test-runner/src/proto/console/gop.rs b/uefi-test-runner/src/proto/console/gop.rs index 6e490cec6..2b0898b6f 100644 --- a/uefi-test-runner/src/proto/console/gop.rs +++ b/uefi-test-runner/src/proto/console/gop.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::{send_request_to_host, HostRequest}; +use crate::{HostRequest, send_request_to_host}; use uefi::boot::{self, OpenProtocolAttributes, OpenProtocolParams}; use uefi::proto::console::gop::{BltOp, BltPixel, FrameBuffer, GraphicsOutput, PixelFormat}; @@ -8,18 +8,20 @@ pub unsafe fn test() { info!("Running graphics output protocol test"); let handle = boot::get_handle_for_protocol::().expect("missing GraphicsOutput protocol"); - let gop = &mut boot::open_protocol::( - OpenProtocolParams { - handle, - agent: boot::image_handle(), - controller: None, - }, - // For this test, don't open in exclusive mode. That - // would break the connection between stdout and the - // video console. - OpenProtocolAttributes::GetProtocol, - ) - .expect("failed to open Graphics Output Protocol"); + let gop = unsafe { + &mut boot::open_protocol::( + OpenProtocolParams { + handle, + agent: boot::image_handle(), + controller: None, + }, + // For this test, don't open in exclusive mode. That + // would break the connection between stdout and the + // video console. + OpenProtocolAttributes::GetProtocol, + ) + .expect("failed to open Graphics Output Protocol") + }; set_graphics_mode(gop); fill_color(gop); @@ -73,10 +75,10 @@ fn draw_fb(gop: &mut GraphicsOutput) { type PixelWriter = unsafe fn(&mut FrameBuffer, usize, [u8; 3]); unsafe fn write_pixel_rgb(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) { - fb.write_value(pixel_base, rgb); + unsafe { fb.write_value(pixel_base, rgb) } } unsafe fn write_pixel_bgr(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) { - fb.write_value(pixel_base, [rgb[2], rgb[1], rgb[0]]); + unsafe { fb.write_value(pixel_base, [rgb[2], rgb[1], rgb[0]]) } } let write_pixel: PixelWriter = match mi.pixel_format() { PixelFormat::Rgb => write_pixel_rgb, diff --git a/uefi-test-runner/src/proto/console/serial.rs b/uefi-test-runner/src/proto/console/serial.rs index e7ecf8b0b..8b44b4a2c 100644 --- a/uefi-test-runner/src/proto/console/serial.rs +++ b/uefi-test-runner/src/proto/console/serial.rs @@ -2,7 +2,7 @@ use crate::reconnect_serial_to_console; use uefi::proto::console::serial::{ControlBits, Serial}; -use uefi::{boot, Result, ResultExt, Status}; +use uefi::{Result, ResultExt, Status, boot}; // For the duration of this function, the serial device is opened in // exclusive mode. That means logs will not work, which means we should diff --git a/uefi-test-runner/src/proto/debug.rs b/uefi-test-runner/src/proto/debug.rs index 74ae9256f..e5e6c0f76 100644 --- a/uefi-test-runner/src/proto/debug.rs +++ b/uefi-test-runner/src/proto/debug.rs @@ -80,10 +80,10 @@ fn test_debug_support() { // make sure that the max processor index is a sane value, i.e. it works let maximum_processor_index = debug_support.get_maximum_processor_index(); assert_ne!( - maximum_processor_index, - usize::MAX, - "get_maximum_processor_index() returning garbage, unless you really have 18,446,744,073,709,551,615 processors" - ); + maximum_processor_index, + usize::MAX, + "get_maximum_processor_index() returning garbage, unless you really have 18,446,744,073,709,551,615 processors" + ); info!("- Architecture: {:?}", debug_support.arch()); info!("- Maximum Processor Index: {:?}", maximum_processor_index); diff --git a/uefi-test-runner/src/proto/device_path.rs b/uefi-test-runner/src/proto/device_path.rs index 0620dfd79..277066be9 100644 --- a/uefi-test-runner/src/proto/device_path.rs +++ b/uefi-test-runner/src/proto/device_path.rs @@ -6,7 +6,7 @@ use uefi::proto::device_path::build::{self, DevicePathBuilder}; use uefi::proto::device_path::text::{ AllowShortcuts, DevicePathFromText, DevicePathToText, DisplayOnly, }; -use uefi::proto::device_path::{messaging, DevicePath, DevicePathNode, LoadedImageDevicePath}; +use uefi::proto::device_path::{DevicePath, DevicePathNode, LoadedImageDevicePath, messaging}; use uefi::proto::loaded_image::LoadedImage; use uefi::proto::media::disk::DiskIo; use uefi::{boot, cstr16}; diff --git a/uefi-test-runner/src/proto/driver.rs b/uefi-test-runner/src/proto/driver.rs index c5ce96ccd..c35bf3e75 100644 --- a/uefi-test-runner/src/proto/driver.rs +++ b/uefi-test-runner/src/proto/driver.rs @@ -104,10 +104,12 @@ fn test_component_name(english: &str) { .find_map(|handle| { let component_name = C::open(*handle).ok()?; - assert!(component_name - .supported_languages() - .ok()? - .any(|lang| lang == english)); + assert!( + component_name + .supported_languages() + .ok()? + .any(|lang| lang == english) + ); let driver_name = component_name.driver_name(english).ok()?; if driver_name == fat_driver_name { diff --git a/uefi-test-runner/src/proto/load.rs b/uefi-test-runner/src/proto/load.rs index 176025ada..5fdda7c9b 100644 --- a/uefi-test-runner/src/proto/load.rs +++ b/uefi-test-runner/src/proto/load.rs @@ -7,10 +7,10 @@ use core::ffi::c_void; use core::pin::Pin; use core::ptr; use core::ptr::addr_of; +use uefi::proto::BootPolicy; use uefi::proto::device_path::build::DevicePathBuilder; use uefi::proto::media::load_file::{LoadFile, LoadFile2}; -use uefi::proto::BootPolicy; -use uefi::{boot, Guid, Handle}; +use uefi::{Guid, Handle, boot}; use uefi_raw::protocol::device_path::DevicePathProtocol; use uefi_raw::protocol::media::{LoadFile2Protocol, LoadFileProtocol}; use uefi_raw::{Boolean, Status}; @@ -23,7 +23,7 @@ unsafe extern "efiapi" fn raw_load_file( buffer: *mut c_void, ) -> Status { log::debug!("Called static extern \"efiapi\" `raw_load_file` glue function"); - let this = this.cast::().as_ref().unwrap(); + let this = unsafe { this.cast::().as_ref().unwrap() }; this.load_file(buffer_size, buffer.cast()) } @@ -60,11 +60,15 @@ impl CustomLoadFile2Protocol { } unsafe fn install_protocol(handle: Handle, guid: Guid, protocol: &mut CustomLoadFile2Protocol) { - boot::install_protocol_interface(Some(handle), &guid, addr_of!(*protocol).cast()).unwrap(); + unsafe { + boot::install_protocol_interface(Some(handle), &guid, addr_of!(*protocol).cast()).unwrap(); + } } unsafe fn uninstall_protocol(handle: Handle, guid: Guid, protocol: &mut CustomLoadFile2Protocol) { - boot::uninstall_protocol_interface(handle, &guid, addr_of!(*protocol).cast()).unwrap(); + unsafe { + boot::uninstall_protocol_interface(handle, &guid, addr_of!(*protocol).cast()).unwrap(); + } } /// This tests the LoadFile and LoadFile2 protocols. As this protocol is not diff --git a/uefi-test-runner/src/proto/media.rs b/uefi-test-runner/src/proto/media.rs index ebe9ff577..7603ba381 100644 --- a/uefi-test-runner/src/proto/media.rs +++ b/uefi-test-runner/src/proto/media.rs @@ -174,9 +174,11 @@ fn test_existing_file(directory: &mut Directory) { file.delete().unwrap(); // Verify the file is gone. - assert!(directory - .open(input_file_path, FileMode::Read, FileAttribute::empty()) - .is_err()); + assert!( + directory + .open(input_file_path, FileMode::Read, FileAttribute::empty()) + .is_err() + ); } /// Test file creation. diff --git a/uefi-test-runner/src/proto/mod.rs b/uefi-test-runner/src/proto/mod.rs index e39b525fd..7bc0ee02f 100644 --- a/uefi-test-runner/src/proto/mod.rs +++ b/uefi-test-runner/src/proto/mod.rs @@ -2,7 +2,7 @@ use uefi::boot::{self, OpenProtocolParams}; use uefi::proto::loaded_image::LoadedImage; -use uefi::{proto, Identify}; +use uefi::{Identify, proto}; pub fn test() { info!("Testing various protocols"); @@ -54,12 +54,14 @@ fn test_protocols_per_handle() { } fn test_test_protocol() { - assert!(boot::test_protocol::(OpenProtocolParams { - handle: boot::image_handle(), - agent: boot::image_handle(), - controller: None, - }) - .unwrap()); + assert!( + boot::test_protocol::(OpenProtocolParams { + handle: boot::image_handle(), + agent: boot::image_handle(), + controller: None, + }) + .unwrap() + ); } mod console; diff --git a/uefi-test-runner/src/proto/network/pxe.rs b/uefi-test-runner/src/proto/network/pxe.rs index 9f29733f7..48d9c69f8 100644 --- a/uefi-test-runner/src/proto/network/pxe.rs +++ b/uefi-test-runner/src/proto/network/pxe.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use uefi::proto::network::pxe::{BaseCode, DhcpV4Packet, IpFilter, IpFilters, UdpOpFlags}; use uefi::proto::network::IpAddress; -use uefi::{boot, CStr8}; +use uefi::proto::network::pxe::{BaseCode, DhcpV4Packet, IpFilter, IpFilters, UdpOpFlags}; +use uefi::{CStr8, boot}; pub fn test() { // Skip the test if the `pxe` feature is not enabled. diff --git a/uefi-test-runner/src/proto/network/snp.rs b/uefi-test-runner/src/proto/network/snp.rs index 5229ce833..1d9d1a6f8 100644 --- a/uefi-test-runner/src/proto/network/snp.rs +++ b/uefi-test-runner/src/proto/network/snp.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use uefi::proto::network::snp::{InterruptStatus, ReceiveFlags, SimpleNetwork}; use uefi::proto::network::MacAddress; -use uefi::{boot, Status}; +use uefi::proto::network::snp::{InterruptStatus, ReceiveFlags, SimpleNetwork}; +use uefi::{Status, boot}; pub fn test() { info!("Testing the simple network protocol"); @@ -73,10 +73,12 @@ pub fn test() { \x04\x01\x02\x03\x04"; let dest_addr = MacAddress([0xffu8; 32]); - assert!(!simple_network - .get_interrupt_status() - .unwrap() - .contains(InterruptStatus::TRANSMIT)); + assert!( + !simple_network + .get_interrupt_status() + .unwrap() + .contains(InterruptStatus::TRANSMIT) + ); // Send the frame simple_network diff --git a/uefi-test-runner/src/proto/pi/mp.rs b/uefi-test-runner/src/proto/pi/mp.rs index 3872851c5..782180a4b 100644 --- a/uefi-test-runner/src/proto/pi/mp.rs +++ b/uefi-test-runner/src/proto/pi/mp.rs @@ -5,7 +5,7 @@ use core::ptr; use core::sync::atomic::{AtomicUsize, Ordering}; use core::time::Duration; use uefi::proto::pi::mp::MpServices; -use uefi::{boot, Status}; +use uefi::{Status, boot}; /// Number of cores qemu is configured to have const NUM_CPUS: usize = 4; diff --git a/uefi-test-runner/src/proto/string/unicode_collation.rs b/uefi-test-runner/src/proto/string/unicode_collation.rs index 73de65808..b9329ff29 100644 --- a/uefi-test-runner/src/proto/string/unicode_collation.rs +++ b/uefi-test-runner/src/proto/string/unicode_collation.rs @@ -2,7 +2,7 @@ use core::cmp::Ordering; use uefi::proto::string::unicode_collation::{StrConversionError, UnicodeCollation}; -use uefi::{boot, CStr16, CStr8}; +use uefi::{CStr8, CStr16, boot}; pub fn test() { info!("Testing the Unicode Collation protocol"); diff --git a/uefi-test-runner/src/proto/tcg.rs b/uefi-test-runner/src/proto/tcg.rs index 26959ae1d..a0759439e 100644 --- a/uefi-test-runner/src/proto/tcg.rs +++ b/uefi-test-runner/src/proto/tcg.rs @@ -2,7 +2,7 @@ use alloc::vec::Vec; use uefi::boot; -use uefi::proto::tcg::{v1, v2, AlgorithmId, EventType, HashAlgorithm, PcrIndex}; +use uefi::proto::tcg::{AlgorithmId, EventType, HashAlgorithm, PcrIndex, v1, v2}; // Environmental note: // @@ -264,10 +264,11 @@ pub fn test_tcg_v2() { // Check that there was no attempt to change the active banks in the // previous boot. - assert!(tcg - .get_result_of_set_active_pcr_banks() - .expect("get_result_of_set_active_pcr_banks failed") - .is_none()); + assert!( + tcg.get_result_of_set_active_pcr_banks() + .expect("get_result_of_set_active_pcr_banks failed") + .is_none() + ); // PCR 8 is initially zero. assert_eq!(tcg_v2_read_pcr_8(&mut tcg), [0; 20]); diff --git a/uefi-test-runner/src/runtime/vars.rs b/uefi-test-runner/src/runtime/vars.rs index 062884212..d02a7ba87 100644 --- a/uefi-test-runner/src/runtime/vars.rs +++ b/uefi-test-runner/src/runtime/vars.rs @@ -3,7 +3,7 @@ use log::info; use uefi::prelude::*; use uefi::runtime::{VariableAttributes, VariableVendor}; -use uefi::{guid, runtime, CStr16, Error}; +use uefi::{CStr16, Error, guid, runtime}; /// Test variable name. const NAME: &CStr16 = cstr16!("UefiRsTestVar"); diff --git a/uefi/CHANGELOG.md b/uefi/CHANGELOG.md index d653d820c..4163c14cc 100644 --- a/uefi/CHANGELOG.md +++ b/uefi/CHANGELOG.md @@ -26,6 +26,7 @@ - The `Display` impl for `CStr8` now excludes the trailing null character. - `VariableKeys` initializes with a larger name buffer to work around firmware bugs on some devices. +- **Breaking:** The MSRV is now 1.85.1 and the crate uses the Rust 2024 edition. # uefi - 0.34.1 (2025-02-07) diff --git a/uefi/src/boot.rs b/uefi/src/boot.rs index 4c44bef55..51cb3fb52 100644 --- a/uefi/src/boot.rs +++ b/uefi/src/boot.rs @@ -22,7 +22,7 @@ //! [`proto`]: crate::proto pub use uefi_raw::table::boot::{ - EventType, MemoryAttribute, MemoryDescriptor, MemoryType, Tpl, PAGE_SIZE, + EventType, MemoryAttribute, MemoryDescriptor, MemoryType, PAGE_SIZE, Tpl, }; use crate::data_types::PhysicalAddress; @@ -37,7 +37,7 @@ use crate::proto::{BootPolicy, Protocol, ProtocolPointer}; use crate::runtime::{self, ResetType}; use crate::table::Revision; use crate::util::opt_nonnull_to_ptr; -use crate::{table, Char16, Error, Event, Guid, Handle, Result, Status, StatusExt}; +use crate::{Char16, Error, Event, Guid, Handle, Result, Status, StatusExt, table}; use core::ffi::c_void; use core::mem::MaybeUninit; use core::ops::{Deref, DerefMut}; diff --git a/uefi/src/data_types/mod.rs b/uefi/src/data_types/mod.rs index 2c94b2062..aa1d81ce4 100644 --- a/uefi/src/data_types/mod.rs +++ b/uefi/src/data_types/mod.rs @@ -119,11 +119,7 @@ pub trait Align { fn offset_up_to_alignment(val: usize) -> usize { assert!(Self::alignment() != 0); let r = val % Self::alignment(); - if r == 0 { - 0 - } else { - Self::alignment() - r - } + if r == 0 { 0 } else { Self::alignment() - r } } /// Round `val` up so that it is aligned. @@ -162,14 +158,14 @@ mod guid; pub use guid::{Guid, Identify}; pub mod chars; -pub use chars::{Char16, Char8}; +pub use chars::{Char8, Char16}; #[macro_use] mod opaque; mod strs; pub use strs::{ - CStr16, CStr8, EqStrUntilNul, FromSliceWithNulError, FromStrWithBufError, UnalignedCStr16Error, + CStr8, CStr16, EqStrUntilNul, FromSliceWithNulError, FromStrWithBufError, UnalignedCStr16Error, }; /// These functions are used in the implementation of the [`cstr8`] macro. diff --git a/uefi/src/data_types/owned_strs.rs b/uefi/src/data_types/owned_strs.rs index 8e01749b4..ed4ea1f8d 100644 --- a/uefi/src/data_types/owned_strs.rs +++ b/uefi/src/data_types/owned_strs.rs @@ -2,8 +2,8 @@ use super::chars::{Char16, NUL_16}; use super::strs::{CStr16, FromSliceWithNulError}; -use crate::data_types::strs::EqStrUntilNul; use crate::data_types::UnalignedSlice; +use crate::data_types::strs::EqStrUntilNul; use crate::polyfill::vec_into_raw_parts; use alloc::borrow::{Borrow, ToOwned}; use alloc::string::String; diff --git a/uefi/src/data_types/strs.rs b/uefi/src/data_types/strs.rs index fc69782f1..19b143de7 100644 --- a/uefi/src/data_types/strs.rs +++ b/uefi/src/data_types/strs.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use super::chars::{Char16, Char8, NUL_16, NUL_8}; use super::UnalignedSlice; +use super::chars::{Char8, Char16, NUL_8, NUL_16}; use crate::polyfill::maybe_uninit_slice_assume_init_ref; use core::borrow::Borrow; use core::ffi::CStr; @@ -762,7 +762,7 @@ where #[cfg(test)] mod tests { use super::*; - use crate::{cstr16, cstr8}; + use crate::{cstr8, cstr16}; use alloc::format; use alloc::string::String; diff --git a/uefi/src/fs/dir_entry_iter.rs b/uefi/src/fs/dir_entry_iter.rs index 4e4a437de..716dd0d9b 100644 --- a/uefi/src/fs/dir_entry_iter.rs +++ b/uefi/src/fs/dir_entry_iter.rs @@ -3,7 +3,7 @@ //! Module for directory iteration. See [`UefiDirectoryIter`]. use super::*; -use crate::{cstr16, CStr16, Result}; +use crate::{CStr16, Result, cstr16}; use alloc::boxed::Box; /// Common skip dirs in UEFI/FAT-style file systems. diff --git a/uefi/src/fs/file_system/fs.rs b/uefi/src/fs/file_system/fs.rs index 0a2261870..4e89b0d65 100644 --- a/uefi/src/fs/file_system/fs.rs +++ b/uefi/src/fs/file_system/fs.rs @@ -2,8 +2,8 @@ //! Module for [`FileSystem`]. -use crate::fs::*; use crate::Status; +use crate::fs::*; use alloc::boxed::Box; use alloc::string::String; use alloc::vec; diff --git a/uefi/src/fs/path/mod.rs b/uefi/src/fs/path/mod.rs index ab2bf33ac..a6b41787c 100644 --- a/uefi/src/fs/path/mod.rs +++ b/uefi/src/fs/path/mod.rs @@ -23,9 +23,9 @@ pub use path::{Components, Path}; pub use pathbuf::PathBuf; use crate::data_types::chars::NUL_16; -use crate::{cstr16, CStr16, Char16}; -pub(super) use validation::validate_path; +use crate::{CStr16, Char16, cstr16}; pub use validation::PathError; +pub(super) use validation::validate_path; /// The default separator for paths. pub const SEPARATOR: Char16 = unsafe { Char16::from_u16_unchecked('\\' as u16) }; diff --git a/uefi/src/fs/path/pathbuf.rs b/uefi/src/fs/path/pathbuf.rs index 22df40b70..5f3a3b45a 100644 --- a/uefi/src/fs/path/pathbuf.rs +++ b/uefi/src/fs/path/pathbuf.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::fs::path::Path; use crate::fs::SEPARATOR; +use crate::fs::path::Path; use crate::{CStr16, CString16, Char16}; use core::fmt::{Display, Formatter}; diff --git a/uefi/src/fs/path/validation.rs b/uefi/src/fs/path/validation.rs index 6230dcbe1..e1beeb626 100644 --- a/uefi/src/fs/path/validation.rs +++ b/uefi/src/fs/path/validation.rs @@ -8,8 +8,8 @@ //! [`fs`]: crate::fs use super::Path; -use crate::fs::CHARACTER_DENY_LIST; use crate::Char16; +use crate::fs::CHARACTER_DENY_LIST; use core::fmt::{self, Display, Formatter}; /// Errors related to file paths. @@ -68,7 +68,7 @@ pub fn validate_path>(path: P) -> Result<(), PathError> { mod tests { use super::*; use crate::fs::PathBuf; - use crate::{cstr16, CString16}; + use crate::{CString16, cstr16}; #[test] fn test_validate_path() { diff --git a/uefi/src/lib.rs b/uefi/src/lib.rs index ebccb2430..7ac51a8b1 100644 --- a/uefi/src/lib.rs +++ b/uefi/src/lib.rs @@ -258,7 +258,7 @@ mod util; #[cfg(feature = "alloc")] pub use data_types::CString16; -pub use data_types::{CStr16, CStr8, Char16, Char8, Event, Guid, Handle, Identify}; +pub use data_types::{CStr8, CStr16, Char8, Char16, Event, Guid, Handle, Identify}; pub use result::{Error, Result, ResultExt, Status, StatusExt}; /// Re-export ucs2_cstr so that it can be used in the implementation of the /// cstr16 macro. It is hidden since it's not intended to be used directly. diff --git a/uefi/src/mem/memory_map/impl_.rs b/uefi/src/mem/memory_map/impl_.rs index 23e0917e1..63079f7d2 100644 --- a/uefi/src/mem/memory_map/impl_.rs +++ b/uefi/src/mem/memory_map/impl_.rs @@ -349,7 +349,9 @@ impl Drop for MemoryMapBackingMemory { log::error!("Failed to deallocate memory map: {e:?}"); } } else { - log::debug!("Boot services are exited. Memory map won't be freed using the UEFI boot services allocator."); + log::debug!( + "Boot services are exited. Memory map won't be freed using the UEFI boot services allocator." + ); } } } diff --git a/uefi/src/mem/util.rs b/uefi/src/mem/util.rs index 2f380c251..6962c51c2 100644 --- a/uefi/src/mem/util.rs +++ b/uefi/src/mem/util.rs @@ -210,7 +210,7 @@ mod tests { let mut buf: Align16<[u8; 16]> = Align16([0; 16]); let data: &mut SomeDataAlign16 = uefi_function_stub_read(&mut buf.0).unwrap(); - assert_eq!(&data.0 .0, &[1, 2, 3, 4]); + assert_eq!(&data.0.0, &[1, 2, 3, 4]); } /// This unit tests checks the [`make_boxed`] utility. The test has different code and behavior @@ -234,6 +234,6 @@ mod tests { #[cfg(feature = "unstable")] let data: Box = make_boxed(fetch_data_fn, Global).unwrap(); - assert_eq!(&data.0 .0, &[1, 2, 3, 4]); + assert_eq!(&data.0.0, &[1, 2, 3, 4]); } } diff --git a/uefi/src/prelude.rs b/uefi/src/prelude.rs index bf5b9127a..886f59f09 100644 --- a/uefi/src/prelude.rs +++ b/uefi/src/prelude.rs @@ -5,5 +5,5 @@ //! This includes the system table modules, `Status` codes, etc. pub use crate::{ - boot, cstr16, cstr8, entry, runtime, system, Handle, ResultExt, Status, StatusExt, + Handle, ResultExt, Status, StatusExt, boot, cstr8, cstr16, entry, runtime, system, }; diff --git a/uefi/src/proto/console/gop.rs b/uefi/src/proto/console/gop.rs index f2e3daf0e..8c0e1b020 100644 --- a/uefi/src/proto/console/gop.rs +++ b/uefi/src/proto/console/gop.rs @@ -54,7 +54,7 @@ use crate::proto::unsafe_protocol; use crate::util::usize_from_u32; -use crate::{boot, Result, StatusExt}; +use crate::{Result, StatusExt, boot}; use core::fmt::{Debug, Formatter}; use core::marker::PhantomData; use core::ptr::{self, NonNull}; diff --git a/uefi/src/proto/device_path/device_path_gen.rs b/uefi/src/proto/device_path/device_path_gen.rs index 8154da885..3892524b1 100644 --- a/uefi/src/proto/device_path/device_path_gen.rs +++ b/uefi/src/proto/device_path/device_path_gen.rs @@ -15,7 +15,7 @@ use crate::proto::device_path::{ self, DevicePathHeader, DevicePathNode, DeviceSubType, DeviceType, NodeConversionError, }; use crate::proto::network::IpAddress; -use crate::{guid, Guid}; +use crate::{Guid, guid}; use bitflags::bitflags; use core::mem::{size_of, size_of_val}; use core::ptr::addr_of; @@ -274,11 +274,11 @@ pub mod hardware { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Vendor") .field("vendor_guid", &{ self.vendor_guid }) - .field("vendor_defined_data", { + .field("vendor_defined_data", &{ let ptr = addr_of!(self.vendor_defined_data); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -580,11 +580,11 @@ pub mod acpi { impl fmt::Debug for Adr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Adr") - .field("adr", { + .field("adr", &{ let ptr = addr_of!(self.adr); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -1187,11 +1187,11 @@ pub mod messaging { .field("interface_number", &{ self.interface_number }) .field("device_vendor_id", &{ self.device_vendor_id }) .field("device_product_id", &{ self.device_product_id }) - .field("serial_number", { + .field("serial_number", &{ let ptr = addr_of!(self.serial_number); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -1841,11 +1841,11 @@ pub mod messaging { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Vendor") .field("vendor_guid", &{ self.vendor_guid }) - .field("vendor_defined_data", { + .field("vendor_defined_data", &{ let ptr = addr_of!(self.vendor_defined_data); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -1997,11 +1997,11 @@ pub mod messaging { .field("options", &{ self.options }) .field("logical_unit_number", &{ self.logical_unit_number }) .field("target_portal_group_tag", &{ self.target_portal_group_tag }) - .field("iscsi_target_name", { + .field("iscsi_target_name", &{ let ptr = addr_of!(self.iscsi_target_name); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -2104,11 +2104,11 @@ pub mod messaging { impl fmt::Debug for Uri { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Uri") - .field("value", { + .field("value", &{ let ptr = addr_of!(self.value); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -2435,11 +2435,11 @@ pub mod messaging { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Dns") .field("address_type", &{ self.address_type }) - .field("addresses", { + .field("addresses", &{ let ptr = addr_of!(self.addresses); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -2540,11 +2540,11 @@ pub mod messaging { f.debug_struct("RestService") .field("service_type", &{ self.service_type }) .field("access_mode", &{ self.access_mode }) - .field("vendor_guid_and_data", { + .field("vendor_guid_and_data", &{ let ptr = addr_of!(self.vendor_guid_and_data); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -2611,11 +2611,11 @@ pub mod messaging { f.debug_struct("NvmeOfNamespace") .field("nidt", &{ self.nidt }) .field("nid", &{ self.nid }) - .field("subsystem_nqn", { + .field("subsystem_nqn", &{ let ptr = addr_of!(self.subsystem_nqn); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -2888,11 +2888,11 @@ pub mod media { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Vendor") .field("vendor_guid", &{ self.vendor_guid }) - .field("vendor_defined_data", { + .field("vendor_defined_data", &{ let ptr = addr_of!(self.vendor_defined_data); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -2943,11 +2943,11 @@ pub mod media { impl fmt::Debug for FilePath { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("FilePath") - .field("path_name", { + .field("path_name", &{ let ptr = addr_of!(self.path_name); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -3038,11 +3038,11 @@ pub mod media { impl fmt::Debug for PiwgFirmwareFile { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("PiwgFirmwareFile") - .field("data", { + .field("data", &{ let ptr = addr_of!(self.data); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -3092,11 +3092,11 @@ pub mod media { impl fmt::Debug for PiwgFirmwareVolume { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("PiwgFirmwareVolume") - .field("data", { + .field("data", &{ let ptr = addr_of!(self.data); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -3332,11 +3332,11 @@ pub mod bios_boot_spec { f.debug_struct("BootSpecification") .field("device_type", &{ self.device_type }) .field("status_flag", &{ self.status_flag }) - .field("description_string", { + .field("description_string", &{ let ptr = addr_of!(self.description_string); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) .finish() } @@ -3647,10 +3647,10 @@ impl TryFrom<&DevicePathNode> for DevicePathNodeEnum<'_> { /// Build device paths from their component nodes. pub mod build { use super::*; + use crate::CStr16; use crate::proto::device_path::build::{BuildError, BuildNode}; use crate::proto::device_path::{DeviceSubType, DeviceType}; - use crate::CStr16; - use core::mem::{size_of_val, MaybeUninit}; + use core::mem::{MaybeUninit, size_of_val}; /// Device path build nodes for [`DeviceType::END`]. pub mod end { use super::*; diff --git a/uefi/src/proto/device_path/mod.rs b/uefi/src/proto/device_path/mod.rs index 448de2c68..84427cc81 100644 --- a/uefi/src/proto/device_path/mod.rs +++ b/uefi/src/proto/device_path/mod.rs @@ -80,11 +80,11 @@ pub mod text; mod device_path_gen; pub use device_path_gen::{ - acpi, bios_boot_spec, end, hardware, media, messaging, DevicePathNodeEnum, + DevicePathNodeEnum, acpi, bios_boot_spec, end, hardware, media, messaging, }; pub use uefi_raw::protocol::device_path::{DeviceSubType, DeviceType}; -use crate::proto::{unsafe_protocol, ProtocolPointer}; +use crate::proto::{ProtocolPointer, unsafe_protocol}; use core::ffi::c_void; use core::fmt::{self, Debug, Display, Formatter}; use core::ops::Deref; diff --git a/uefi/src/proto/driver/component_name.rs b/uefi/src/proto/driver/component_name.rs index 1e948eeb0..a6e75ef54 100644 --- a/uefi/src/proto/driver/component_name.rs +++ b/uefi/src/proto/driver/component_name.rs @@ -346,17 +346,19 @@ fn language_to_cstr(language: &str) -> Result { #[cfg(test)] mod tests { use super::*; - use alloc::vec::Vec; use LanguageIterKind::{V1, V2}; + use alloc::vec::Vec; #[test] fn test_language_iter_v1() { // Empty string. let data = "\0"; - assert!(LanguageIter::new(data.as_ptr(), V1) - .unwrap() - .next() - .is_none()); + assert!( + LanguageIter::new(data.as_ptr(), V1) + .unwrap() + .next() + .is_none() + ); // Two languages. let data = "engfra\0"; @@ -388,10 +390,12 @@ mod tests { fn test_language_iter_v2() { // Empty string. let data = "\0"; - assert!(LanguageIter::new(data.as_ptr(), V2) - .unwrap() - .next() - .is_none()); + assert!( + LanguageIter::new(data.as_ptr(), V2) + .unwrap() + .next() + .is_none() + ); // Two languages. let data = "en;fr\0"; diff --git a/uefi/src/proto/loaded_image.rs b/uefi/src/proto/loaded_image.rs index 3ab91c4a4..df43d53e5 100644 --- a/uefi/src/proto/loaded_image.rs +++ b/uefi/src/proto/loaded_image.rs @@ -95,7 +95,7 @@ impl LoadedImage { /// /// [`load_options_as_cstr16`]: `Self::load_options_as_cstr16` #[must_use] - pub fn load_options_as_bytes(&self) -> Option<&[u8]> { + pub const fn load_options_as_bytes(&self) -> Option<&[u8]> { if self.0.load_options.is_null() { None } else { diff --git a/uefi/src/proto/media/file/dir.rs b/uefi/src/proto/media/file/dir.rs index 79661c902..c87628d39 100644 --- a/uefi/src/proto/media/file/dir.rs +++ b/uefi/src/proto/media/file/dir.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use super::{File, FileHandle, FileInfo, FromUefi, RegularFile}; -use crate::data_types::Align; use crate::Result; +use crate::data_types::Align; use core::ffi::c_void; #[cfg(feature = "alloc")] use {crate::mem::make_boxed, alloc::boxed::Box}; diff --git a/uefi/src/proto/media/file/info.rs b/uefi/src/proto/media/file/info.rs index 8a51b7ea5..2f8feeb03 100644 --- a/uefi/src/proto/media/file/info.rs +++ b/uefi/src/proto/media/file/info.rs @@ -427,8 +427,8 @@ impl FileProtocolInfo for FileSystemVolumeLabel {} #[cfg(test)] mod tests { use super::*; - use crate::runtime::{Daylight, Time, TimeParams}; use crate::CString16; + use crate::runtime::{Daylight, Time, TimeParams}; use alloc::vec; fn validate_layout(info: &T, name: &[Char16]) { diff --git a/uefi/src/proto/media/load_file.rs b/uefi/src/proto/media/load_file.rs index 665145a46..ead2c5e83 100644 --- a/uefi/src/proto/media/load_file.rs +++ b/uefi/src/proto/media/load_file.rs @@ -2,15 +2,15 @@ //! LoadFile and LoadFile2 protocols. -use crate::proto::unsafe_protocol; #[cfg(doc)] use crate::Status; +use crate::proto::unsafe_protocol; #[cfg(all(feature = "alloc", feature = "unstable"))] use alloc::alloc::Global; use uefi_raw::protocol::media::{LoadFile2Protocol, LoadFileProtocol}; #[cfg(feature = "alloc")] use { - crate::{mem::make_boxed, proto::device_path::DevicePath, Result, StatusExt}, + crate::{Result, StatusExt, mem::make_boxed, proto::device_path::DevicePath}, alloc::boxed::Box, uefi::proto::BootPolicy, uefi_raw::Boolean, diff --git a/uefi/src/proto/media/partition.rs b/uefi/src/proto/media/partition.rs index 99f1c774e..1230c8e49 100644 --- a/uefi/src/proto/media/partition.rs +++ b/uefi/src/proto/media/partition.rs @@ -3,7 +3,7 @@ //! Partition information protocol. use crate::proto::unsafe_protocol; -use crate::{guid, Char16, Guid}; +use crate::{Char16, Guid, guid}; newtype_enum! { /// MBR OS type. diff --git a/uefi/src/proto/security/memory_protection.rs b/uefi/src/proto/security/memory_protection.rs index 3481195b8..86423950d 100644 --- a/uefi/src/proto/security/memory_protection.rs +++ b/uefi/src/proto/security/memory_protection.rs @@ -92,7 +92,7 @@ impl MemoryProtection { } /// Convert a byte `Range` to `(base_address, length)`. -fn range_to_base_and_len(r: Range) -> (PhysicalAddress, PhysicalAddress) { +const fn range_to_base_and_len(r: Range) -> (PhysicalAddress, PhysicalAddress) { (r.start, r.end.checked_sub(r.start).unwrap()) } diff --git a/uefi/src/proto/shell_params.rs b/uefi/src/proto/shell_params.rs index 2d4d60209..288bd47a7 100644 --- a/uefi/src/proto/shell_params.rs +++ b/uefi/src/proto/shell_params.rs @@ -3,7 +3,7 @@ //! `ShellParams` protocol use crate::proto::unsafe_protocol; -use crate::{data_types, Char16}; +use crate::{Char16, data_types}; use core::slice::from_raw_parts; use uefi_raw::protocol::shell_params::ShellParametersProtocol; diff --git a/uefi/src/proto/string/unicode_collation.rs b/uefi/src/proto/string/unicode_collation.rs index 0836298f6..bab4d6f87 100644 --- a/uefi/src/proto/string/unicode_collation.rs +++ b/uefi/src/proto/string/unicode_collation.rs @@ -5,7 +5,7 @@ //! This protocol is used in the boot services environment to perform //! lexical comparison functions on Unicode strings for given languages. -use crate::data_types::{CStr16, CStr8}; +use crate::data_types::{CStr8, CStr16}; use crate::proto::unsafe_protocol; use core::cmp::Ordering; use core::fmt::{self, Display, Formatter}; diff --git a/uefi/src/proto/tcg/v2.rs b/uefi/src/proto/tcg/v2.rs index d13573d6e..39c425bba 100644 --- a/uefi/src/proto/tcg/v2.rs +++ b/uefi/src/proto/tcg/v2.rs @@ -12,7 +12,7 @@ //! [TCG]: https://trustedcomputinggroup.org/ //! [TPM]: https://en.wikipedia.org/wiki/Trusted_Platform_Module -use super::{v1, AlgorithmId, EventType, HashAlgorithm, PcrIndex}; +use super::{AlgorithmId, EventType, HashAlgorithm, PcrIndex, v1}; use crate::data_types::{Align, PhysicalAddress, UnalignedSlice}; use crate::proto::unsafe_protocol; use crate::util::{ptr_write_unaligned_and_add, usize_from_u32}; diff --git a/uefi/src/result/status.rs b/uefi/src/result/status.rs index a1ea354b6..f66ac1926 100644 --- a/uefi/src/result/status.rs +++ b/uefi/src/result/status.rs @@ -95,9 +95,11 @@ mod tests { assert!(Status::BUFFER_TOO_SMALL.to_result().is_err()); assert_eq!(Status::SUCCESS.to_result_with_val(|| 123).unwrap(), 123); - assert!(Status::WARN_DELETE_FAILURE - .to_result_with_val(|| 123) - .is_err()); + assert!( + Status::WARN_DELETE_FAILURE + .to_result_with_val(|| 123) + .is_err() + ); assert!(Status::BUFFER_TOO_SMALL.to_result_with_val(|| 123).is_err()); assert!(Status::SUCCESS.to_result_with_err(|_| 123).is_ok()); diff --git a/uefi/src/runtime.rs b/uefi/src/runtime.rs index 52802cf6d..156da607b 100644 --- a/uefi/src/runtime.rs +++ b/uefi/src/runtime.rs @@ -16,9 +16,9 @@ use uefi_raw::table::boot::MemoryDescriptor; #[cfg(feature = "alloc")] use { - crate::mem::make_boxed, crate::CString16, crate::Guid, + crate::mem::make_boxed, alloc::borrow::ToOwned, alloc::boxed::Box, alloc::{vec, vec::Vec}, diff --git a/uefi/src/table/cfg.rs b/uefi/src/table/cfg.rs index bbeebe456..c0ce868d3 100644 --- a/uefi/src/table/cfg.rs +++ b/uefi/src/table/cfg.rs @@ -9,7 +9,7 @@ //! This module contains the actual entries of the configuration table, //! as well as GUIDs for many known vendor tables. -use crate::{guid, Guid}; +use crate::{Guid, guid}; use bitflags::bitflags; use core::ffi::c_void; diff --git a/xtask/src/cargo.rs b/xtask/src/cargo.rs index cd982332d..af6e3fe80 100644 --- a/xtask/src/cargo.rs +++ b/xtask/src/cargo.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::arch::UefiArch; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use std::env; use std::ffi::OsString; use std::process::Command; diff --git a/xtask/src/check_raw.rs b/xtask/src/check_raw.rs index 5d9ccb38d..2d33b0c1e 100644 --- a/xtask/src/check_raw.rs +++ b/xtask/src/check_raw.rs @@ -17,9 +17,9 @@ use syn::punctuated::Punctuated; use syn::spanned::Spanned; use syn::token::Comma; use syn::{ - parenthesized, Abi, Attribute, Field, Fields, FieldsNamed, FieldsUnnamed, File, Item, - ItemConst, ItemMacro, ItemStruct, ItemType, ItemUnion, LitInt, ReturnType, Type, TypeArray, - TypeBareFn, TypePtr, Visibility, + Abi, Attribute, Field, Fields, FieldsNamed, FieldsUnnamed, File, Item, ItemConst, ItemMacro, + ItemStruct, ItemType, ItemUnion, LitInt, ReturnType, Type, TypeArray, TypeBareFn, TypePtr, + Visibility, parenthesized, }; use walkdir::WalkDir; @@ -459,22 +459,26 @@ mod tests { }; // Valid fn ptr. - assert!(check_fn_ptr( - &parse_quote! { - unsafe extern "efiapi" fn() - }, - src(), - ) - .is_ok()); + assert!( + check_fn_ptr( + &parse_quote! { + unsafe extern "efiapi" fn() + }, + src(), + ) + .is_ok() + ); // Valid fn ptr with c-variadics. - assert!(check_fn_ptr( - &parse_quote! { - unsafe extern "C" fn(usize, ...) - }, - src(), - ) - .is_ok()); + assert!( + check_fn_ptr( + &parse_quote! { + unsafe extern "C" fn(usize, ...) + }, + src(), + ) + .is_ok() + ); // Not `extern efiapi`. check_fn_err( @@ -512,16 +516,18 @@ mod tests { #[test] fn test_struct() { // Valid struct. - assert!(check_struct( - &parse_quote! { - #[repr(C)] - pub struct S { - pub f: u32, - } - }, - src(), - ) - .is_ok()); + assert!( + check_struct( + &parse_quote! { + #[repr(C)] + pub struct S { + pub f: u32, + } + }, + src(), + ) + .is_ok() + ); // Missing `pub` on struct. check_item_err( @@ -604,17 +610,19 @@ mod tests { #[test] fn test_union() { // Valid union. - assert!(check_union( - &parse_quote! { - #[repr(C)] - pub union U { - pub a: u32, - pub b: u64, - } - }, - src(), - ) - .is_ok()); + assert!( + check_union( + &parse_quote! { + #[repr(C)] + pub union U { + pub a: u32, + pub b: u64, + } + }, + src(), + ) + .is_ok() + ); // Missing `pub` on union. check_item_err( diff --git a/xtask/src/device_path/field.rs b/xtask/src/device_path/field.rs index 2406e4b0a..b835ef9df 100644 --- a/xtask/src/device_path/field.rs +++ b/xtask/src/device_path/field.rs @@ -2,7 +2,7 @@ use crate::device_path::util::is_doc_attr; use proc_macro2::{Span, TokenStream}; -use quote::{quote, ToTokens, TokenStreamExt}; +use quote::{ToTokens, TokenStreamExt, quote}; use syn::{Attribute, Expr, ExprLit, Field, Ident, Lit, Path, Type, TypeArray}; /// A fixed-size non-array type. diff --git a/xtask/src/device_path/group.rs b/xtask/src/device_path/group.rs index b4767edd1..16ee3d279 100644 --- a/xtask/src/device_path/group.rs +++ b/xtask/src/device_path/group.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use super::node::{is_node_attr, Node}; +use super::node::{Node, is_node_attr}; use heck::ToUpperCamelCase; use proc_macro2::{Span, TokenStream}; use quote::quote; diff --git a/xtask/src/device_path/mod.rs b/xtask/src/device_path/mod.rs index b03fa5e03..821a705b6 100644 --- a/xtask/src/device_path/mod.rs +++ b/xtask/src/device_path/mod.rs @@ -6,7 +6,7 @@ mod node; mod util; use crate::opt::GenCodeOpt; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use fs_err as fs; use group::NodeGroup; use proc_macro2::TokenStream; @@ -54,7 +54,7 @@ fn gen_uefi_raw_code_as_string(groups: &[NodeGroup]) -> Result { use bitflags::bitflags; use crate::protocol::device_path; use crate::table::boot::MemoryType; - use crate::{guid, Guid, IpAddress}; + use crate::{Guid, IpAddress, guid}; use device_path::DevicePathProtocol as DevicePathHeader; #[cfg(doc)] use device_path::DeviceType; @@ -73,7 +73,7 @@ fn gen_uefi_code_as_string(groups: &[NodeGroup]) -> Result { let code = quote!( use bitflags::bitflags; use crate::data_types::UnalignedSlice; - use crate::{guid, Guid}; + use crate::{Guid, guid}; use crate::polyfill::maybe_uninit_slice_as_mut_ptr; use crate::proto::device_path::{ self, DevicePathHeader, DevicePathNode, DeviceSubType, DeviceType, diff --git a/xtask/src/device_path/node.rs b/xtask/src/device_path/node.rs index 263b08689..890c3d7cd 100644 --- a/xtask/src/device_path/node.rs +++ b/xtask/src/device_path/node.rs @@ -208,11 +208,11 @@ impl Node { // It's not trivial to nicely format the DST data since // the slice might be unaligned. Treat it as a byte // slice instead. - quote!({ + quote!(&{ let ptr = addr_of!(#field_val); let (ptr, len) = ptr_meta::to_raw_parts(ptr); let byte_len = size_of::<#slice_elem_ty>() * len; - unsafe { &slice::from_raw_parts(ptr.cast::(), byte_len) } + unsafe { slice::from_raw_parts(ptr.cast::(), byte_len) } }) } else { // Wrap in `{...}` to make a copy of the (potentially diff --git a/xtask/src/device_path/util.rs b/xtask/src/device_path/util.rs index 297c48dac..59cdc6627 100644 --- a/xtask/src/device_path/util.rs +++ b/xtask/src/device_path/util.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use std::io::Write; use std::process::{Command, Stdio}; use std::thread; diff --git a/xtask/src/disk.rs b/xtask/src/disk.rs index 753f091be..ec732cf94 100644 --- a/xtask/src/disk.rs +++ b/xtask/src/disk.rs @@ -2,7 +2,7 @@ use anyhow::Result; use fatfs::{Date, DateTime, FileSystem, FormatVolumeOptions, FsOptions, Time}; -use mbrman::{MBRPartitionEntry, BOOT_INACTIVE, CHS, MBR}; +use mbrman::{BOOT_INACTIVE, CHS, MBR, MBRPartitionEntry}; use std::io::{Cursor, Read, Write}; use std::ops::Range; use std::path::Path; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 91e288eb9..79861cc0b 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -14,7 +14,7 @@ mod tpm; mod util; use crate::opt::{FmtOpt, TestOpt}; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use arch::UefiArch; use cargo::{Cargo, CargoAction, Feature, Package, TargetTypes}; use clap::Parser; diff --git a/xtask/src/qemu.rs b/xtask/src/qemu.rs index ee6d18161..854151e18 100644 --- a/xtask/src/qemu.rs +++ b/xtask/src/qemu.rs @@ -7,10 +7,10 @@ use crate::pipe::Pipe; use crate::tpm::Swtpm; use crate::util::command_to_string; use crate::{net, platform}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use ovmf_prebuilt::{FileType, Prebuilt, Source}; use regex::bytes::Regex; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use std::env; use std::ffi::OsString; use std::io::{BufRead, BufReader, Read, Write}; diff --git a/xtask/src/util.rs b/xtask/src/util.rs index 90e02dada..398aa64d1 100644 --- a/xtask/src/util.rs +++ b/xtask/src/util.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use std::process::Command; /// Format a `Command` as a `String.