Skip to content

Clarify that function items defined by struct and such are constructors for these types #106516

Closed
@nagisa

Description

@nagisa

Noticed this while reviewing. Code as such:

struct Foo(());

fn banana() -> Foo { Foo }

results in the following diagnostic:

1 | struct Foo(());
  | ---------- fn(()) -> Foo {Foo} defined here
2 |
3 | fn banana() -> Foo { Foo }
  |                ---   ^^^ expected struct `Foo`, found fn item
  |                |
  |                expected `Foo` because of return type
  |
  = note: expected struct `Foo`
            found fn item `fn(()) -> Foo {Foo}`

it isn’t particularly obvious what is the relation between struct and a function definition. Instead the span could say something like:

1 | struct Foo(());
  | ---------- also defines a constructor function `fn(()) -> Foo {Foo}`

or somesuch.

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions