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 ! for erroneous identifier not #49258

Merged
merged 2 commits into from
Apr 10, 2018

Conversation

zackmdavis
Copy link
Member

not_recovery

This supersedes #48858.

r? @petrochenkov

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 22, 2018
let mut err = self.diagnostic()
.struct_span_err(self.span,
&format!("unexpected {} after identifier",
found.to_string()));
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use format!("unexpected {} after identifier", self.this_token_descr()) here.

// but as `rustc`-the-compiler, we can issue clever diagnostics
// for confused users who really want to say `!`
let token_cannot_continue_expr = |t: &token::Token| match *t {
// These tokens can't continue an expression after an ident
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment nit: Tokens that can start an expression after !, but can't continue an expression after an ident

// for confused users who really want to say `!`
let token_cannot_continue_expr = |t: &token::Token| match *t {
// These tokens can't continue an expression after an ident
token::Ident(..) | token::Literal(..) | token::Pound => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it should be easier now to add the Nt variants from #48858 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, for token::Ident the correct condition is t is Token(ident) && ident_can_begin_expr(ident)

@petrochenkov
Copy link
Contributor

Meta: opening a new PR moves it into the end of @bors queue, it's usually better to rework an original PR, then it will land sooner.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 22, 2018
@shepmaster
Copy link
Member

Ping from triage, @zackmdavis ! It's been a week since we heard from you; will you be able to address the review feedback you've received?

@zackmdavis
Copy link
Member Author

@shepmaster yes, but next week; very busy lately

@zackmdavis
Copy link
Member Author

updated to address feedback, except that I don't know how to write a test example that exercises the nonterminals (and it's more efficient to push this and admit that I don't know if I can't spare the effort to figure it out myself now)

Meta: opening a new PR moves it into the end of @bors queue, it's usually better to rework an original PR, then it will land sooner.

I usually add commits or force-push existing PRs, but in this case, I don't think there are any lines of code in common between the original submission and the post-reviewer-feedback version; semantically, it feels like a "different PR addressing the same issue" rather than "a revision of the same PR". For something nonessential like this, I'm not that interested in jostling for position in the buildbot queue: that's a zero-sum game among outstanding PRs!

@TimNN
Copy link
Contributor

TimNN commented Apr 6, 2018

Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
Resolving deltas: 100% (612068/612068), completed with 4858 local objects.
---
[00:00:41] configure: rust.quiet-tests     := True
---
[00:38:41] ..........................................................................i.........................
[00:38:47] .................i......................................F...........................................
---
[00:39:20] ...............................................................................................i....
[00:39:27] .....................................................................i..............................
---
[00:39:48] ---- [ui] ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs stdout ----
[00:39:48]
[00:39:48] error: /checkout/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs:13: unexpected error: '13:12: 13:19: unexpected `for_you` after identifier'
[00:39:48]
[00:39:48] error: /checkout/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs:21: unexpected error: '21:15: 21:24: unexpected `the_worst` after identifier'
[00:39:48]
[00:39:48] error: /checkout/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs:30: unexpected error: '30:9: 30:16: unexpected `println` after identifier'
[00:39:48]
[00:39:48] error: /checkout/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs:42: unexpected error: '42:27: 42:50: unexpected `be_smothered_out_before` after identifier'
[00:39:48]
[00:39:48] error: /checkout/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs:13: expected error not found: unexpected identifier after identifier
[00:39:48]
[00:39:48] error: /checkout/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs:21: expected error not found: unexpected identifier after identifier
[00:39:48]
[00:39:48] error: /checkout/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs:30: expected error not found: unexpected identifier after identifier
[]         line_num: 30,
[00:39:48]         kind: Some(
[00:39:48]             Error
[00:39:48]         ),
[00:39:48]         msg: "30:9: 30:16: unexpected `println` after identifier"
---
[00:39:48]         msg: "42:27: 42:50: unexpected `be_smothered_out_before` after identifier"
---
[00:39:48]         msg: "unexpected identifier after identifier"
---
[00:39:48]         msg: "unexpected identifier after identifier"
---
[00:39:48]         msg: "unexpected identifier after identifier"
---
[00:39:48]         msg: "unexpected identifier after identifier"
[00:39:48]     }
[00:39:48] ]
[00:39:48]
[00:39:48] thread '[ui] ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:1253:13
[00:39:48] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:39:48]
[00:39:48]
[00:39:48] failures:
[00:39:48]     [ui] ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs
---
[00:39:48] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zmiri -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zmiri -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "alwa3696680 .

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN.

@petrochenkov
Copy link
Contributor

r=me after making Travis green (updating UI tests)

Thanks to the inestimably inimitable Esteban "Estebank" Küber for
pointing this out.

This is relevant to rust-lang#46836.
Impressing confused Python users with magical diagnostics is perhaps
worth this not-grossly-unreasonable (only 40ish lines) extra complexity
in the parser?

Thanks to Vadim Petrochenkov for guidance.

This resolves rust-lang#46836.
@zackmdavis
Copy link
Member Author

(I wish the check for //~-expected errors ran anyway even if the stderr file didn't match; it's too easy to update the latter and forget about the former.)

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Apr 9, 2018

📌 Commit ba0dd8e has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 9, 2018
@bors
Copy link
Contributor

bors commented Apr 9, 2018

⌛ Testing commit ba0dd8e with merge 6f0cad9687f69e5dbb3a643515a419997bc50912...

@bors
Copy link
Contributor

bors commented Apr 9, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 9, 2018
@zackmdavis
Copy link
Member Author

@petrochenkov
Copy link
Contributor

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 10, 2018
@bors
Copy link
Contributor

bors commented Apr 10, 2018

⌛ Testing commit ba0dd8e with merge 5d7f892...

@bors
Copy link
Contributor

bors commented Apr 10, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 5d7f892 to master...

@bors bors merged commit ba0dd8e into rust-lang:master Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants