Skip to content

Commit e88d340

Browse files
committed
Fix remaining clippy warnings
1 parent ebfd09a commit e88d340

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

src/args/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl RunnerCommand {
5252
}
5353

5454
Ok(Self::Runner(RunnerArgs {
55-
executable: executable.ok_or(anyhow!(
55+
executable: executable.ok_or_else(|| anyhow!(
5656
"excepted path to kernel executable as first argument"
5757
))?,
5858
quiet,

src/bin/cargo-bootimage.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn main() -> Result<()> {
1414

1515
let executable_name = raw_args
1616
.next()
17-
.ok_or(anyhow!("no first argument (executable name)"))?;
17+
.ok_or_else(|| anyhow!("no first argument (executable name)"))?;
1818
let file_stem = Path::new(&executable_name)
1919
.file_stem()
2020
.and_then(|s| s.to_str());
@@ -30,8 +30,13 @@ pub fn main() -> Result<()> {
3030

3131
match BuildCommand::parse_args(raw_args)? {
3232
BuildCommand::Build(args) => build(args),
33-
BuildCommand::Version => Ok(help::print_version()),
34-
BuildCommand::Help => Ok(help::print_cargo_bootimage_help()),
33+
BuildCommand::Version => {
34+
help::print_version(); Ok(())
35+
},
36+
BuildCommand::Help => {
37+
help::print_cargo_bootimage_help();
38+
Ok(())
39+
},
3540
}
3641
}
3742

@@ -47,12 +52,12 @@ fn build(args: BuildArgs) -> Result<()> {
4752
for executable in executables {
4853
let out_dir = executable
4954
.parent()
50-
.ok_or(anyhow!("executable has no parent path"))?;
55+
.ok_or_else(|| anyhow!("executable has no parent path"))?;
5156
let bin_name = &executable
5257
.file_stem()
53-
.ok_or(anyhow!("executable has no file stem"))?
58+
.ok_or_else(|| anyhow!("executable has no file stem"))?
5459
.to_str()
55-
.ok_or(anyhow!("executable file stem not valid utf8"))?;
60+
.ok_or_else(|| anyhow!("executable file stem not valid utf8"))?;
5661

5762
let bootimage_path = out_dir.join(format!("bootimage-{}.bin", bin_name));
5863
builder.create_bootimage(bin_name, &executable, &bootimage_path, quiet)?;

src/builder/bootloader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl BuildConfig {
2929
bootloader_pkg
3030
.manifest_path
3131
.parent()
32-
.ok_or(BootloaderError::BootloaderInvalid(
32+
.ok_or_else(|| BootloaderError::BootloaderInvalid(
3333
"bootloader manifest has no target directory".into(),
3434
))?;
3535

@@ -47,7 +47,7 @@ impl BuildConfig {
4747
let target_str =
4848
target
4949
.and_then(|v| v.as_str())
50-
.ok_or(BootloaderError::BootloaderInvalid(
50+
.ok_or_else(|| BootloaderError::BootloaderInvalid(
5151
"No `package.metadata.bootloader.target` key found in Cargo.toml of bootloader\n\n\
5252
(If you're using the official bootloader crate, you need at least version 0.5.1)"
5353
.into(),
@@ -93,7 +93,7 @@ impl BuildConfig {
9393

9494
/// Creates the cargo build command for building the bootloader.
9595
pub fn build_command(&self) -> Command {
96-
let cargo = std::env::var("CARGO").unwrap_or("cargo".to_owned());
96+
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
9797
let mut cmd = Command::new(&cargo);
9898
cmd.arg("xbuild");
9999
cmd.arg("--manifest-path");

src/builder/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Builder {
4848
}
4949

5050
// try to run cargo xbuild
51-
let cargo = std::env::var("CARGO").unwrap_or("cargo".to_owned());
51+
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
5252
let mut cmd = process::Command::new(&cargo);
5353
cmd.arg("xbuild");
5454
cmd.args(args);
@@ -172,7 +172,7 @@ impl Builder {
172172
}
173173
}
174174
}
175-
let bootloader_elf_path = bootloader_elf_path.ok_or(BootloaderError::BootloaderInvalid(
175+
let bootloader_elf_path = bootloader_elf_path.ok_or_else(|| BootloaderError::BootloaderInvalid(
176176
"bootloader has no executable".into(),
177177
))?;
178178

src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn read_config_inner(manifest_path: &Path) -> Result<Config> {
5959
}
6060
Some(metadata) => metadata
6161
.as_table()
62-
.ok_or(anyhow!("Bootimage configuration invalid: {:?}", metadata))?,
62+
.ok_or_else(|| anyhow!("Bootimage configuration invalid: {:?}", metadata))?,
6363
};
6464

6565
let mut config = ConfigBuilder::default();
@@ -128,7 +128,7 @@ struct ConfigBuilder {
128128
impl Into<Config> for ConfigBuilder {
129129
fn into(self) -> Config {
130130
Config {
131-
run_command: self.run_command.unwrap_or(vec![
131+
run_command: self.run_command.unwrap_or_else(|| vec![
132132
"qemu-system-x86_64".into(),
133133
"-drive".into(),
134134
"format=raw,file={}".into(),

src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn main() -> Result<()> {
1414

1515
let executable_name = raw_args
1616
.next()
17-
.ok_or(anyhow!("no first argument (executable name)"))?;
17+
.ok_or_else(|| anyhow!("no first argument (executable name)"))?;
1818
let file_stem = Path::new(&executable_name)
1919
.file_stem()
2020
.and_then(|s| s.to_str());
@@ -63,12 +63,12 @@ pub(crate) fn runner(args: RunnerArgs) -> Result<i32> {
6363
let exe_parent = args
6464
.executable
6565
.parent()
66-
.ok_or(anyhow!("kernel executable has no parent"))?;
66+
.ok_or_else(|| anyhow!("kernel executable has no parent"))?;
6767
let is_doctest = exe_parent
6868
.file_name()
69-
.ok_or(anyhow!("kernel executable's parent has no file name"))?
69+
.ok_or_else(|| anyhow!("kernel executable's parent has no file name"))?
7070
.to_str()
71-
.ok_or(anyhow!(
71+
.ok_or_else(|| anyhow!(
7272
"kernel executable's parent file name is not valid UTF-8"
7373
))?
7474
.starts_with("rustdoctest");
@@ -77,9 +77,9 @@ pub(crate) fn runner(args: RunnerArgs) -> Result<i32> {
7777
let bin_name = args
7878
.executable
7979
.file_stem()
80-
.ok_or(anyhow!("kernel executable has no file stem"))?
80+
.ok_or_else(|| anyhow!("kernel executable has no file stem"))?
8181
.to_str()
82-
.ok_or(anyhow!("kernel executable file stem is not valid UTF-8"))?;
82+
.ok_or_else(|| anyhow!("kernel executable file stem is not valid UTF-8"))?;
8383

8484
let output_bin_path = exe_parent.join(format!("bootimage-{}.bin", bin_name));
8585
let executable_canonicalized = args.executable.canonicalize().with_context(|| {
@@ -143,7 +143,7 @@ pub(crate) fn runner(args: RunnerArgs) -> Result<i32> {
143143
}
144144
let qemu_exit_code = exit_status
145145
.code()
146-
.ok_or(anyhow!("Failed to read QEMU exit code"))?;
146+
.ok_or_else(|| anyhow!("Failed to read QEMU exit code"))?;
147147
match config.test_success_exit_code {
148148
Some(code) if qemu_exit_code == code => 0,
149149
_ => qemu_exit_code,

0 commit comments

Comments
 (0)