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

Point at : when using it instead of ; #43096

Merged
merged 3 commits into from
Jul 23, 2017
Merged

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jul 6, 2017

When triggering type ascription in such a way that we can infer a
statement end was intended, add a suggestion for the change. Always
point out the reason for the expectation of a type is due to type
ascription.

Fix #42057, #41928.

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

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

@bors
Copy link
Contributor

bors commented Jul 7, 2017

☔ The latest upstream changes (presumably #43060) made this pull request unmergeable. Please resolve the merge conflicts.


fn main() {
println!("test"):
0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it work if a colon was here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The output in that case is

error: expected type, found `0`
  --> ../../src/test/ui/suggestions/type-ascription-instead-of-statement-end.rs:15:5
   |
14 |     println!("test"):
   |                     - help: did you mean to use `;` here instead?
15 |     0:
   |     ^ expecting a type here because of type ascription

@shepmaster shepmaster added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 7, 2017
14 | println!("test"):
| -
| |
| help: did you mean to end the statement here instead? `;`
Copy link
Contributor

@nikomatsakis nikomatsakis Jul 7, 2017

Choose a reason for hiding this comment

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

this sort of looks funny, perhaps because of the ^ having no label. I think I'd prefer:

error: expected type, found `0`
  --> $DIR/type-ascription-instead-of-statement-end.rs:15:5
   |
14 |     println!("test"):
   |                     - help: did you mean to use a `;` here?
15 |     0;
   |     ^ expecting a type here because of type ascription

error: aborting due to previous error

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.

@estebank estebank force-pushed the ascription-help branch 2 times, most recently from ad7c8eb to a4217cb Compare July 7, 2017 21:18
--> $DIR/type-ascription-instead-of-statement-end.rs:15:5
|
14 | println!("test"):
| - help: did you mean to end the statement here instead? `;`
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, this looks strange to me somehow. Why not say "help: did you mean to use ; here?"? I think users might not know that "end the statement" means ; -- but also, I am not sure about this "floating" ; that appears at the end of the sentence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The presentation is because it is an inline suggestion. Should I change the code so that we can control wether the code to be replaced should be displayed when inline?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm; I think either change the code, or change the wording. But yeah probably just having the option to "suppress" the suggestion when displayed inline seems good.

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.

@shepmaster
Copy link
Member

This is your polite 7-day ping @estebank — when do you think you'll be able to respond to the comments?

When triggering type ascription in such a way that we can infer a
statement end was intended, add a suggestion for the change. Always
point out the reason for the expectation of a type is due to type
ascription.
@nikomatsakis
Copy link
Contributor

Failure:

[01:08:34] failures:
[01:08:34]     [ui] ui/issue-22644.rs

The new message looks improved, though. =)

Now there's a way to add suggestions that hide the suggested code when
presented inline, to avoid weird wording when short code snippets are
added at the end.
@estebank
Copy link
Contributor Author

@nikomatsakis fixed

@estebank
Copy link
Contributor Author

@nikomatsakis covered another case that fails during resolve instead of parse:

fn f() {}

fn main() {
    f():
    f();
}

@estebank
Copy link
Contributor Author

@nikomatsakis ping

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jul 23, 2017

📌 Commit e39bcec has been approved by nikomatsakis

@nikomatsakis
Copy link
Contributor

cc @oli-obk, I don't this suggestion follows the guidelines, but I also think it looks good. Perhaps we need to adjust the guidelines to account for the "suppress example code" option?

@bors
Copy link
Contributor

bors commented Jul 23, 2017

⌛ Testing commit e39bcec with merge afe145d...

bors added a commit that referenced this pull request Jul 23, 2017
Point at `:` when using it instead of `;`

When triggering type ascription in such a way that we can infer a
statement end was intended, add a suggestion for the change. Always
point out the reason for the expectation of a type is due to type
ascription.

Fix #42057, #41928.
@oli-obk
Copy link
Contributor

oli-obk commented Jul 23, 2017

I'm assuming you mean that the guildelines aren't followed by the use of did you mean. This guideline exists because of #42033 (comment) which notes that the did you mean sounds condescending. I don't have a strong opinion on this guideline though.

"Try using a ; instead:" looks fine to me. Otherwise let's adjust the guidelines if that's desired.

@bors
Copy link
Contributor

bors commented Jul 23, 2017

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

@bors bors merged commit e39bcec into rust-lang:master Jul 23, 2017
@luser
Copy link
Contributor

luser commented Jul 25, 2017

@estebank Thanks for making this error message better!

@Nokel81
Copy link
Contributor

Nokel81 commented Jul 26, 2017

Which error message got finalized?

@estebank
Copy link
Contributor Author

@Nokel81 sorry, I don't understand the question. Could you rephrase? This PR adds a label stating "help: did you mean to use ; here?" when type ascription (triggered by :) ends the previous line to the type error, as it probably was a mistyped :

@Nokel81
Copy link
Contributor

Nokel81 commented Jul 26, 2017

I was talking about the guideline of not using did you mean that was referenced several times near the end of this PR chain. Was the guidelines followed or was the original error message kept as help: did you mean to use ; here instead?

@estebank
Copy link
Contributor Author

@Nokel81 ah, I see. No, I didn't change the message before it got merged. I can post a PR later today/tomorrow changing the wording, if you want.

@Nokel81
Copy link
Contributor

Nokel81 commented Jul 26, 2017

No it is fine, I personally feel that there are some cases where did you mean makes sense. Mostly for small syntactic typos like this. I was just wondering if it had actually been changed

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