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 impl Iterator when possible for _ return type #106172

Merged
merged 3 commits into from
Dec 28, 2022

Conversation

estebank
Copy link
Contributor

Address #106096.

@rustbot
Copy link
Collaborator

rustbot commented Dec 27, 2022

r? @spastorino

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 27, 2022
@rustbot
Copy link
Collaborator

rustbot commented Dec 27, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

r=me with nits or not

compiler/rustc_hir_analysis/src/collect.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_analysis/src/collect.rs Show resolved Hide resolved
Comment on lines +1282 to +1296
let ty_var = infcx.next_ty_var(origin);
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::Projection(
ty::ProjectionPredicate {
projection_ty: tcx.mk_alias_ty(iterator_item, tcx.mk_substs([ret_ty.into()].iter())),
term: ty_var.into(),
},
)));
// Add `<ret_ty as Iterator>::Item = _` obligation.
ocx.register_obligation(crate::traits::Obligation::misc(
tcx,
span,
hir_id,
tcx.param_env(def_id),
projection,
));
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 you can just construct a projection type then pass it to ocx.normalize instead, should make the code a lot simpler

Copy link
Member

Choose a reason for hiding this comment

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

I guess I'll fix this in a follow-up PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried making that change, but I must have done it incorrectly and it didn't work. Let's land this and clean it up soon.

Copy link
Member

Choose a reason for hiding this comment

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

Don't worry about it at all, I got it working on a local branch in any case. I do wonder what was wrong, though.

compiler/rustc_hir_analysis/src/collect.rs Outdated Show resolved Hide resolved
@estebank
Copy link
Contributor Author

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Dec 27, 2022

📌 Commit 96f37aff124d77c6b0355157cbddb0f6d36a3371 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 Dec 27, 2022
@compiler-errors
Copy link
Member

@bors r-

tests needs bless 😸

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 27, 2022
@rust-log-analyzer

This comment has been minimized.

@estebank
Copy link
Contributor Author

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Dec 27, 2022

📌 Commit b400bde 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 27, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 28, 2022
…piler-errors

Suggest `impl Iterator` when possible for `_` return type

Address rust-lang#106096.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 28, 2022
…piler-errors

Suggest `impl Iterator` when possible for `_` return type

Address rust-lang#106096.
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 28, 2022
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#106028 (docs/test: add UI test and long-form error docs for `E0461`)
 - rust-lang#106172 (Suggest `impl Iterator` when possible for `_` return type)
 - rust-lang#106173 (Deduplicate `op` methods)
 - rust-lang#106176 (Recover `fn` keyword as `Fn` trait in bounds)
 - rust-lang#106194 (rustdoc: combine common sidebar background color CSS rules)
 - rust-lang#106199 (Silence knock-down errors on `[type error]` bindings)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 31f5e75 into rust-lang:master Dec 28, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 28, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 4, 2023
…, r=estebank

Suggest `impl Fn*` and `impl Future` in `-> _` return suggestions

Follow-up to rust-lang#106172, only the last commit is relevant. Can rebase once that PR is landed for easier review.

Suggests `impl Future` and `impl Fn{,Mut,Once}` in `-> _` return suggestions.

r? `@estebank`
@estebank estebank deleted the suggest-impl-trait branch November 9, 2023 05:14
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants