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 diagnostics for parenthesized type arguments #122152

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

wutchzone
Copy link
Contributor

Fixes #120892

r? fmease

@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @fmease (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 7, 2024
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! Looks very good already. I have a couple of suggestions. I will probably kick off a performance run once you have address my suggestions related to the parser snapshot creation to make sure we don't impact the parsing performance of Fn{,Mut,Once}(…) -> … in the good path.


let mut snapshot = None;
if self.may_recover()
&& (self.token.can_begin_expr() || self.token.can_begin_pattern())
Copy link
Member

Choose a reason for hiding this comment

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

Could you make this check stricter by only checking if style is PathStyle::Expr first and if so if token.can_begin_expr(), too, or if style is PathStyle::Pat and if so if token.can_begin_pattern()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like this?

compiler/rustc_parse/src/parser/path.rs Show resolved Hide resolved
compiler/rustc_parse/src/parser/path.rs Show resolved Hide resolved
let (inputs, _) = match self.parse_paren_comma_seq(|p| p.parse_ty()) {
Ok(output) => output,
Err(mut error) if prev_token_before_parsing.kind == token::ModSep => {
error.span_label(prev_token_before_parsing.span.with_hi(prev_token_before_parsing.span.hi() + BytePos(1)), "while parsing this list of parenthesized type arguments starting here");
Copy link
Member

Choose a reason for hiding this comment

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

Manual offsetting is a bit fragile. I don't think this specific instance can lead to crashes but SourceMap::next_point should be preferred over BytePos(1) to account for multi-byte Unicode code points.

Anyway, BytePos(1) is not what we want here because it doesn't work if we have f:: ( (notice the space between the path separator and the opening parenthesis. Could you instead use Span::until or Span::between where the “upper”/right span is the span of the opening parenthesis / the span of the “paren_comma_seq” (I don't know how easy it is to obtain) to highlight the entirety of e.g. :: ( or ::/* comment */(.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I absolutely missed that 🤦 . I added to the tests. I think it should be enough to save the current token before calling the parse_paren_comma_seq with a combination of Span::to.

Now I wonder how fragile is the hardcoded byte offsetting, there are plenty of them in the code base 😄 .

compiler/rustc_parse/src/parser/path.rs Outdated Show resolved Hide resolved
{
error.span_suggestion_verbose(
prev_token_before_parsing.span,
"consider removing `::`",
Copy link
Member

@fmease fmease Mar 8, 2024

Choose a reason for hiding this comment

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

The suggestion is already pretty good but I'd like to see more context provided in this message. Something like consider removing the `::` here to make this a function call / … to turn this into a …. Function call is definitely not the right term here, maybe call expression / tuple struct pattern depending on the style.

Hopefully you can find a better more general term here, I don't know how to best call “$expr($expr, …)” / $path($pat, …) lol.

Copy link
Contributor Author

@wutchzone wutchzone Mar 9, 2024

Choose a reason for hiding this comment

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

I think™ the call expression is the correct term based on the rust reference. For the second one, I couldn't find a better name than you had already suggested.

compiler/rustc_parse/src/parser/path.rs Outdated Show resolved Hide resolved
@fmease fmease 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 8, 2024
@wutchzone
Copy link
Contributor Author

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbot rustbot 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 9, 2024
error: expected type, found `123`
--> $DIR/diagnostics-parenthesized-type-arguments-issue-120892-2.rs:2:45
|
LL | foo::/* definitely not harmful comment */(123, "foo") -> (u32);
Copy link
Member

Choose a reason for hiding this comment

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

😆

format!(
"consider removing the `::` here to {}",
match style {
PathStyle::Expr => "call the expresion",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
PathStyle::Expr => "call the expresion",
PathStyle::Expr => "call the expression",

typo

@fmease
Copy link
Member

fmease commented Mar 9, 2024

Let's do a perf run to make sure we haven't regressed the parsing perf of FnOnce() and friends.
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2024
Improve diagnostics for parenthesized type arguments

Fixes rust-lang#120892

r? fmease
@bors
Copy link
Contributor

bors commented Mar 9, 2024

⌛ Trying commit 2648a13 with merge d180540...

@bors
Copy link
Contributor

bors commented Mar 9, 2024

☀️ Try build successful - checks-actions
Build commit: d180540 (d180540fce069d2383eb1d1812142eff89641701)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d180540): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.5%, -0.3%] 3
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.8% [0.8%, 0.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [0.8%, 0.8%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 649.076s -> 648.931s (-0.02%)
Artifact size: 172.58 MiB -> 308.34 MiB (78.66%)

@Kobzol
Copy link
Contributor

Kobzol commented Mar 10, 2024

(The artifact size change is just getting the libLLVM.so size back, thanks to rust-lang/rustc-perf#1838).

Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

I love it, thanks!

@fmease
Copy link
Member

fmease commented Mar 11, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 11, 2024

📌 Commit 58f6aaa has been approved by fmease

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 11, 2024
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Mar 11, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 11, 2024
Improve diagnostics for parenthesized type arguments

Fixes rust-lang#120892

r? fmease
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 11, 2024
…kingjubilee

Rollup of 15 pull requests

Successful merges:

 - rust-lang#116791 (Allow codegen backends to opt-out of parallel codegen)
 - rust-lang#116793 (Allow targets to override default codegen backend)
 - rust-lang#117458 (LLVM Bitcode Linker: A self contained linker for nvptx and other targets)
 - rust-lang#119385 (Fix type resolution of associated const equality bounds (take 2))
 - rust-lang#121438 (std support for wasm32 panic=unwind)
 - rust-lang#121893 (Add tests (and a bit of cleanup) for interior mut handling in promotion and const-checking)
 - rust-lang#122080 (Clarity improvements to `DropTree`)
 - rust-lang#122152 (Improve diagnostics for parenthesized type arguments)
 - rust-lang#122166 (Remove the unused `field_remapping` field from `TypeLowering`)
 - rust-lang#122249 (interpret: do not call machine read hooks during validation)
 - rust-lang#122299 (Store backtrace for `must_produce_diag`)
 - rust-lang#122318 (Revision-related tweaks for next-solver tests)
 - rust-lang#122320 (Use ptradd for vtable indexing)
 - rust-lang#122328 (unix_sigpipe: Replace `inherit` with `sig_dfl` in syntax tests)
 - rust-lang#122330 (bootstrap readme: fix, improve, update)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 05ff86c into rust-lang:master Mar 11, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 11, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 11, 2024
Rollup merge of rust-lang#122152 - wutchzone:120892, r=fmease

Improve diagnostics for parenthesized type arguments

Fixes rust-lang#120892

r? fmease
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. 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.

Unhelpful error message when missing the final path segment for a function call
8 participants