-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix expect_fun_call producing invalid suggestions #15122
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
Conversation
rustbot has assigned @samueltardieu. Use |
What's the rationale behind this? |
Note: this doesn't fix #15195 (nor does it pretend to) |
This behavior is inherited from switch_to_lazy_eval() which is also used by the or_fun_call lint, and #![warn(clippy::or_fun_call)]
fn call() -> i32 {
0
}
const fn const_call() -> i32 {
0
}
fn opt() -> Option<i32> {
None
}
fn main() {
let a: Option<i32> = opt();
a.unwrap_or(call()); // triggers the lint
a.unwrap_or(const_call()); // doesn't trigger
} Should I try to address this in this same PR or handle it separately? |
This comment was marked as outdated.
This comment was marked as outdated.
As far as I can see while testing, it doesn't allow |
A separate PR (prerequisite for this one) would be preferable as to evaluate the effects on other callers of the eagerness evaluator. |
After the experiment in #15211 we have to choose whether we want to lint on
Note that if the call to the Would you be wanting to try looking for function or method calls which are made outside an always- @rustbot author |
Reminder, once the PR becomes ready for a review, use |
30c1358
to
a605431
Compare
@rustbot ready |
Thanks |
Previously expect_fun_call would too eagerly convert cases like
foo.expect(if | block | match)
intofoo.unwrap_or_else
. Additionally, it would also add to_string() even though the argument is being passed into format!() which can accept a &str. I also discovered some other cases where this lint would either produce invalid results, or be triggered unnecessarily:opt.unwrap_or_else(|| panic!("{}", {"literal"}.to_string()))
Fixes #15056
changelog: [
expect_fun_call
]: fix expect_fun_call producing invalid suggestions