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

When given an enum E and expecting a struct S, rustc suggests using "a variant" of S. #55250

Closed
pnkfelix opened this issue Oct 21, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@pnkfelix
Copy link
Member

Consider the following code (play):

enum E { Var1, Var2, }

struct S { base: E, }

struct Context { s: S, }

fn main() { let _c = Context { s: E::Var1 }; }

It currently yields the following diagnostic messages:

error[E0308]: mismatched types
 --> src/main.rs:7:35
  |
7 | fn main() { let _c = Context { s: E::Var1 }; }
  |                                   ^^^^^^^
  |                                   |
  |                                   expected struct `S`, found enum `E`
  |                                   help: try using a variant of the expected type: `S(E::Var1)`
  |
  = note: expected type `S`
             found type `E`

This line is what I object to:

  |                                   help: try using a variant of the expected type: `S(E::Var1)`

It has two problems:

  1. It uses the terminology variant when discussing building up an instance of the struct S.
  2. It uses a tuple struct form in the example rewrite it provides; but our S is a braced struct with named fields.
@pnkfelix pnkfelix added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 21, 2018
zackmdavis added a commit to zackmdavis/rust that referenced this issue Oct 21, 2018
Felix S. Klock II pointed out that this suggestion (introduced in
pull-request rust-lang#43178 / eac7410) was being issued for one-field-struct
expected types (in which case it is misleading and outright wrong),
even though it was only intended for one-field enum-variants (most
notably, `Some`). Particularly tender-hearted code-historians may be
inclined to show mercy towards the author of rust-lang#43178 on the grounds
that it's somewhat confusing that struct field definitions are given
in a type called `ty::VariantDef`.

Add a conditional to adhere to the original intent. (It would be
possible to generalize to structs, but not obviously net desirable.)
This adds a level of indentation, so the diff here is going to be
easier to read in ignore-whitespace mode (`-w`).

Resolves rust-lang#55250.
zackmdavis added a commit to zackmdavis/rust that referenced this issue Oct 21, 2018
Felix S. Klock II pointed out that this suggestion (introduced in
pull-request rust-lang#43178 / eac7410) was being issued for one-field-struct
expected types (in which case it is misleading and outright wrong),
even though it was only intended for one-field enum-variants (most
notably, `Some`). Particularly tender-hearted code-historians may be
inclined to show mercy towards the author of rust-lang#43178 on the grounds
that it's somewhat confusing that struct field definitions are given
in a type called `ty::VariantDef`.

Add a conditional to adhere to the original intent. (It would be
possible to generalize to structs, but not obviously net desirable.)
This adds a level of indentation, so the diff here is going to be
easier to read in ignore-whitespace mode (`-w`).

Resolves rust-lang#55250.
@zackmdavis
Copy link
Member

Is GitHub suffering from some kind of cache-consistency problem!? (I guess so: status.github.com now says they're investigating service unavailability.) I apparently-successfully opened PR #55253 to fix this, but then it wasn't showing up in the PR list and the pull/55253 URL was 404ing, so then I thought that it might not have actually gone through, so then I tried to resubmit, and then that failed with an "A pull request already exists" flash message, and then I wanted to try submitting under a different branch name, and/or rebased so as to have a different SHA (on the theory that maybe the problem had something to do with the fact that I was reusing the branch name from the my PR of last year in which the "variant of the expected type" message was introduced, even though it would be really surprising if a site as old and usually-stable as GitHub didn't already handle that case), but then the "Compare branches" pages aren't showing the open-pull-request form that they usually do.

Typically I wouldn't even bother commenting about this kind of glitch (trusting that our friends at GitHub will sort it out any mere availability issue soon enough), but the fact that other PR pages are loading fine for me makes me wonder if there's some kind of bad state associated with #55253 in particular?!

1 similar comment
@zackmdavis
Copy link
Member

Is GitHub suffering from some kind of cache-consistency problem!? (I guess so: status.github.com now says they're investigating service unavailability.) I apparently-successfully opened PR #55253 to fix this, but then it wasn't showing up in the PR list and the pull/55253 URL was 404ing, so then I thought that it might not have actually gone through, so then I tried to resubmit, and then that failed with an "A pull request already exists" flash message, and then I wanted to try submitting under a different branch name, and/or rebased so as to have a different SHA (on the theory that maybe the problem had something to do with the fact that I was reusing the branch name from the my PR of last year in which the "variant of the expected type" message was introduced, even though it would be really surprising if a site as old and usually-stable as GitHub didn't already handle that case), but then the "Compare branches" pages aren't showing the open-pull-request form that they usually do.

Typically I wouldn't even bother commenting about this kind of glitch (trusting that our friends at GitHub will sort it out any mere availability issue soon enough), but the fact that other PR pages are loading fine for me makes me wonder if there's some kind of bad state associated with #55253 in particular?!

pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 23, 2018
only issue "variant of the expected type" suggestion for enums

This suggestion (introduced in pull-request rust-lang#43178 / eac7410) was being issued for one-field-struct expected types (in which case it is misleading and outright wrong), even though it was only intended for one-field enum-variants (most notably, `Some`).

Add a conditional to adhere to the original intent. (It would be possible to generalize to structs, but not obviously net desirable.) This adds a level of indentation, so the diff here is going to be
easier to read in [ignore-whitespace mode](rust-lang@b0d3d3b9?w=1).

Resolves rust-lang#55250.

r? @pnkfelix
kennytm added a commit to kennytm/rust that referenced this issue Oct 24, 2018
only issue "variant of the expected type" suggestion for enums

This suggestion (introduced in pull-request rust-lang#43178 / eac7410) was being issued for one-field-struct expected types (in which case it is misleading and outright wrong), even though it was only intended for one-field enum-variants (most notably, `Some`).

Add a conditional to adhere to the original intent. (It would be possible to generalize to structs, but not obviously net desirable.) This adds a level of indentation, so the diff here is going to be
easier to read in [ignore-whitespace mode](rust-lang@b0d3d3b9?w=1).

Resolves rust-lang#55250.

r? @pnkfelix
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 25, 2018
only issue "variant of the expected type" suggestion for enums

This suggestion (introduced in pull-request rust-lang#43178 / eac7410) was being issued for one-field-struct expected types (in which case it is misleading and outright wrong), even though it was only intended for one-field enum-variants (most notably, `Some`).

Add a conditional to adhere to the original intent. (It would be possible to generalize to structs, but not obviously net desirable.) This adds a level of indentation, so the diff here is going to be
easier to read in [ignore-whitespace mode](rust-lang@b0d3d3b9?w=1).

Resolves rust-lang#55250.

r? @pnkfelix
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
Projects
None yet
Development

No branches or pull requests

2 participants