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

Want better error for impl<some generics> impl Trait for Type {...} #109963

Closed
ijackson opened this issue Apr 5, 2023 · 0 comments · Fixed by #111477
Closed

Want better error for impl<some generics> impl Trait for Type {...} #109963

ijackson opened this issue Apr 5, 2023 · 0 comments · Fixed by #111477
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ijackson
Copy link
Contributor

ijackson commented Apr 5, 2023

Code

use std::panic::UnwindSafe;

struct S<T>(T);

impl<T: UnwindSafe> impl UnwindSafe for T {}

// We're using UnwindSafe as an example trait

Current output

error: expected a trait, found type
 --> src/lib.rs:5:21
  |
5 | impl<T: UnwindSafe> impl UnwindSafe for T {}
  |                     ^^^^^^^^^^^^^^^

Desired output

error: expected a trait, found type
 --> src/lib.rs:5:21
  |
5 | impl<T: UnwindSafe> impl UnwindSafe for T {}
  |                     ^^^^^^^^^^^^^^^

 --> src/lib.rs:5:21
  |
5 | impl<T: UnwindSafe> impl UnwindSafe for T {}
  | ^^^^                ^^^^
note: second occurrence of keyword `impl` is probably a mistake

Rationale and extra context

I made this mistake and didn't spot that the ^^^^ were pointing at the whole of impl Trait rather than just Trait and spent several minutes thinking "but Trait is a trait!".

Probably my "desired output" could be improved. Maybe replacing rather than supplementing the "expected trait, not type" would be better.

Other cases

No response

Anything else?

No response

@ijackson ijackson added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 5, 2023
@Noratrieb Noratrieb added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 5, 2023
@bors bors closed this as completed in d7f7425 May 14, 2023
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-enhancement Category: An issue proposing an enhancement or a PR with one. 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