Skip to content

Commit a5cb371

Browse files
Manciukicbchalios
authored andcommitted
chore(clippy): enable warn for or_fun_call
"or_fun_call" warns us when a function is called in side a "*_or(...)" function. In this case the value is computed (which may be expensive), but is only used if the Result/Option is an Error/None. In these cases, using the "*_or_else" variant is the best thing to do. Signed-off-by: Riccardo Mancini <[email protected]> Signed-off-by: Babis Chalios <[email protected]>
1 parent bd22a2d commit a5cb371

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ exit = "warn"
2929
tests_outside_test_module = "warn"
3030
assertions_on_result_states = "warn"
3131
error_impl_error = "warn"
32+
or_fun_call = "warn"
3233

3334
[profile.dev]
3435
panic = "abort"

src/clippy-tracing/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl Error for ExecError {}
260260
fn exec() -> Result<Option<(PathBuf, usize, usize)>, ExecError> {
261261
let args = CommandLineArgs::parse();
262262

263-
let path = args.path.unwrap_or(PathBuf::from("."));
263+
let path = args.path.unwrap_or_else(|| PathBuf::from("."));
264264
for entry_res in WalkDir::new(path).follow_links(true) {
265265
let entry = entry_res.map_err(ExecError::Entry)?;
266266
let entry_path = entry.into_path();

src/cpu-template-helper/src/template/verify/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ where
4343
for (key, template_value_filter) in template {
4444
let config_value_filter = config
4545
.get(&key)
46-
.ok_or(VerifyError::KeyNotFound(key.to_string()))?;
46+
.ok_or_else(|| VerifyError::KeyNotFound(key.to_string()))?;
4747

4848
let template_value = template_value_filter.value & template_value_filter.filter;
4949
let config_value = config_value_filter.value & template_value_filter.filter;

src/vmm/src/vstate/vm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ impl InterruptSourceGroup for MsiVectorGroup {
170170

171171
fn trigger(&self, index: InterruptIndex) -> vm_device::interrupt::Result<()> {
172172
self.notifier(index)
173-
.ok_or_else(|| std::io::Error::other(format!(
174-
"trigger: invalid interrupt index {index}"
175-
)))?
173+
.ok_or_else(|| {
174+
std::io::Error::other(format!("trigger: invalid interrupt index {index}"))
175+
})?
176176
.write(1)
177177
}
178178

0 commit comments

Comments
 (0)