Skip to content

Check that the bounds of impl are implied by trait in a more general way #20020

Closed
@nikomatsakis

Description

@nikomatsakis

Currently we check that the where clauses on an impl are consistent with a trait by examining the TypeParameterDefs, and also with some specialized code around regions. This is not consistent with generalized where clauses. Probably the right approach is to:

  1. Create a ParameterEnvironment that contains the bounds from the trait method, substituted appropriately so that they are in the namespace of the impl.
  2. Create a fresh inference and fulfillment context.
  3. Register each bound in the impl method in that fulfillment context and then run select_all_or_error(). If any errors result, that indicates a bound in the impl that does not appear in the trait.
  4. We have to remember to also run resolve_regions_and_report_errors() as well to check for region obligations that are not satisfiable.

We may want to take some care here with respect to error messages; we probably want to print something more helpful about how there is a mismatch between the trait and impl.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions