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

Improve parsing diagnostic for negative supertrait bounds #57364

Merged
merged 1 commit into from
Feb 24, 2019
Merged

Improve parsing diagnostic for negative supertrait bounds #57364

merged 1 commit into from
Feb 24, 2019

Conversation

hdhoang
Copy link
Contributor

@hdhoang hdhoang commented Jan 6, 2019

closes #33418

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 6, 2019
src/libsyntax/ast.rs Outdated Show resolved Hide resolved
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). 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.
travis_time:end:0ec3f578:start=1546782125819050653,finish=1546782196239804965,duration=70420754312
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[01:00:27] .................................................................................................... 3500/5299
[01:00:31] .................................................................................................... 3600/5299
[01:00:34] ......................................ii............................................................ 3700/5299
[01:00:36] .........................................................i.......................................... 3800/5299
[01:00:37] .........................................F.......................................................... 3900/5299
[01:00:42] .................................................................................................... 4100/5299
[01:00:52] .................................................................................................... 4200/5299
[01:00:55] .................................................................................................... 4300/5299
[01:00:59] .................................................................................................... 4400/5299
[01:00:59] .................................................................................................... 4400/5299
[01:01:02] ........................................................i........................................... 4500/5299
[01:01:08] .................................................................................................... 4600/5299
[01:01:12] .................................................................................................... 4700/5299
[01:01:15] .................................................................................................... 4800/5299
[01:01:19] .................................................................................................... 4900/5299
[01:01:22] .................................................................................................... 5000/5299
[01:01:31] - LL | trait Tr4: !Sized + !Send + Copy + !Sync + !Unpin {} //~ ERROR negative trait bounds are not supported
[01:01:31] -    |                                  --^^^^^
[01:01:31] + LL | trait Tr4: !Sized + Copy + !Sync + !Unpin {} //~ ERROR negative trait bounds are not supported
[01:01:31] +    |                                  --^^^^^^
[01:01:31] 47    |                                  help: remove this trait bound
[01:01:31] 48 
[01:01:31] 
[01:01:31] 49 error: negative trait bounds are not supported
[01:01:31] 49 error: negative trait bounds are not supported
[01:01:31] -   --> $DIR/issue-33418.rs:6:44
[01:01:31] -    |
[01:01:31] - LL | trait Tr4: !Sized + !Send + Copy + !Sync + !Unpin {} //~ ERROR negative trait bounds are not supported
[01:01:31] -    |                                          --^^^^^^
[01:01:31] -    |                                          help: remove this trait bound
[01:01:31] - 
[01:01:31] - error: negative trait bounds are not supported
[01:01:31] 58   --> $DIR/issue-33418.rs:7:12
[01:01:31] 58   --> $DIR/issue-33418.rs:7:12
[01:01:31] 59    |
[01:01:31] 60 LL | trait Tr5: !Sized + !Send {} //~ ERROR negative trait bounds are not supported
[01:01:31] 70    |                   |
[01:01:31] 71    |                   help: remove this trait bound
[01:01:31] 72 
[01:01:31] - error: aborting due to 9 previous errors
---
[01:01:31] 
[01:01:31] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:495:22
[01:01:31] 
[01:01:31] 
[01:01:31] 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-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -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" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/travis_time:end:2a9fb0c4:start=1546782205172551672,finish=1546785897059313420,duration=3691886761748
travis_time:start:03060326
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sun Jan  6 14:44:57 UTC 2019
Sun, 06 Jan 2019 14:44:57 GMT

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. (Feature Requests)

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

It seems like the tests are currently broken. Added an alternative way of getting the suggestion span.

src/libsyntax/parse/parser.rs Show resolved Hide resolved
src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
@estebank estebank 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 Jan 7, 2019
@stokhos
Copy link

stokhos commented Jan 14, 2019

Ping from triage @hdhoang Have you been able to make any progress on this?

@hdhoang
Copy link
Contributor Author

hdhoang commented Jan 14, 2019

thank you, I have a rough outline of the necessary flow inside the loop. I will describe most of it later while working it out locally.

@hdhoang
Copy link
Contributor Author

hdhoang commented Jan 14, 2019

I have pushed a WIP flow for review.

Firstly, I have renamed the supertraits in tests to make talking about them easier.

On to the parser, to pass the colon span into the loop, I have added a colon_span argument to parse_generic_bounds/parse_generic_bounds_common, then passing DUMMY_SP at irrelevant callsites. The name isn't descriptive, but hopefully using a dummy span elsewhere makes it clear.

Next, I have implemented your last_plus_span flow, and created a flag to track whether we need to promote a plus to a colon to keep the code valid. I temporarily used struct_span_err here, but I think a warning/note/help message hanging on to last_plus_span is more appropriate. I will find a more suitable macro for that, and a clearer message for "will become the first one".

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

The output looks superb.

I think that we can iterate on the changes to parse_generic_bounds_common, as you're using a DUMMY_SP in some cases. I think that replacing that with None would be safer, and just avoid giving any suggestion if colon_span isn't Some(sp), just a help line similar to what we have now.

You can see how I handled a similar suggestion case in 28ea03e, but that one was more self contained.

src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
@hdhoang
Copy link
Contributor Author

hdhoang commented Jan 16, 2019

thanks! I intend to update this weekend, and see how it goes

@hdhoang
Copy link
Contributor Author

hdhoang commented Jan 19, 2019

hopefully I have addressed your review correctly. I have also downgraded the colon suggestion to a warning, since it's due to rustfix, not the original code

@hdhoang
Copy link
Contributor Author

hdhoang commented Jan 23, 2019

ping @estebank, have you had a chance chance to look at this?

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

Apologies for the delay. Some suggestions inline. Let me know what you think.

src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
"".into(),
Applicability::MachineApplicable);
} else {
err.help("remove this trait bound");
Copy link
Contributor

Choose a reason for hiding this comment

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

If the other comment is implemented, this is the branch where you would have to account for the trailing + span instead, and suggest the removal of it, instead of in the warning.

src/test/ui/parser/issue-33418.stderr Outdated Show resolved Hide resolved
help: remove the trait bound
|
LL | trait Tr3 + SuperB {} //~ ERROR negative trait bounds are not supported
| --
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These help messages come out nonsensical, but the code suggestions apply correctly. Is this okay?

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 shame, we should try to make the suggestion more readable by showing the final code in a single step, instead of applying multiple changes at the same time. In this case it should be something like

error: negative trait bounds are not supported
  --> $DIR/issue-33418.rs:5:10
   |
LL | trait Tr3: !SuperA + SuperB {} //~ ERROR negative trait bounds are not supported
   |          ^^^^^^^^^
help: remove the trait bound
   |
LL | trait Tr3: SuperB {} //~ ERROR negative trait bounds are not supported
   |           --

src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
@hdhoang
Copy link
Contributor Author

hdhoang commented Feb 3, 2019

I have reconstructed a new bound list from the parsed bounds, unfortunately this will also delete linebreaks and compiletest`s comment. However I hope this method have minimal impact on the happy path.

@hdhoang
Copy link
Contributor Author

hdhoang commented Feb 9, 2019

hi @estebank, how do you feel about the current approach?

@estebank
Copy link
Contributor

@hdhoang I've been away for the past week. I'll try to review today.

@bors
Copy link
Contributor

bors commented Feb 12, 2019

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

@hdhoang
Copy link
Contributor Author

hdhoang commented Feb 13, 2019

I have resolved the conflict locally, but still would like to wait to rebase & make use of #58296 before pushing

@hdhoang
Copy link
Contributor Author

hdhoang commented Feb 17, 2019

Using span_suggestion_hidden gave the same output as span_suggestion_short, so I have skipped out on that change and only fixed the conflict.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 20, 2019

📌 Commit a55f1c3da60797b5c705ef34433a1d3414f99bf6 has been approved by estebank

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 20, 2019
@hdhoang
Copy link
Contributor Author

hdhoang commented Feb 22, 2019

Looks to be a network failure, please retry.

@ljedrz
Copy link
Contributor

ljedrz commented Feb 22, 2019

@bors retry

@bors
Copy link
Contributor

bors commented Feb 22, 2019

@ljedrz: 🔑 Insufficient privileges: not in try users

@ljedrz
Copy link
Contributor

ljedrz commented Feb 22, 2019

Oops, it seems that my try privileges haven't been deployed yet.

@kennytm
Copy link
Member

kennytm commented Feb 22, 2019

@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 Feb 22, 2019
@bors
Copy link
Contributor

bors commented Feb 23, 2019

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

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 23, 2019
@hdhoang
Copy link
Contributor Author

hdhoang commented Feb 23, 2019

I'll get on this

@hdhoang
Copy link
Contributor Author

hdhoang commented Feb 23, 2019

hi, this is good to go again. please ask @bors to retry.

@ljedrz
Copy link
Contributor

ljedrz commented Feb 23, 2019

Ok, let's try again ^^.

@bors retry

@bors
Copy link
Contributor

bors commented Feb 23, 2019

@ljedrz: 🔑 Insufficient privileges: not in try users

@kennytm
Copy link
Member

kennytm commented Feb 23, 2019

After push to a PR it can't simply be retried, it must be r+'ed again.

@bors r=estebank

@bors
Copy link
Contributor

bors commented Feb 23, 2019

📌 Commit 7cfddfb has been approved by estebank

@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 Feb 23, 2019
Centril added a commit to Centril/rust that referenced this pull request Feb 24, 2019
…tebank

Improve parsing diagnostic for negative supertrait bounds

closes rust-lang#33418

r? @estebank
Centril added a commit to Centril/rust that referenced this pull request Feb 24, 2019
…tebank

Improve parsing diagnostic for negative supertrait bounds

closes rust-lang#33418

r? @estebank
bors added a commit that referenced this pull request Feb 24, 2019
Rollup of 6 pull requests

Successful merges:

 - #57364 (Improve parsing diagnostic for negative supertrait bounds)
 - #58183 (Clarify guarantees for `Box` allocation)
 - #58442 (Simplify the unix `Weak` functionality)
 - #58454 (Refactor Windows stdio and remove stdin double buffering )
 - #58511 (Const to op simplification)
 - #58642 (rustdoc: support methods on primitives in intra-doc links)

Failed merges:

r? @ghost
@bors bors merged commit 7cfddfb into rust-lang:master Feb 24, 2019
@hdhoang
Copy link
Contributor Author

hdhoang commented Feb 24, 2019

thanks to everyone for guidance!

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.

Diagnostic when trying to use ! or ? in trait is confusing.
8 participants