Skip to content

Eliminate the function call in xxx_or (e.g. unwrap_or("".to_string()) #15802

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

Open
Rachelint opened this issue Apr 22, 2025 · 2 comments · May be fixed by #15841
Open

Eliminate the function call in xxx_or (e.g. unwrap_or("".to_string()) #15802

Rachelint opened this issue Apr 22, 2025 · 2 comments · May be fixed by #15841
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Rachelint
Copy link
Contributor

Rachelint commented Apr 22, 2025

Is your feature request related to a problem or challenge?

I found some unnecessary functions are called, due to using unwrap_or rather than unwrap_or_else in funcation call case (some fucntion calls may be not really cheap).
I have eliminate some of them in SessionStateBuilder::build(#15800 ), but I think we should use lints to ensure it.

Describe the solution you'd like

  • Add or_fun_call lint to crates
  • Make clippy again by eliminating the function call in unwrap_or
  • It is better to also add unnecessary_lazy_evaluations to avoid abusing unwrap_or_else

Describe alternatives you've considered

No response

Additional context

No response

@Rachelint Rachelint added the enhancement New feature or request label Apr 22, 2025
@Rachelint
Copy link
Contributor Author

Rachelint commented Apr 22, 2025

Recommend to add the lint crate by crate(one pr for one crate), like what are done in #11143
Here is an example adding these two lints to core crate:
#15807

@lifan-ake
Copy link

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants