Skip to content

"approximate check" for outlives relations can miss matches #54572

Description

@nikomatsakis

Per this comment, the current system for handling outlives obligations relies on an "approximate" match for outlives relations that is actually kind of flawed in some edge cases, which can lead to us overconstraining inference:

It's not really meant to be conservative in "two dimensions". That is, projection_approx_declared_bounds_from_env ought to return anything that might potentially be useful. I suspect this is not presently true, though, around bound regions and a few other edge cases (e.g., I think we by and large ignore things like for<'a> T::Proj<'a>: 'a, which is really a bug, although a pre-existing one; we also are too conservative I think around equality of types like for<'a> fn(&'a u32) vs for<'b> fn(&'b u32). Also a pre-existing bug.)

I might be able to fix those cases where we are "overly" conservative though via a more thorough erasure. I think erasing regions today preserves the lifetime bounds, but we would ideally look for an "equality" check that just completely ignores region equality (even around binders). I was working towards that but never finished it.

Originally, I had intended to fix this by using the "type relation" code from the NLL type checker, but in a mode where it ignored all the outlives relations. I introduced the idea of an "outlives delegate" and so forth in preparation for that but then never took the last step, since "erasing obligations" seemed simpler and sufficient for the moment.

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-NLLArea: Non-lexical lifetimes (NLL)
    on Sep 25, 2018
  2. pnkfelix commented on Oct 2, 2018

    @pnkfelix
    Contributor

    SInce this is about getting "valid code" to compile, tagging as NLL-complete. But @nikomatsakis notes that it does not feel that urgent, so we're also tagging as NLL-deferred.

  3. pnkfelix commented on Dec 21, 2018

    @pnkfelix
    Contributor

    Re-triaging for #56754. P-low.

  4. aliemjay commented on Mar 2, 2023

    @aliemjay
    Contributor

    I believe the work intended here was implemented in #98109. We now support where for<'a> T::Proj<'a>: 'a and we have equality around binders via the test_type_match machinery.

    Close?

  5. aliemjay commented on May 1, 2023

    @aliemjay
    Contributor

    Closing as fixed in #98109.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)NLL-completeWorking towards the "valid code works" goalP-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