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

On type mismatch involving associated type, suggest constraint #71108

Merged
merged 11 commits into from
May 4, 2020

Commits on May 3, 2020

  1. On type mismatch involving associated type, suggest constraint

    When an associated type is found when a specific type was expected, if
    possible provide a structured suggestion constraining the associated
    type in a bound.
    
    ```
    error[E0271]: type mismatch resolving `<T as Foo>::Y == i32`
      --> $DIR/associated-types-multiple-types-one-trait.rs:13:5
       |
    LL |     want_y(t);
       |     ^^^^^^ expected `i32`, found associated type
    ...
    LL | fn want_y<T:Foo<Y=i32>>(t: &T) { }
       |                 ----- required by this bound in `want_y`
       |
       = note:         expected type `i32`
               found associated type `<T as Foo>::Y`
    help: consider constraining the associated type `<T as Foo>::Y` to `i32`
       |
    LL | fn have_x_want_y<T:Foo<X=u32, Y = i32>>(t: &T)
       |                             ^^^^^^^^^
    ```
    
    ```
    error[E0308]: mismatched types
      --> $DIR/trait-with-missing-associated-type-restriction.rs:12:9
       |
    LL |     qux(x.func())
       |         ^^^^^^^^ expected `usize`, found associated type
       |
       = note:         expected type `usize`
               found associated type `<impl Trait as Trait>::A`
    help: consider constraining the associated type `<impl Trait as Trait>::A` to `usize`
       |
    LL | fn foo(x: impl Trait<A = usize>) {
       |                     ^^^^^^^^^^
    ```
    estebank committed May 3, 2020
    Configuration menu
    Copy the full SHA
    3a795fb View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    31b3566 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    ee96b8b View commit details
    Browse the repository at this point in the history
  4. Point at associated types when they have a default type

    Associated types with a default type in a trait can't be relied upon to
    remain of that default type when in use, so literals of that type can't
    be used in the trait's items. Point at the associated type and state
    that information.
    
    Reduce verbosity for associated consts of the wrong type.
    estebank committed May 3, 2020
    Configuration menu
    Copy the full SHA
    299bd12 View commit details
    Browse the repository at this point in the history
  5. fix rebase

    estebank committed May 3, 2020
    Configuration menu
    Copy the full SHA
    6648a08 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    b0085c8 View commit details
    Browse the repository at this point in the history
  7. Add docs

    estebank committed May 3, 2020
    Configuration menu
    Copy the full SHA
    9bb5b54 View commit details
    Browse the repository at this point in the history
  8. trailing newlines

    estebank committed May 3, 2020
    Configuration menu
    Copy the full SHA
    74b7ed7 View commit details
    Browse the repository at this point in the history
  9. fix rebase

    estebank committed May 3, 2020
    Configuration menu
    Copy the full SHA
    de3b4d4 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    3c872e2 View commit details
    Browse the repository at this point in the history

Commits on May 4, 2020

  1. Configuration menu
    Copy the full SHA
    b368229 View commit details
    Browse the repository at this point in the history