-
Notifications
You must be signed in to change notification settings - Fork 1.7k
or_fun_call
isn't always a performance lint
#8574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@rustbot claim |
Hi @hrxi ! |
Hey @fedemartinezdev, welcome to Clippy 👋. In general we have Clippy's lint list which I use a lot. In this case, I searched for |
I ran into this same issue! It's not just |
I just ran into more clippy suggestions where it doesn't improve performance:
Or a couple of others, the pattern is the same, |
Also change its category to `style` so it's clear that it's not always a performance lint. Fixes rust-lang#8574.
Also change its category to `style` so it's clear that it's not always a performance lint. Fixes rust-lang#8574.
Also move it to nursery so that the false-positives can be dealt with. CC rust-lang#8574
Also move it to nursery so that the false-positives can be dealt with. CC rust-lang#8574
Make it clear that `or_fun_call` can be a false-positive Also move it to nursery so that the false-positives can be dealt with. CC #8574 changelog: [`or_fun_call`]: Mention false-positives, move to nursery.
@hrxi Do you still have the full example? I am having trouble reproducing the behavior you described. For example, the following does not seem to trigger enum Enum {
InvalidUtf8,
}
fn foo() -> Result<String, Enum> {
let vec = Vec::new();
String::from_utf8(vec).or(Err(Enum::InvalidUtf8))
} |
#![warn(clippy::or_fun_call)]
use std::borrow::Cow;
fn foo() -> Result<String, Cow<'static, str>> {
let vec = Vec::new();
String::from_utf8(vec).or(Err(Cow::from("abc")))
}
fn main() { let _ = foo(); }
Haven't tried to minimize it. |
Thanks! |
I think my question was imprecise, though. I was looking for an example that produces equivalent code even when Am I making a mistake? For context, I am trying to understand what is needed to move |
It seems you're not compiling with optimizations ( I shortened the code a little and get equivalent assembly, the |
Thanks again! |
Replacing
.unwrap_or(Vec::new())
with.unwrap_or_default()
doesn't do anything for performance, they produce identical machine code with optimizations: https://rust.godbolt.org/z/hzTdazGqW.Perhaps the lint category could be changed or it could be changed to not detect cases where it's not actually a performance warning?
The text was updated successfully, but these errors were encountered: