Skip to content

Account for HRTB on unsatisfied trait bound suggestions #66762

Open
@estebank

Description

@estebank

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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions