Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sethdusek
Copy link

@sethdusek sethdusek commented Jun 24, 2025

Previously expect_fun_call would too eagerly convert cases like foo.expect(if | block | match) into foo.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:

  • Clippy would suggest changing expect to unwrap_or_else even if the expression inside expect contains a return statement
  • opt.expect(const_fn()) no longer triggers the lint
  • The lint would always add braces to the closure body, even if the body of expect is a single expression
  • opt.expect({"literal"}) used to get turned into opt.unwrap_or_else(|| panic!("{}", {"literal"}.to_string()))

Fixes #15056

changelog: [expect_fun_call]: fix expect_fun_call producing invalid suggestions

@rustbot
Copy link
Collaborator

rustbot commented Jun 24, 2025

r? @samueltardieu

rustbot has assigned @samueltardieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Garbage clippy::expect_fun_call lint for result.expect(if b { "" } else { "" })
3 participants