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

Extraneous comma in trait bound suggestion #72693

Closed
jplatte opened this issue May 28, 2020 · 0 comments · Fixed by #72715
Closed

Extraneous comma in trait bound suggestion #72693

jplatte opened this issue May 28, 2020 · 0 comments · Fixed by #72715
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jplatte
Copy link
Contributor

jplatte commented May 28, 2020

The following code (Playground):

trait T1 {
    type A;
}

trait T2: T1
where
    Self::A: Clone,
{
}

fn generic<T: T2>()
where
    u8: Copy,
{
}

Produces an invalid suggestion:

error[E0277]: the trait bound `<T as T1>::A: std::clone::Clone` is not satisfied
  --> src/lib.rs:11:15
   |
5  | trait T2: T1
   |       -- required by a bound in this
6  | where
7  |     Self::A: Clone,
   |              ----- required by this bound in `T2`
...
11 | fn generic<T: T2>()
   |               ^^ the trait `std::clone::Clone` is not implemented for `<T as T1>::A`
   |
help: consider further restricting the associated type
   |
13 |     u8: Copy,, <T as T1>::A: std::clone::Clone
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

on nightly. On stable, the error message looks a bit different but seems to also be suggesting an extra comma.

When trying to reduce this test case I found that in other cases this same lint seems to suggest the right thing (this may be useful as an additional test case):

#[derive(Clone)]
struct Generic<T>(T);

fn generic<T>() -> impl Clone
where
    Generic<T>: Default,
{
    Generic::<T>::default()
}

correct suggestion (nightly):

Standard Error

   Compiling playground v0.0.1 (/playground)

error[E0277]: the trait bound `T: std::clone::Clone` is not satisfied
 --> src/lib.rs:4:20
  |
4 | fn generic<T>() -> impl Clone
  |                    ^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `T`
...
8 |     Generic::<T>::default()
  |     ----------------------- this returned value is of type `Generic<T>`
  |
  = note: required because of the requirements on the impl of `std::clone::Clone` for `Generic<T>`
  = note: the return type of a function must have a statically known size
help: consider further restricting type parameter `T`
  |
6 |     Generic<T>: Default, T: std::clone::Clone
  |                        ^^^^^^^^^^^^^^^^^^^^^^
@jplatte jplatte added the C-bug Category: This is a bug. label May 28, 2020
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 28, 2020
@estebank estebank self-assigned this May 28, 2020
RalfJung added a commit to RalfJung/rust that referenced this issue May 31, 2020
…trochenkov

Account for trailing comma when suggesting `where` clauses

Fix rust-lang#72693.
RalfJung added a commit to RalfJung/rust that referenced this issue May 31, 2020
…trochenkov

Account for trailing comma when suggesting `where` clauses

Fix rust-lang#72693.
@bors bors closed this as completed in 0424371 May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants