Skip to content

Suggest Ok(()) when encountering Result::<(), E>::Ok() - #44059

Merged
bors merged 1 commit into
rust-lang:masterfrom
oli-obk:ok_suggestion
Aug 29, 2017
Merged

bors merged 1 commit into
rust-lang:masterfrom
oli-obk:ok_suggestion

Conversation

@oli-obk

@oli-obk oli-obk commented Aug 23, 2017

Copy link
Copy Markdown
Contributor

No description provided.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @nikomatsakis

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

@nikomatsakis nikomatsakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice. I left a few thoughts -- I think we could use to iterate once or twice on the exact message.

cc @estebank @jonathandturner

Comment thread src/librustc_typeck/check/mod.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a cute trick; is unit the terminology we are using here? somehow this message feels a bit "jargon-y" to me, but I'm not sure how to say it better.

cc @rust-lang/docs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe word it like E0178?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confess, this message was also designed to trigger the 10 word limit for suggestions, otherwise you'd get "try creating a new unit value: ()", which really doesn't help the target audience.

I will reword it in a shorter manner and add a way to exempt this suggestion from being shortened to a label

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about?

help: expected the unit value `()`; try to insert one more pair of parenthesis?
   |
15 |     let _: Result<(), String> = Ok(());
   |                                    ^^ 

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this one better, but the ; looks out of place.

maybe like this?

help: expected a unit value. Try to insert one more pair of parenthesis?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the message

Comment thread src/librustc_typeck/check/mod.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you add a comment to this method and explain what some of the arguments are? Or perhaps just give this a clearer name, like suggest_unit_argument? (In that case, why not make it a bool?)

Alternatively, we could make this more general, but right now the added labels only make sense with ().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be suggesting as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea. I haven't figured out yet what's going on...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@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 Aug 23, 2017
@nikomatsakis

Copy link
Copy Markdown
Contributor

Seems good to me now.

@bors r+

@bors

bors commented Aug 28, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 0b72497 has been approved by nikomatsakis

sugg_span.hi = sugg_span.lo;
err.span_suggestion(
sugg_span,
"expected the unit value `()`. You can create one with a pair of parenthesis",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pair of parentheses, plural

bors added a commit that referenced this pull request Aug 29, 2017
Suggest `Ok(())` when encountering `Result::<(), E>::Ok()`
@bors

bors commented Aug 29, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 0b72497 with merge 6f82dea...

@bors

bors commented Aug 29, 2017

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 6f82dea to master...

@bors
bors merged commit 0b72497 into rust-lang:master Aug 29, 2017
@oli-obk
oli-obk deleted the ok_suggestion branch June 15, 2020 15:26
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.

9 participants