Skip to content

Higher-ranked subtyping is too strict #33684

Closed

Description

@nikomatsakis

Branching off from #32330. The current subtyping rules for higher-ranked regions are overly conservative, with the result that a function declaration like this:

fn foo<'a>() -> &'a i32

is not equivalent to

fn foo() -> &'static i32

This exaggerates the impact of #32330 because functions like

fn foo<'a>(&self) -> &'a i32

must be converted to the form

fn foo<'a>(&'a self) -> &'a i32

in some cases, which feels a bit silly.

I proposed a fix in #32330 (described in some detail here), however I decided to hold off and land that fix separately, when I had more time to polish it (and consider it). In the meantime, this does mean that we wind up with more warnings than we otherwise would.

There is some mild backcompat risk in that the current coherence rules will allow you to distinguish between types on the basis of bound regions, but in some cases that is wrong. It is probably worth modifying coherence so that it doesn't distinguish bound regions at all -- or better yet, operates with fully erased regions.

Activity

  1. nikomatsakis commented on May 17, 2016

    @nikomatsakis
    ContributorAuthor
  2. added a commit that references this issue on Aug 31, 2017
    f6d72d2
  3. added a commit that references this issue on Sep 12, 2017
    5883be8
  4. added a commit that references this issue on Mar 19, 2018
  5. 20 remaining items

  6. added a commit that references this issue on Jan 5, 2019
    a0ccf99
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

    C-bugCategory: This is a bug.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions