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

suggest one-argument enum variant to fix type mismatch when applicable #43178

Merged
merged 2 commits into from
Jul 19, 2017

Conversation

zackmdavis
Copy link
Member

Following @est31's suggestion.

some_suggestion

Resolves #42764.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@zackmdavis
Copy link
Member Author

I don't know what AppVeyor's problem is.

@codyps
Copy link
Contributor

codyps commented Jul 12, 2017

From the example, it looks like this replaces the function suggestions with the enum constructor. Would it be possible to add the enum constructor as an additional item in the list of suggestions?

@aidanhs aidanhs added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 13, 2017
@zackmdavis
Copy link
Member Author

it looks like this replaces the function suggestions with the enum constructor. Would it be possible to add the enum constructor as an additional item in the list of suggestions?

The behavior is intentional; discussion on the original issue looked unfavorably on the existing suggestions in this situation (at least in the case of Option).

Intuitively, I'd guess that situations that trigger this but where the probe-for-return-type method suggestions would be preferrable are kind of rare? (If you have an x: T where an Option<T> is expected, it's more likely that you meant to write Some(x) than that you meant a method on x that happens to return a Some(T)?—most useful methods on T will return something else.)

Most notably, this will suggest `Some(x)` when the expected type was
an Option<T> but we got an x: T.

Resolves rust-lang#42764.
@zackmdavis
Copy link
Member Author

(rebased on master and forced-pushed in the hopes of removing the spurious "AppVeyor was unable to build" failure indicator)

@codyps
Copy link
Contributor

codyps commented Jul 13, 2017

The behavior is intentional; discussion on the original issue looked unfavorably on the existing suggestions in this situation (at least in the case of Option).

There is an issue opened around what the right way to filter and/or order the suggestions. #42929 . It seems preferable to allow generating the additional suggestion of the enum constructor while we're still in the process of deciding how to order/filter suggestions.

We want the suggested replacement (which IDE tooling and such might offer to
automatically swap in) to, like, actually be correct: suggesting `MyVariant(x)`
when the actual fix is `MyEnum::MyVariant(x)` might be better than nothing, but
Rust is supposed to be the future of computing: we're better than better than
nothing.

As an exceptional case, we excise the prelude path, preferring to suggest
`Some` or `Ok` rather than `std::prelude::v1::Some` and
`std::prelude::v2::Ok`. (It's not worth the effort to future-proof against
hypothetical preludes v2, v3, &c.: we trust our successors to grep—excuse me,
ripgrep—for that.)

Also, don't make this preëmpt the existing probe-for-return-type suggestions,
despite their being looked unfavorably upon, at least in this situation
(rust-lang#42764 (comment)): Cody
Schafer pointed out that that's a separate issue
(rust-lang#43178 (comment)).

This is in the matter of rust-lang#42764.
@zackmdavis
Copy link
Member Author

@jmesmon OK (deleted return statement in 80c603f).

no_return_early_sole_argument_variant

Also 80c603f, made the suggestion use the path to the enum rather than the bare name (which might not be in scope).

@arielb1 arielb1 assigned arielb1 and unassigned pnkfelix Jul 18, 2017
@arielb1
Copy link
Contributor

arielb1 commented Jul 18, 2017

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned arielb1 Jul 18, 2017
@eddyb
Copy link
Member

eddyb commented Jul 19, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Jul 19, 2017

📌 Commit 80c603f has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jul 19, 2017

⌛ Testing commit 80c603f with merge b59d66de6045f11bb7663719c019ea0289be94b2...

@bors
Copy link
Contributor

bors commented Jul 19, 2017

💔 Test failed - status-appveyor

@est31
Copy link
Member

est31 commented Jul 19, 2017

@bors retry -- intermittent network (service) issue

@bors
Copy link
Contributor

bors commented Jul 19, 2017

⌛ Testing commit 80c603f with merge f07dd9ae3be22de126d283ce2e0ca99d68a80cc9...

@bors
Copy link
Contributor

bors commented Jul 19, 2017

💔 Test failed - status-appveyor

@kennytm
Copy link
Member

kennytm commented Jul 19, 2017

Unable to download cmake crate because the SSL revocation server is offline. Spurious.

  [35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - The revocation function was unable to check revocation because the revocation server was offline.)

@est31
Copy link
Member

est31 commented Jul 19, 2017

@kennytm this issue affects all PRs right now. Not sure what the cause of the issue is, but probably either some revocation server is actually down, or there is a networking issue with appveyor that is specific to the revocation servers (generally there seems to be network).

I guess we just wait a bit and hope the issue gets fixed by itself, but smashing the retry button won't be very useful....

cc @oli-obk

@est31
Copy link
Member

est31 commented Jul 19, 2017

lets try whether it persists...

@bors retry

@bors
Copy link
Contributor

bors commented Jul 19, 2017

⌛ Testing commit 80c603f with merge 356d1a7212304f96f686419631256efa4eaea7bd...

@bors
Copy link
Contributor

bors commented Jul 19, 2017

💔 Test failed - status-travis

@est31
Copy link
Member

est31 commented Jul 19, 2017

@bors retry -- sscache network issue and not on appveyor

@bors
Copy link
Contributor

bors commented Jul 19, 2017

⌛ Testing commit 80c603f with merge a7dffd14a21a338a89b87751a1aadfff1cb52094...

@bors
Copy link
Contributor

bors commented Jul 19, 2017

💔 Test failed - status-travis

@nagbot-rs
Copy link

nagbot-rs commented Jul 19, 2017 via email

@bors
Copy link
Contributor

bors commented Jul 19, 2017

@nagbot-rs: 🔑 Insufficient privileges: and not in try users

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Contributor

bors commented Jul 19, 2017

⌛ Testing commit 80c603f with merge 582af6e...

bors added a commit that referenced this pull request Jul 19, 2017
suggest one-argument enum variant to fix type mismatch when applicable

Following @est31's [suggestion](#42764 (comment)).

![some_suggestion](https://user-images.githubusercontent.com/1076988/28101064-ee83f51e-667a-11e7-9e4f-d8f9eb2fb6c3.png)

Resolves #42764.
@bors
Copy link
Contributor

bors commented Jul 19, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 582af6e to master...

@bors bors merged commit 80c603f into rust-lang:master Jul 19, 2017
@zackmdavis zackmdavis deleted the some_suggestion branch January 13, 2018 07:43
zackmdavis added a commit to zackmdavis/rust that referenced this pull request 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 pull request 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.
pietroalbini added a commit to pietroalbini/rust that referenced this pull request 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 pull request 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 pull request 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
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.