mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Enable or_fun_call lint to avoid unnecessary allocations (#7754)
### What From the [lint description](https://rust-lang.github.io/rust-clippy/master/index.html?search=or_fu#or_fun_call): > The function will always be called. This is only bad if it allocates or does some non-trivial amount of work. But also: > If the function has side-effects, not calling it will change the semantic of the program, but you shouldn’t rely on that. > > The lint also cannot figure out whether the function you call is actually expensive to call or not. Still worth it to keep our happy paths clean, imo.
This commit is contained in:
@@ -264,7 +264,8 @@ impl Display for SnapshotError {
|
||||
diff,
|
||||
diff_path,
|
||||
} => {
|
||||
let diff_path = std::path::absolute(diff_path).unwrap_or(diff_path.clone());
|
||||
let diff_path =
|
||||
std::path::absolute(diff_path).unwrap_or_else(|_| diff_path.clone());
|
||||
write!(
|
||||
f,
|
||||
"'{name}' Image did not match snapshot. Diff: {diff}, {}. {HOW_TO_UPDATE_SCREENSHOTS}",
|
||||
@@ -272,7 +273,7 @@ impl Display for SnapshotError {
|
||||
)
|
||||
}
|
||||
Self::OpenSnapshot { path, err } => {
|
||||
let path = std::path::absolute(path).unwrap_or(path.clone());
|
||||
let path = std::path::absolute(path).unwrap_or_else(|_| path.clone());
|
||||
match err {
|
||||
ImageError::IoError(io) => match io.kind() {
|
||||
ErrorKind::NotFound => {
|
||||
@@ -310,7 +311,7 @@ impl Display for SnapshotError {
|
||||
)
|
||||
}
|
||||
Self::WriteSnapshot { path, err } => {
|
||||
let path = std::path::absolute(path).unwrap_or(path.clone());
|
||||
let path = std::path::absolute(path).unwrap_or_else(|_| path.clone());
|
||||
write!(f, "Error writing snapshot: {err}\nAt: {}", path.display())
|
||||
}
|
||||
Self::RenderError { err } => {
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn default_wgpu_setup() -> egui_wgpu::WgpuSetup {
|
||||
adapters
|
||||
.first()
|
||||
.map(|a| (*a).clone())
|
||||
.ok_or("No adapter found".to_owned())
|
||||
.ok_or_else(|| "No adapter found".to_owned())
|
||||
}));
|
||||
|
||||
egui_wgpu::WgpuSetup::CreateNew(setup)
|
||||
|
||||
Reference in New Issue
Block a user