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

Implement impl Trait in argument position (RFC1951, Universal quantification) #45918

Merged
merged 28 commits into from
Nov 16, 2017

Commits on Nov 15, 2017

  1. Move E0562 to librustc from librustc_typeck

    With the check for impl trait moving from type checking to HIR lowering
    the error needs to move too.
    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    779fc37 View commit details
    Browse the repository at this point in the history
  2. Split hir::TyImplTrait, move checks to HIR lowering

    Replace hir::TyImplTrait with TyImplTraitUniversal and
    TyImplTraitExistential.
    
    Add an ImplTraitContext enum to rustc::hir::lowering to track the kind
    and allowedness of an impl Trait.
    
    Significantly alter lowering to thread ImplTraitContext and one other
    boolean parameter described below throughought much of lowering.
    
    The other parameter is for tracking if lowering a function is in a trait
    impl, as there is not enough information to otherwise know this
    information during lowering otherwise.
    
    This change also removes the checks from ast_ty_to_ty for impl trait
    allowedness as they are now all taking place in HIR lowering.
    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    8fd48e7 View commit details
    Browse the repository at this point in the history
  3. Add bool item is_in_impl_trait to LoweringContext

    This is for tracking if an ImplItem is part of a trait impl. Add
    a with_trait_impl_ref method to ItemLowerer to appropriately save the
    state to allow appropriate nesting of trait and non-trait impls.
    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    e4c7e2c View commit details
    Browse the repository at this point in the history
  4. Alter type collection to collect impl Trait bounds

    In ast_generics extraction in generics_of and explicit_predicates_of,
    also collect inputs if there are any.
    
    Then use a Visitor to extract the necessary information from the
    TyImplTraitUniversal types before extending generics and predicates with
    the new information.
    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    94df3c5 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    f225fe4 View commit details
    Browse the repository at this point in the history
  6. Add new error comparision to hide desugaring

    First some background:
    To the compiler, the following two signatures in the trait vs the impl
    are the same.
    
    ```rust
    trait Foo {
        fn foo(&self, &impl Debug);
    }
    impl Foo for () {
        fn foo<U: Debug>(&self, x: &U) { ... }
    }
    ```
    
    We do not want to allow this, and so we add a new error and check.
    
    The check just tests that all paramters 'syntheticness' match up. As
    during collection, the impl Trait parameters are transformed into
    anonymous synthetic generics.
    
    Furthermore, causes a check for unused type parameters to be skipped in
    check_bounds_are_used if there is already a TyError. Thus, an unused
    input will not trigger `type parameter unused` errors.
    
    Update the one test that checked for this error in the case of
    a TyError.
    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    109f2dd View commit details
    Browse the repository at this point in the history
  7. Add universal_impl_trait feature gate

    Move feature gate check to inside HIR lowering. Change error messages
    and update tests.
    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    bdff946 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    06dff80 View commit details
    Browse the repository at this point in the history
  9. Fix style and grammar

    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    a23bea5 View commit details
    Browse the repository at this point in the history
  10. Remove unamed parameters

    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    7d25d2e View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    04ad8fd View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    b4c1aef View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    2520279 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    ebc4408 View commit details
    Browse the repository at this point in the history
  15. extend where-allowed.rs with many more cases

    also merge disallowed and disallowed-2 into that set
    nikomatsakis authored and chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    37dd79f View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    6f9fb91 View commit details
    Browse the repository at this point in the history
  17. add some more positive tests

    It'd be good to have a positive test for each case where it is
    allowed, I should think.
    nikomatsakis authored and chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    9d71bf6 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    15001ee View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    2786ea6 View commit details
    Browse the repository at this point in the history
  20. Add proper names to impl Trait parameters.

    Uses Symbol::intern and hir.node_to_pretty_string to create a name for
    the impl Trait parameter that is just impl and then a ' + ' separated
    list of bounds that the user typed.
    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    7e9948f View commit details
    Browse the repository at this point in the history
  21. Incorporate review feedback

    Add requested comments, restructure some small bits of code. Fix extern
    declarations allowing impl Trait.
    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    9b4372e View commit details
    Browse the repository at this point in the history
  22. Disallow all impl Trait within Fn trait sugar

    We already disallowed them to be in the arg list, such as
    Fn(impl Debug), but now we disallow Fn() -> impl Debug.
    
    Also remove the ImplTraitContext argument from the function
    lower_parenthesized_parameter_data as it is now unused.
    
    Comment out part of test run-pass/impl-trait/xcrate.rs that now fails.
    chrisvittal committed Nov 15, 2017
    Configuration menu
    Copy the full SHA
    b276429 View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    f710d41 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    22f0940 View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    517db79 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    337dee4 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    98d5db3 View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    4ce61b7 View commit details
    Browse the repository at this point in the history