Skip to content

Account for HRTB on unsatisfied trait bound suggestions #66762

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
estebank opened this issue Nov 26, 2019 · 1 comment
Open

Account for HRTB on unsatisfied trait bound suggestions #66762

estebank opened this issue Nov 26, 2019 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

When encountering a higher-ranked-trait-bound error where the compiler would suggest adding a new where bound that is the same as an existing bound, the suggestion should be to replace the existing one with the hrtb version:

before:

error[E0277]: the trait bound `for<'tcx> F: Foo<'tcx>` is not satisfied
  --> $DIR/hrtb-higher-ranker-supertraits.rs:18:26
   |
LL |     where F : Foo<'x>
   |                      - help: consider further restricting type parameter `F`: `, F: for<'tcx> Foo<'tcx>`
...
LL |     want_foo_for_any_tcx(f);
   |                          ^ the trait `for<'tcx> Foo<'tcx>` is not implemented for `F`
...
LL | fn want_foo_for_any_tcx<F>(f: &F)
   |    --------------------
LL |     where F : for<'tcx> Foo<'tcx>
   |               ------------------- required by this bound in `want_foo_for_any_tcx`

after:

error[E0277]: the trait bound `for<'tcx> F: Foo<'tcx>` is not satisfied
  --> $DIR/hrtb-higher-ranker-supertraits.rs:18:26
   |
LL |     where F : Foo<'x>
   |           ----------- help: consider restricting type parameter `F` with HRTB: `F: for<'tcx> Foo<'tcx>`
...
LL |     want_foo_for_any_tcx(f);
   |                          ^ the trait `for<'tcx> Foo<'tcx>` is not implemented for `F`
...
LL | fn want_foo_for_any_tcx<F>(f: &F)
   |    --------------------
LL |     where F : for<'tcx> Foo<'tcx>
   |               ------------------- required by this bound in `want_foo_for_any_tcx`
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Nov 26, 2019
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jan 12, 2020
@Dylan-DPC
Copy link
Member

this code no longer errors and now compiles so we would need another sample if this error still occurs

@fmease fmease added the A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants