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

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

Closed
nagisa opened this issue Jan 5, 2023 · 0 comments · Fixed by #106524
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks.

Comments

@nagisa
Copy link
Member

nagisa commented Jan 5, 2023

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.

@nagisa nagisa added A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. labels Jan 5, 2023
@compiler-errors compiler-errors self-assigned this Jan 6, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 12, 2023
…r=cjgillot

Label `struct/enum constructor` instead of `fn item`, mention that it should be called on type mismatch

Fixes rust-lang#106516
@bors bors closed this as completed in d711394 Jan 12, 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 D-papercut Diagnostics: An error or lint that needs small tweaks.
Projects
None yet
2 participants