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

Help for missing trait method suggests unstable code #98562

Closed
Cerber-Ursi opened this issue Jun 27, 2022 · 0 comments · Fixed by #112123
Closed

Help for missing trait method suggests unstable code #98562

Cerber-Ursi opened this issue Jun 27, 2022 · 0 comments · Fixed by #112123
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Cerber-Ursi
Copy link
Contributor

Cerber-Ursi commented Jun 27, 2022

I tried this code:

use core::iter::Sum;

struct Summer;

impl Sum<i32> for Summer {
}

Playground

I expected to see this happen: an error which either just shows the error itself or the compilable sugestion for change.

Instead, this happened: the error is like following:

error[E0046]: not all trait items implemented, missing: `sum`
 --> src/lib.rs:5:1
  |
5 | impl Sum<i32> for Summer {
  | ^^^^^^^^^^^^^^^^^^^^^^^^ missing `sum` in implementation
  |
  = help: implement the missing item: `fn sum<I>(_: I) -> Self where I: Iterator, std::iter::Iterator::Item = A { todo!() }`

Now, if I add the code from the help block into the trait, I'll get another error:

error: equality constraints are not yet supported in `where` clauses
 --> src/lib.rs:6:44
  |
6 | fn sum<I>(_: I) -> Self where I: Iterator, std::iter::Iterator::Item = A { todo!() }
  |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not supported
  |
  = note: [see issue #20041 <https://github.com/rust-lang/rust/issues/20041>](https://github.com/rust-lang/rust/issues/20041) for more information

error[E0412]: cannot find type `A` in this scope
 --> src/lib.rs:6:72
  |
6 | fn sum<I>(_: I) -> Self where I: Iterator, std::iter::Iterator::Item = A { todo!() }
  |        - similarly named type parameter `I` defined here               ^ help: a type parameter with a similar name exists: `I`

The first one is the one I'm worried about, since it shows that the suggest was using a nightly-only feature on stable.

Noting also that rust-analyzer seems to do this correctly - it creates an intention to insert fn sum<I: Iterator<Item = i32>>(_: I) { todo!(); }, which compiles immediately.

@Cerber-Ursi Cerber-Ursi added the C-bug Category: This is a bug. label Jun 27, 2022
@TaKO8Ki TaKO8Ki added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 28, 2022
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 28, 2023
fix(suggestion): insert projection to associated types

Fixes rust-lang#98562

This PR has fixed some help suggestions for unsupported syntax, such as `fn f<T>(_:T) where T: IntoIterator, std::iter::IntoIterator::Item = () {}` to `fn f<T: IntoIterator<Item = ()>>(_T) {}`.
@bors bors closed this as completed in 4a88646 Sep 29, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 29, 2023
Rollup merge of rust-lang#112123 - bvanjoi:fix-98562, r=compiler-errors

fix(suggestion): insert projection to associated types

Fixes rust-lang#98562

This PR has fixed some help suggestions for unsupported syntax, such as `fn f<T>(_:T) where T: IntoIterator, std::iter::IntoIterator::Item = () {}` to `fn f<T: IntoIterator<Item = ()>>(_T) {}`.
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 C-bug Category: This is a bug. 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.

3 participants