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

Account for non-overlapping unmet trait bounds in suggestion #120507

Merged
merged 4 commits into from
Feb 7, 2024

Commits on Jan 30, 2024

  1. Configuration menu
    Copy the full SHA
    d34b0fa View commit details
    Browse the repository at this point in the history
  2. Account for unbounded type param receiver in suggestions

    When encountering
    
    ```rust
    fn f<T>(a: T, b: T) -> std::cmp::Ordering {
        a.cmp(&b) //~ ERROR E0599
    }
    ```
    
    output
    
    ```
    error[E0599]: no method named `cmp` found for type parameter `T` in the current scope
      --> $DIR/method-on-unbounded-type-param.rs:2:7
       |
    LL | fn f<T>(a: T, b: T) -> std::cmp::Ordering {
       |      - method `cmp` not found for this type parameter
    LL |     a.cmp(&b)
       |       ^^^ method cannot be called on `T` due to unsatisfied trait bounds
       |
       = help: items from traits can only be used if the type parameter is bounded by the trait
    help: the following traits define an item `cmp`, perhaps you need to restrict type parameter `T` with one of them:
       |
    LL | fn f<T: Ord>(a: T, b: T) -> std::cmp::Ordering {
       |       +++++
    LL | fn f<T: Iterator>(a: T, b: T) -> std::cmp::Ordering {
       |       ++++++++++
    ```
    
    Fix rust-lang#120186.
    estebank committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    20b1c2a View commit details
    Browse the repository at this point in the history
  3. fix rebase

    estebank committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    9ccc770 View commit details
    Browse the repository at this point in the history
  4. Account for non-overlapping unmet trait bounds in suggestion

    When a method not found on a type parameter could have been provided by any
    of multiple traits, suggest each trait individually, instead of a single
    suggestion to restrict the type parameter with *all* of them.
    
    Before:
    
    ```
    error[E0599]: the method `cmp` exists for reference `&T`, but its trait bounds were not satisfied
      --> $DIR/method-on-unbounded-type-param.rs:5:10
       |
    LL |     (&a).cmp(&b)
       |          ^^^ method cannot be called on `&T` due to unsatisfied trait bounds
       |
       = note: the following trait bounds were not satisfied:
               `T: Ord`
               which is required by `&T: Ord`
               `&T: Iterator`
               which is required by `&mut &T: Iterator`
               `T: Iterator`
               which is required by `&mut T: Iterator`
    help: consider restricting the type parameters to satisfy the trait bounds
       |
    LL | fn g<T>(a: T, b: T) -> std::cmp::Ordering where T: Iterator, T: Ord {
       |                                           +++++++++++++++++++++++++
    ```
    
    After:
    
    ```
    error[E0599]: the method `cmp` exists for reference `&T`, but its trait bounds were not satisfied
      --> $DIR/method-on-unbounded-type-param.rs:5:10
       |
    LL |     (&a).cmp(&b)
       |          ^^^ method cannot be called on `&T` due to unsatisfied trait bounds
       |
       = note: the following trait bounds were not satisfied:
               `T: Ord`
               which is required by `&T: Ord`
               `&T: Iterator`
               which is required by `&mut &T: Iterator`
               `T: Iterator`
               which is required by `&mut T: Iterator`
       = help: items from traits can only be used if the type parameter is bounded by the trait
    help: the following traits define an item `cmp`, perhaps you need to restrict type parameter `T` with one of them:
       |
    LL | fn g<T: Ord>(a: T, b: T) -> std::cmp::Ordering {
       |       +++++
    LL | fn g<T: Iterator>(a: T, b: T) -> std::cmp::Ordering {
       |       ++++++++++
    ```
    
    Fix rust-lang#108428.
    estebank committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    5c41409 View commit details
    Browse the repository at this point in the history