Skip to content
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

Fix coherence checking for impl trait in type aliases #63934

Merged
merged 2 commits into from
Sep 25, 2019

Commits on Sep 24, 2019

  1. Fix coherence checking for impl trait in type aliases

    Fixes rust-lang#63677
    
    RFC rust-lang#2071 (impl-trait-existential-types) does not explicitly state how
    impl trait type alises should interact with coherence. However, there's
    only one choice which makes sense - coherence should look at the
    underlying type (i.e. the 'defining' type of the impl trait) of the type
    alias, just like we do for non-impl-trait type aliases.
    
    Specifically, impl trait type alises which resolve to a local type
    should be treated like a local type with respect to coherence (e.g.
    impl trait type aliases which resolve to a forieign type should be
    treated as a foreign type, and those that resolve to a local type should
    be treated as a local type).
    
    Since neither inherent impls nor direct trait impl (i.e. `impl MyType`
    or `impl MyTrait for MyType`) are allowd for type aliases, this
    usually does not come up. Before we ever attempt to do coherence
    checking, we will have errored out if an impl trait type alias was used
    directly in an 'impl' clause.
    
    However, during trait selection, we sometimes need to prove bounds like
    'T: Sized' for some type 'T'. If 'T' is an impl trait type alias, this
    requires to know the coherence behavior for impl trait type aliases when
    we perform coherence checking.
    
    Note: Since determining the underlying type of an impl trait type alias
    requires us to perform body type checking, this commit causes us to type
    check some bodies easlier than we otherwise would have. However, since
    this is done through a query, this shouldn't cause any problems
    
    For completeness, I've added an additional test of the coherence-related
    behavior of impl trait type aliases.
    Aaron1011 committed Sep 24, 2019
    Configuration menu
    Copy the full SHA
    33e1dd7 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    61cfe92 View commit details
    Browse the repository at this point in the history