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 Ok(()) when encountering Result::<(), E>::Ok() #44059

Merged
merged 1 commit into from
Aug 29, 2017

Conversation

oli-obk
Copy link
Contributor

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

No description provided.

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

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

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

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

sugg_span.hi = sugg_span.lo;
err.span_suggestion(
sugg_span,
"expected one unit argument. try creating a new unit value",
Copy link
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
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
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
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
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
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

@@ -2423,7 +2423,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {

fn parameter_count_error<'tcx>(sess: &Session, sp: Span, expected_count: usize,
arg_count: usize, error_code: &str, variadic: bool,
def_span: Option<Span>) {
def_span: Option<Span>, sugg: Option<String>) {
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

done

| ---------------- defined here
...
18 | bar();
| ^^^^^ expected 1 parameter
Copy link
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
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
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
Contributor

Seems good to me now.

@bors r+

@bors
Copy link
Contributor

bors commented Aug 28, 2017

📌 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
Member

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
Copy link
Contributor

bors commented Aug 29, 2017

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

@bors
Copy link
Contributor

bors commented Aug 29, 2017

☀️ 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