Skip to content

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

Closed
@ijackson

Description

@ijackson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions