Skip to content
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

Suggest unwrap_or_else when a closure is given #102441

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

chenyukang
Copy link
Member

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 28, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2022
@chenyukang
Copy link
Member Author

May need more work to expand to suggest map_or_else, etc.

@bors
Copy link
Contributor

bors commented Oct 1, 2022

☔ The latest upstream changes (presumably #102545) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

… to unwrap_or instead of suggesting calling it
err: &mut Diagnostic,
expr: &hir::Expr<'_>,
found: Ty<'tcx>,
can_satisfy: impl FnOnce(Ty<'tcx>) -> bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be an argument. Can you inline the can_coerce call here by passing in expected: Ty<'tcx>?

..,
) = call_expr.kind
{
let self_ty = self.typeck_results.borrow().expr_ty(self_expr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is an expr_ty_opt version of this that doesn't ICE if the node is missing a type If so, then please use that, just in case.

let fn_ty = self.tcx.type_of(pick.item.def_id) &&
let fn_sig = fn_ty.fn_sig(self.tcx) &&
let fn_args = fn_sig.skip_binder().inputs() &&
fn_args.len() == args.len() +1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn_args.len() == args.len() +1 {
fn_args.len() == args.len() + 1 {

Comment on lines 2366 to 2367
let fn_ty = self.tcx.type_of(pick.item.def_id) &&
let fn_sig = fn_ty.fn_sig(self.tcx) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let fn_ty = self.tcx.type_of(pick.item.def_id) &&
let fn_sig = fn_ty.fn_sig(self.tcx) &&
let fn_sig = self.tcx.fn_sig(pick.item.def_id) &&

@compiler-errors
Copy link
Member

Few more nits

@chenyukang
Copy link
Member Author

Few more nits

Fixed, thanks!

@compiler-errors
Copy link
Member

Hm, this suggestion might have some false positives still, but this is probably ok...

@bors r+

@bors
Copy link
Contributor

bors commented Oct 4, 2022

📌 Commit 0188273 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 4, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 4, 2022
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#102441 (Suggest unwrap_or_else when a closure is given)
 - rust-lang#102547 (Migrate CSS theme for search results)
 - rust-lang#102567 (Delay evaluating lint primary message until after it would be suppressed)
 - rust-lang#102624 (rustdoc: remove font family CSS on `.rustdoc-toggle summary::before`)
 - rust-lang#102628 (Change the parameter name of From::from to `value`)
 - rust-lang#102637 (Ignore fuchsia on two compiler tests)
 - rust-lang#102639 (Improve spans when splitting multi-char operator tokens for proc macros.)

Failed merges:

 - rust-lang#102496 (Suggest `.into()` when all other coercion suggestions fail)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a2126e7 into rust-lang:master Oct 4, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggest unwrap_or_else when a closure is passed to unwrap_or instead of suggesting calling it
6 participants