• B
    Auto merge of #38920 - petrochenkov:selfimpl, r=eddyb · df8debf6
    bors 提交于
    Partially implement RFC 1647 (`Self` in impl headers)
    
    The name resolution part is easy, but the typeck part contains an unexpected problem.
    
    It turns out that `Self` type *depends* on bounds and `where` clauses, so we need to convert them first to determine what the `Self` type is! If bounds/`where` clauses can refer to `Self` then we have a cyclic dependency.
    This is required to support impls like this:
    ```
    // Found in libcollections
    impl<I: IntoIterator> SpecExtend<I> for LinkedList<I::Item> { .... }
                                                          ^^^^^ associated type `Item` is found using information from bounds
    
    ```
    I'm not yet sure how to resolve this issue.
    One possible solution (that feels hacky) is to make two passes over generics - first collect predicates ignoring everything involving `Self`, then determine `Self`, then collect predicates again without ignoring anything. (Some kind of lazy on-demand checking or something looks like a proper solution.)
    
    This patch in its current state doesn't solve the problem with `Self` in bounds, so the only observable things it does is improving error messages and supporting `impl Trait<Self> for Type {}`.
    
    There's also a question about feature gating. It's non-trivial to *detect* "newly resolved" `Self`s to feature gate them, but it's simple to *enable* the new resolution behavior when the feature gate is already specified. Alternatively this can be considered a bug fix and merged without a feature gate.
    
    cc https://github.com/rust-lang/rust/issues/38864
    r? @nikomatsakis
    cc @EddyB
    Whitespace ignoring diff https://github.com/rust-lang/rust/pull/38920/files?w=1
    df8debf6
lib.rs 135.2 KB