-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
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 (
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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()) |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this?
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"); |
There was a problem hiding this comment.
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 */(
.
There was a problem hiding this comment.
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 😄 .
{ | ||
error.span_suggestion_verbose( | ||
prev_token_before_parsing.span, | ||
"consider removing `::`", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
tests/ui/parser/issues/diagnostics-parenthesized-type-arguments-issue-120892-3.stderr
Outdated
Show resolved
Hide resolved
@rustbot label -S-waiting-on-author +S-waiting-on-review |
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); |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PathStyle::Expr => "call the expresion", | |
PathStyle::Expr => "call the expression", |
typo
Let's do a perf run to make sure we haven't regressed the parsing perf of |
This comment has been minimized.
This comment has been minimized.
Improve diagnostics for parenthesized type arguments Fixes rust-lang#120892 r? fmease
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (d180540): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking 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 Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 649.076s -> 648.931s (-0.02%) |
(The artifact size change is just getting the libLLVM.so size back, thanks to rust-lang/rustc-perf#1838). |
There was a problem hiding this 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!
@bors r+ rollup |
Improve diagnostics for parenthesized type arguments Fixes rust-lang#120892 r? fmease
…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
Rollup merge of rust-lang#122152 - wutchzone:120892, r=fmease Improve diagnostics for parenthesized type arguments Fixes rust-lang#120892 r? fmease
Fixes #120892
r? fmease