Skip to content

Improve suggestion for calling fn-like expr on type mismatch #98280

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged

Conversation

compiler-errors
Copy link
Member

1.) Suggest calling values of with RPIT types (and probably TAIT) when we expect Ty and have impl Fn() -> Ty
2.) Suggest calling closures even when they're not assigned to a local variable first
3.) Drive-by fix of a pretty-printing bug (impl Fn()-> Ty => impl Fn() -> Ty)

r? @estebank

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 20, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2022
let sig = self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
if let ty::PredicateKind::Projection(proj) = pred.kind().skip_binder()
&& Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output()
&& let ty::Tuple(args) = proj.projection_ty.substs.type_at(1).kind() // args tuple will always be substs[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
&& let ty::Tuple(args) = proj.projection_ty.substs.type_at(1).kind() // args tuple will always be substs[1]
// args tuple will always be substs[1]
&& let ty::Tuple(args) = proj.projection_ty.substs.type_at(1).kind()

@estebank
Copy link
Contributor

r=me after addressing the comment comment :)

@compiler-errors compiler-errors force-pushed the better-call-closure-on-type-err branch from b85719a to d15fed7 Compare June 22, 2022 01:12
@compiler-errors
Copy link
Member Author

@bors r=estebank

@bors
Copy link
Collaborator

bors commented Jun 22, 2022

📌 Commit d15fed7 has been approved by estebank

@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 Jun 22, 2022
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 23, 2022
…-on-type-err, r=estebank

Improve suggestion for calling fn-like expr on type mismatch

1.) Suggest calling values of with RPIT types (and probably TAIT) when we expect `Ty` and have `impl Fn() -> Ty`
2.) Suggest calling closures even when they're not assigned to a local variable first
3.) Drive-by fix of a pretty-printing bug (`impl Fn()-> Ty` => `impl Fn() -> Ty`)

r? `@estebank`
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 24, 2022
…-on-type-err, r=estebank

Improve suggestion for calling fn-like expr on type mismatch

1.) Suggest calling values of with RPIT types (and probably TAIT) when we expect `Ty` and have `impl Fn() -> Ty`
2.) Suggest calling closures even when they're not assigned to a local variable first
3.) Drive-by fix of a pretty-printing bug (`impl Fn()-> Ty` => `impl Fn() -> Ty`)

r? ``@estebank``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 24, 2022
Rollup of 9 pull requests

Successful merges:

 - rust-lang#91264 (Add macro support in jump to definition feature)
 - rust-lang#96955 (Remove (transitive) reliance on sorting by DefId in pretty-printer)
 - rust-lang#97633 (Session object: Set OS/ABI)
 - rust-lang#98039 (Fix `panic` message for `BTreeSet`'s `range` API and document `panic` cases)
 - rust-lang#98214 (rustc_target: Remove some redundant target properties)
 - rust-lang#98280 (Improve suggestion for calling fn-like expr on type mismatch)
 - rust-lang#98394 (Fixup missing renames from `#[main]` to `#[rustc_main]`)
 - rust-lang#98411 (Update tendril)
 - rust-lang#98419 (Remove excess rib while resolving closures)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 964fc41 into rust-lang:master Jun 24, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 24, 2022
@compiler-errors compiler-errors deleted the better-call-closure-on-type-err branch August 11, 2023 19:55
# for free to join this conversation on GitHub. Already have an account? # 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.

6 participants