Skip to content

Commit 316deea

Browse files
phip1611nicholasbishop
authored andcommitted
clippy: require must_use_candidate lint everywhere
1 parent 01b27af commit 316deea

File tree

31 files changed

+280
-0
lines changed

31 files changed

+280
-0
lines changed

uefi-services/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![no_std]
3030
#![feature(alloc_error_handler)]
3131
#![feature(abi_efiapi)]
32+
#![deny(clippy::must_use_candidate)]
3233

3334
extern crate log;
3435
// Core types.
@@ -64,6 +65,7 @@ static mut LOGGER: Option<uefi::logger::Logger> = None;
6465
/// `init` must have been called first by the UEFI app.
6566
///
6667
/// The returned pointer is only valid until boot services are exited.
68+
#[must_use]
6769
pub fn system_table() -> NonNull<SystemTable<Boot>> {
6870
unsafe {
6971
let table_ref = SYSTEM_TABLE

uefi/src/data_types/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub trait Align {
7373
/// Calculate the offset from `val` necessary to make it aligned,
7474
/// rounding up. For example, if `val` is 1 and the alignment is 8,
7575
/// this will return 7. Returns 0 if `val == 0`.
76+
#[must_use]
7677
fn offset_up_to_alignment(val: usize) -> usize {
7778
assert!(Self::alignment() != 0);
7879
let r = val % Self::alignment();
@@ -84,6 +85,7 @@ pub trait Align {
8485
}
8586

8687
/// Round `val` up so that it is aligned.
88+
#[must_use]
8789
fn round_up_to_alignment(val: usize) -> usize {
8890
val + Self::offset_up_to_alignment(val)
8991
}

uefi/src/data_types/strs.rs

+13
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl CStr8 {
7878
/// The function will start accessing memory from `ptr` until the first
7979
/// null byte. It's the callers responsibility to ensure `ptr` points to
8080
/// a valid null-terminated string in accessible memory.
81+
#[must_use]
8182
pub unsafe fn from_ptr<'ptr>(ptr: *const Char8) -> &'ptr Self {
8283
let mut len = 0;
8384
while *ptr.add(len) != NUL_8 {
@@ -106,22 +107,26 @@ impl CStr8 {
106107
///
107108
/// It's the callers responsibility to ensure chars is a valid Latin-1
108109
/// null-terminated string, with no interior null bytes.
110+
#[must_use]
109111
pub const unsafe fn from_bytes_with_nul_unchecked(chars: &[u8]) -> &Self {
110112
&*(chars as *const [u8] as *const Self)
111113
}
112114

113115
/// Returns the inner pointer to this CStr8.
116+
#[must_use]
114117
pub const fn as_ptr(&self) -> *const Char8 {
115118
self.0.as_ptr()
116119
}
117120

118121
/// Converts this CStr8 to a slice of bytes without the terminating null byte.
122+
#[must_use]
119123
pub fn to_bytes(&self) -> &[u8] {
120124
let chars = self.to_bytes_with_nul();
121125
&chars[..chars.len() - 1]
122126
}
123127

124128
/// Converts this CStr8 to a slice of bytes containing the trailing null byte.
129+
#[must_use]
125130
pub const fn to_bytes_with_nul(&self) -> &[u8] {
126131
unsafe { &*(&self.0 as *const [Char8] as *const [u8]) }
127132
}
@@ -189,6 +194,7 @@ impl CStr16 {
189194
/// The function will start accessing memory from `ptr` until the first
190195
/// null byte. It's the callers responsibility to ensure `ptr` points to
191196
/// a valid string, in accessible memory.
197+
#[must_use]
192198
pub unsafe fn from_ptr<'ptr>(ptr: *const Char16) -> &'ptr Self {
193199
let mut len = 0;
194200
while *ptr.add(len) != NUL_16 {
@@ -227,6 +233,7 @@ impl CStr16 {
227233
///
228234
/// It's the callers responsibility to ensure chars is a valid UCS-2
229235
/// null-terminated string, with no interior null bytes.
236+
#[must_use]
230237
pub const unsafe fn from_u16_with_nul_unchecked(codes: &[u16]) -> &Self {
231238
&*(codes as *const [u16] as *const Self)
232239
}
@@ -303,27 +310,32 @@ impl CStr16 {
303310
}
304311

305312
/// Returns the inner pointer to this C string
313+
#[must_use]
306314
pub const fn as_ptr(&self) -> *const Char16 {
307315
self.0.as_ptr()
308316
}
309317

310318
/// Get the underlying [`Char16`] slice, including the trailing null.
319+
#[must_use]
311320
pub const fn as_slice_with_nul(&self) -> &[Char16] {
312321
&self.0
313322
}
314323

315324
/// Converts this C string to a u16 slice
325+
#[must_use]
316326
pub fn to_u16_slice(&self) -> &[u16] {
317327
let chars = self.to_u16_slice_with_nul();
318328
&chars[..chars.len() - 1]
319329
}
320330

321331
/// Converts this C string to a u16 slice containing the trailing 0 char
332+
#[must_use]
322333
pub const fn to_u16_slice_with_nul(&self) -> &[u16] {
323334
unsafe { &*(&self.0 as *const [Char16] as *const [u16]) }
324335
}
325336

326337
/// Returns an iterator over this C string
338+
#[must_use]
327339
pub const fn iter(&self) -> CStr16Iter {
328340
CStr16Iter {
329341
inner: self,
@@ -332,6 +344,7 @@ impl CStr16 {
332344
}
333345

334346
/// Get the number of bytes in the string (including the trailing null character).
347+
#[must_use]
335348
pub const fn num_bytes(&self) -> usize {
336349
self.0.len() * 2
337350
}

uefi/src/data_types/unaligned_slice.rs

+5
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ impl<'a, T: Copy> UnalignedSlice<'a, T> {
3636
}
3737

3838
/// Returns true if the slice has a length of 0.
39+
#[must_use]
3940
pub const fn is_empty(&self) -> bool {
4041
self.len == 0
4142
}
4243

4344
/// Returns the number of elements in the slice.
45+
#[must_use]
4446
pub const fn len(&self) -> usize {
4547
self.len
4648
}
4749

4850
/// Returns the element at `index`, or `None` if the `index` is out
4951
/// of bounds.
52+
#[must_use]
5053
pub fn get(&self, index: usize) -> Option<T> {
5154
if index < self.len {
5255
Some(unsafe { self.data.add(index).read_unaligned() })
@@ -58,6 +61,7 @@ impl<'a, T: Copy> UnalignedSlice<'a, T> {
5861
/// Returns an iterator over the slice.
5962
///
6063
/// The iterator yields all items from start to end.
64+
#[must_use]
6165
pub const fn iter(&'a self) -> UnalignedSliceIter<'a, T> {
6266
UnalignedSliceIter {
6367
slice: self,
@@ -111,6 +115,7 @@ impl<'a, T: Copy> UnalignedSlice<'a, T> {
111115

112116
/// Copies `self` into a new `Vec`.
113117
#[cfg(feature = "alloc")]
118+
#[must_use]
114119
pub fn to_vec(&self) -> Vec<T> {
115120
let len = self.len();
116121
let mut v = Vec::with_capacity(len);

uefi/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
// Enable some additional warnings and lints.
6868
#![warn(clippy::ptr_as_ptr, missing_docs, unused)]
6969
#![deny(clippy::all)]
70+
#![deny(clippy::must_use_candidate)]
7071

7172
// Enable once we use vec![] or similar
7273
// #[cfg_attr(feature = "alloc", macro_use)]

uefi/src/proto/console/gop.rs

+12
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl<'boot> GraphicsOutput<'boot> {
109109
}
110110

111111
/// Returns information about all available graphics modes.
112+
#[must_use]
112113
pub fn modes(&'_ self) -> impl ExactSizeIterator<Item = Mode> + '_ {
113114
ModeIter {
114115
gop: self,
@@ -294,6 +295,7 @@ impl<'boot> GraphicsOutput<'boot> {
294295
}
295296

296297
/// Returns the frame buffer information for the current mode.
298+
#[must_use]
297299
pub const fn current_mode_info(&self) -> ModeInfo {
298300
*self.mode.info
299301
}
@@ -377,11 +379,13 @@ impl Mode {
377379
/// The size of the info structure in bytes.
378380
///
379381
/// Newer versions of the spec might add extra information, in a backwards compatible way.
382+
#[must_use]
380383
pub const fn info_size(&self) -> usize {
381384
self.info_sz
382385
}
383386

384387
/// Returns a reference to the mode info structure.
388+
#[must_use]
385389
pub const fn info(&self) -> &ModeInfo {
386390
&self.info
387391
}
@@ -404,16 +408,19 @@ impl ModeInfo {
404408
/// Returns the (horizontal, vertical) resolution.
405409
///
406410
/// On desktop monitors, this usually means (width, height).
411+
#[must_use]
407412
pub const fn resolution(&self) -> (usize, usize) {
408413
(self.hor_res as usize, self.ver_res as usize)
409414
}
410415

411416
/// Returns the format of the frame buffer.
417+
#[must_use]
412418
pub const fn pixel_format(&self) -> PixelFormat {
413419
self.format
414420
}
415421

416422
/// Returns the bitmask of the custom pixel format, if available.
423+
#[must_use]
417424
pub const fn pixel_bitmask(&self) -> Option<PixelBitmask> {
418425
match self.format {
419426
PixelFormat::Bitmask => Some(self.mask),
@@ -425,6 +432,7 @@ impl ModeInfo {
425432
///
426433
/// Due to performance reasons, the stride might not be equal to the width,
427434
/// instead the stride might be bigger for better alignment.
435+
#[must_use]
428436
pub const fn stride(&self) -> usize {
429437
self.stride as usize
430438
}
@@ -475,6 +483,7 @@ pub struct BltPixel {
475483

476484
impl BltPixel {
477485
/// Create a new pixel from RGB values.
486+
#[must_use]
478487
pub const fn new(red: u8, green: u8, blue: u8) -> Self {
479488
Self {
480489
red,
@@ -582,6 +591,7 @@ impl<'gop> FrameBuffer<'gop> {
582591
}
583592

584593
/// Query the framebuffer size in bytes
594+
#[must_use]
585595
pub const fn size(&self) -> usize {
586596
self.size
587597
}
@@ -607,6 +617,7 @@ impl<'gop> FrameBuffer<'gop> {
607617
/// - You must honor the pixel format and stride specified by the mode info
608618
/// - There is no bound checking on memory accesses in release mode
609619
#[inline]
620+
#[must_use]
610621
pub unsafe fn read_byte(&self, index: usize) -> u8 {
611622
debug_assert!(index < self.size, "Frame buffer accessed out of bounds");
612623
self.base.add(index).read_volatile()
@@ -647,6 +658,7 @@ impl<'gop> FrameBuffer<'gop> {
647658
/// - You must honor the pixel format and stride specified by the mode info
648659
/// - There is no bound checking on memory accesses in release mode
649660
#[inline]
661+
#[must_use]
650662
pub unsafe fn read_value<T>(&self, index: usize) -> T {
651663
debug_assert!(
652664
index.saturating_add(mem::size_of::<T>()) <= self.size,

uefi/src/proto/console/pointer/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ impl<'boot> Pointer<'boot> {
4747

4848
/// Event to be used with `BootServices::wait_for_event()` in order to wait
4949
/// for input from the pointer device
50+
#[must_use]
5051
pub const fn wait_for_input_event(&self) -> &Event {
5152
&self.wait_for_input
5253
}
5354

5455
/// Returns a reference to the pointer device information.
56+
#[must_use]
5557
pub const fn mode(&self) -> &PointerMode {
5658
self.mode
5759
}

uefi/src/proto/console/serial.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl<'boot> Serial<'boot> {
4444
}
4545

4646
/// Returns the current I/O mode.
47+
#[must_use]
4748
pub const fn io_mode(&self) -> &IoMode {
4849
self.io_mode
4950
}

uefi/src/proto/console/text/input.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl Input {
4444

4545
/// Event to be used with `BootServices::wait_for_event()` in order to wait
4646
/// for a key to be available
47+
#[must_use]
4748
pub const fn wait_for_key_event(&self) -> &Event {
4849
&self.wait_for_key
4950
}

uefi/src/proto/console/text/output.rs

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl<'boot> Output<'boot> {
129129
}
130130

131131
/// Returns whether the cursor is currently shown or not.
132+
#[must_use]
132133
pub const fn cursor_visible(&self) -> bool {
133134
self.data.cursor_visible
134135
}
@@ -142,6 +143,7 @@ impl<'boot> Output<'boot> {
142143
}
143144

144145
/// Returns the column and row of the cursor.
146+
#[must_use]
145147
pub const fn cursor_position(&self) -> (usize, usize) {
146148
let column = self.data.cursor_column;
147149
let row = self.data.cursor_row;
@@ -260,18 +262,21 @@ pub struct OutputMode {
260262
impl OutputMode {
261263
/// Returns the index of this mode.
262264
#[inline]
265+
#[must_use]
263266
pub const fn index(&self) -> usize {
264267
self.index
265268
}
266269

267270
/// Returns the width in columns.
268271
#[inline]
272+
#[must_use]
269273
pub const fn columns(&self) -> usize {
270274
self.dims.0
271275
}
272276

273277
/// Returns the height in rows.
274278
#[inline]
279+
#[must_use]
275280
pub const fn rows(&self) -> usize {
276281
self.dims.1
277282
}

uefi/src/proto/debug/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub struct DebugSupport {
5757

5858
impl DebugSupport {
5959
/// Returns the processor architecture of the running CPU.
60+
#[must_use]
6061
pub const fn arch(&self) -> ProcessorArch {
6162
self.isa
6263
}

0 commit comments

Comments
 (0)