Skip to content

Commit 2576556

Browse files
committed
Address Clippy lints and re-run rustfmt
1 parent 79a27ba commit 2576556

File tree

7 files changed

+48
-35
lines changed

7 files changed

+48
-35
lines changed

src/proto/console/text/output.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ impl fmt::Write for Output {
136136
buf[*i] = 0;
137137
*i = 0;
138138

139-
self.output_string(buf.as_ptr())
140-
.map_err(|_| fmt::Error)
139+
self.output_string(buf.as_ptr()).map_err(|_| fmt::Error)
141140
};
142141

143142
// This closure converts a character to UCS-2 and adds it to the buffer,

src/table/boot.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,20 @@ impl BootServices {
292292
///
293293
/// If provided, the watchdog data must be a null-terminated string
294294
/// optionally followed by other binary data.
295-
pub fn set_watchdog_timer(&self, timeout: usize, watchdog_code: u64, data: Option<&mut [u16]>) -> Result<()> {
296-
let (data_len, data) =
297-
data.map(|d| {
298-
assert!(d.contains(&0), "Watchdog data must contain a null-terminated string");
299-
(d.len(), d.as_mut_ptr())
300-
})
301-
.unwrap_or((0, ptr::null_mut()));
295+
pub fn set_watchdog_timer(
296+
&self,
297+
timeout: usize,
298+
watchdog_code: u64,
299+
data: Option<&mut [u16]>,
300+
) -> Result<()> {
301+
let (data_len, data) = data
302+
.map(|d| {
303+
assert!(
304+
d.contains(&0),
305+
"Watchdog data must contain a null-terminated string"
306+
);
307+
(d.len(), d.as_mut_ptr())
308+
}).unwrap_or((0, ptr::null_mut()));
302309

303310
(self.set_watchdog_timer)(timeout, watchdog_code, data_len, data).into()
304311
}

uefi-exts/src/boot.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ impl BootServicesExt for BootServices {
4949
// We have to retrieve them all and find one that works.
5050
.iter()
5151
.map(|&handle| self.handle_protocol::<P>(handle))
52-
// Only choose a handle which implements the protocol.
53-
.filter(Option::is_some)
54-
// Pick the first one that works.
55-
.next()
52+
// Find a handle which implements the protocol.
53+
.find(Option::is_some)
5654
// Filter itself returns an option, we need to lift it out.
5755
.unwrap_or(None)
5856
}

uefi-logger/src/lib.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ impl log::Log for Logger {
4545

4646
fn log(&self, record: &log::Record) {
4747
let writer = unsafe { &mut *self.writer.get() };
48-
DecoratedLog::write(writer,
49-
record.level(),
50-
record.args()).unwrap();
48+
DecoratedLog::write(writer, record.level(), record.args()).unwrap();
5149
}
5250

5351
fn flush(&self) {
@@ -59,7 +57,6 @@ impl log::Log for Logger {
5957
unsafe impl Sync for Logger {}
6058
unsafe impl Send for Logger {}
6159

62-
6360
/// Writer wrapper which prints a log level in front of every line of text
6461
///
6562
/// This is less easy than it sounds because...
@@ -71,18 +68,15 @@ unsafe impl Send for Logger {}
7168
///
7269
/// Therefore, we need to inject ourselves in the middle of the fmt::Write
7370
/// machinery and intercept the strings that it sends to the Writer.
74-
///.
7571
struct DecoratedLog<'a, W: fmt::Write> {
7672
backend: &'a mut W,
7773
log_level: log::Level,
7874
at_line_start: bool,
7975
}
80-
//
76+
8177
impl<'a, W: fmt::Write> DecoratedLog<'a, W> {
8278
// Call this method to print a level-annotated log
83-
fn write(writer: &'a mut W,
84-
level: log::Level,
85-
args: &fmt::Arguments) -> fmt::Result {
79+
fn write(writer: &'a mut W, level: log::Level, args: &fmt::Arguments) -> fmt::Result {
8680
let mut decorated_writer = Self {
8781
backend: writer,
8882
log_level: level,
@@ -91,7 +85,7 @@ impl<'a, W: fmt::Write> DecoratedLog<'a, W> {
9185
writeln!(decorated_writer, "{}", *args)
9286
}
9387
}
94-
//
88+
9589
impl<'a, W: fmt::Write> fmt::Write for DecoratedLog<'a, W> {
9690
fn write_str(&mut self, s: &str) -> fmt::Result {
9791
// Split the input string into lines
@@ -122,4 +116,4 @@ impl<'a, W: fmt::Write> fmt::Write for DecoratedLog<'a, W> {
122116
}
123117
Ok(())
124118
}
125-
}
119+
}

uefi-services/src/lib.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
//! through the reference provided by `system_table`.
1111
1212
#![no_std]
13+
#![feature(alloc_error_handler)]
14+
#![feature(asm)]
1315
#![feature(lang_items)]
1416
#![feature(panic_info_message)]
15-
#![feature(alloc_error_handler)]
1617

1718
// These crates are required.
1819
extern crate rlibc;
@@ -139,11 +140,19 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
139140

140141
// If we don't have any shutdown mechanism handy, the best we can do is loop
141142
error!("Could not shut down, please power off the system manually...");
142-
loop {}
143+
144+
loop {
145+
unsafe {
146+
// Try to at least keep CPU from running at 100%
147+
asm!("hlt" :::: "volatile");
148+
}
149+
}
143150
}
144151

145152
#[alloc_error_handler]
146-
fn out_of_memory(_: ::core::alloc::Layout) -> ! {
147-
// TODO: handle out-of-memory conditions
148-
loop {}
153+
fn out_of_memory(layout: ::core::alloc::Layout) -> ! {
154+
panic!(
155+
"Ran out of free memory while trying to allocate {:#?}",
156+
layout
157+
);
149158
}

uefi-test-runner/src/boot/memory.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ fn memmove(bt: &BootServices) {
5151
let mut dest = [0u8; 4];
5252

5353
// Fill the buffer with a value
54-
unsafe { bt.memset(dest.as_mut_ptr(), dest.len(), 1); }
54+
unsafe {
55+
bt.memset(dest.as_mut_ptr(), dest.len(), 1);
56+
}
5557

5658
assert_eq!(dest, [1; 4], "Failed to set memory");
5759

5860
// Copy other values on it
59-
unsafe { bt.memmove(dest.as_mut_ptr(), src.as_ptr(), dest.len()); }
61+
unsafe {
62+
bt.memmove(dest.as_mut_ptr(), src.as_ptr(), dest.len());
63+
}
6064

6165
assert_eq!(dest, src, "Failed to copy memory");
6266
}

uefi-test-runner/src/proto/console/serial.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ pub fn test(bt: &BootServices) {
66
if let Some(mut serial) = bt.find_protocol::<Serial>() {
77
let serial = unsafe { serial.as_mut() };
88

9-
let old_ctrl_bits = serial.get_control_bits()
10-
.expect("Failed to get device control bits");
9+
let old_ctrl_bits = serial
10+
.get_control_bits()
11+
.expect("Failed to get device control bits");
1112
let mut ctrl_bits = ControlBits::empty();
1213

1314
// For the purposes of testing, we're _not_ going to implement
@@ -40,8 +41,9 @@ pub fn test(bt: &BootServices) {
4041

4142
// Clean up after ourselves
4243
serial.reset().expect("Could not reset the serial device");
43-
serial.set_control_bits(old_ctrl_bits & ControlBits::SETTABLE)
44-
.expect("Could not restore the serial device state");
44+
serial
45+
.set_control_bits(old_ctrl_bits & ControlBits::SETTABLE)
46+
.expect("Could not restore the serial device state");
4547
} else {
4648
warn!("No serial device found");
4749
}

0 commit comments

Comments
 (0)