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

Provide suggestion for missing > in a type parameter list #94495

Merged
merged 2 commits into from
Mar 27, 2022

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Mar 1, 2022

When encountering an inproperly terminated type parameter list, provide
a suggestion to close it after the last non-constraint type parameter
that was successfully parsed.

Fix #94058.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 1, 2022
@rust-highfive
Copy link
Collaborator

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 1, 2022
@compiler-errors
Copy link
Member

I am somewhat concerned about the ratio of misleading to useful "add >" suggestions here

... though I'm not sure how much additional effort it would take to improve this to e.g. not suggest adding > when there are already more > tokens downstream, or e.g. not suggest changing <a; b> into <a>; b> when the user uses an incorrect delimiter in a comma-separated list.

For example:

   |
help: you might have meant to end the type parameters here
   |
LL |     fn f1<'a>(arg : Box<dyn X<X::Y> = u32>>) {}
   |                                   +
   |
help: you might have meant to end the type parameters here
   |
LL | fn foo<'a, 'b>(x: &mut Foo<'a>; 'b>) {}
   |                              +

@estebank
Copy link
Contributor Author

estebank commented Mar 1, 2022

Those two cases in particular could/should be handled, one by explicitly accepting <type param> = <type> and rejecting it with an explicit error and by detecting , -> ; substitution, as we do elsewhere in the parser, but at the same time I feel that should be handled on its own targeted PR. From what I've seen most other tests that are changing seem to be caused by weird enough errors that the suggestion isn't entirely detrimental. What is problematic is the redundant label that I hadn't noticed saying "maybe try to close unmatched angle bracket".

@JohnCSimon JohnCSimon 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 20, 2022
@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 27, 2022
@estebank
Copy link
Contributor Author

@JohnCSimon I'm gonna revert the labels back here because I'm waiting on further review 😅

I feel like the fallout is acceptable as is for merging, but can understand if the reviewers disagree.

When encountering an inproperly terminated type parameter list, provide
a suggestion to close it after the last non-constraint type parameter
that was successfully parsed.

Fix rust-lang#94058.
Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

I think it's hard to say anything about the "very wrong syntax" cases. But, I think this is worth it from the new tests, which more likely represent what a user would normally run into.

One nit, but r=me with/without.

arg.span().shrink_to_hi(),
"you might have meant to end the type parameters here",
">".to_string(),
Applicability::MaybeIncorrect,
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if MaybeIncorrect is the right choice here. A lot of the suggestions in tests don't result in valid code (namely when we later have a closing >. But 🤷‍♀️

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 think it's the best of the available Applicabilitys we have available today :)

@estebank
Copy link
Contributor Author

Added one more check for ,/; typo in type params.

@jackh726
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 27, 2022

📌 Commit 157c67b has been approved by jackh726

@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 Mar 27, 2022
@bors
Copy link
Contributor

bors commented Mar 27, 2022

⌛ Testing commit 157c67b with merge 6a755d790d12f0ba5a1234f613f147f19725be76...

@bors
Copy link
Contributor

bors commented Mar 27, 2022

💔 Test failed - checks-actions

@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 Mar 27, 2022
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
To only update this specific test, also pass `--test-args concurrency/libc_pthread_cond.rs`

error: 1 errors occurred comparing output.
status: exit status: 101
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools-bin/miri" "tests/run-pass/concurrency/libc_pthread_cond.rs" "-L" "/tmp/compiletestMD29BU" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-C" "prefer-dynamic" "-o" "/tmp/compiletestMD29BU/concurrency/libc_pthread_cond.stage-id" "-A" "unused" "--edition" "2018" "-Astable-features" "--sysroot" "/home/user/.cache/miri/HOST" "-Zmiri-disable-isolation" "-Zmiri-check-number-validity" "-L" "/tmp/compiletestMD29BU/concurrency/libc_pthread_cond.stage-id.aux"
------------------------------------------

------------------------------------------
stderr:
---
To only update this specific test, also pass `--test-args concurrency/sync.rs`

error: 2 errors occurred comparing output.
status: exit status: 101
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools-bin/miri" "tests/run-pass/concurrency/sync.rs" "-L" "/tmp/compiletestMD29BU" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-C" "prefer-dynamic" "-o" "/tmp/compiletestMD29BU/concurrency/sync.stage-id" "-A" "unused" "--edition" "2018" "-Astable-features" "--sysroot" "/home/user/.cache/miri/HOST" "-Zmiri-disable-isolation" "-Zmiri-check-number-validity" "-L" "/tmp/compiletestMD29BU/concurrency/sync.stage-id.aux"
------------------------------------------

------------------------------------------
stderr:
---



The actual stderr differed from the expected stderr.
Actual stderr saved to /tmp/compiletestMD29BU/vec.stage-id.stderr
To only update this specific test, also pass `--test-args vec.rs`

error: 1 errors occurred comparing output.
status: exit status: 101
status: exit status: 101
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools-bin/miri" "tests/run-pass/vec.rs" "-L" "/tmp/compiletestMD29BU" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-C" "prefer-dynamic" "-o" "/tmp/compiletestMD29BU/vec.stage-id" "-A" "unused" "--edition" "2018" "-Astable-features" "--sysroot" "/home/user/.cache/miri/HOST" "-Zmiri-tag-raw-pointers" "-Zmiri-check-number-validity" "-L" "/tmp/compiletestMD29BU/vec.stage-id.aux"
------------------------------------------

------------------------------------------
stderr:
---
.......... (60/61)
          (61/61)


/checkout/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml search-tab-selection-if-current-is-empty... FAILED
[ERROR] (line 6) TimeoutError: waiting for selector "#titles" failed: timeout 30000ms exceeded: for command `wait-for: "#titles"`
Build completed unsuccessfully in 0:00:46

@estebank
Copy link
Contributor Author

Looks like a timeout error?

/checkout/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml search-tab-selection-if-current-is-empty... FAILED
Error:  (line 6) TimeoutError: waiting for selector "#titles" failed: timeout 30000ms exceeded: for command `wait-for: "#titles"`

Build completed unsuccessfully in 0:00:46
== clock drift check ==
  local time: Sun Mar 27 15:02:11 UTC 2022
  network time: Sun, 27 Mar 2022 15:02:11 GMT
== end clock drift check ==
F
Error: Process completed with exit code 1.

@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 Mar 27, 2022
@bors
Copy link
Contributor

bors commented Mar 27, 2022

⌛ Testing commit 157c67b with merge ab0c2e1...

@bors
Copy link
Contributor

bors commented Mar 27, 2022

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing ab0c2e1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 27, 2022
@bors bors merged commit ab0c2e1 into rust-lang:master Mar 27, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 27, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ab0c2e1): comparison url.

Summary: This benchmark run did not return any relevant results. 7 results were found to be statistically significant but too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@estebank estebank deleted the missing-closing-gt branch November 9, 2023 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad diagnostics span for unmatched angle brackets of generic args
9 participants