Skip to content

trait/struct name conflict error confusingly worded #42061

Closed
@Gankra

Description

@Gankra
trait Foo { }
struct Foo { }

fn main() {}
error[E0428]: a trait named `Foo` has already been defined in this module
 --> <anon>:2:1
  |
1 | trait Foo { }
  | ------------- previous definition of `Foo` here
2 | struct Foo { }
  | ^^^^^^^^^^^^^^ `Foo` already defined

Two things are confusing here:

  • Using "already" here is confusing because it makes you think that the compiler is talking about two conflicting traits, when the conflict is that we're declaring a struct with the same name as a trait.

  • "Foo already defined" looks like it's trying to indicate the place of the first definition, and not the place of the second.

Random recommendation:

  • "Two definitions with the name Foo"
  • Foo redefined here

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions