Skip to content

Don't suggest a semicolon when one already exists #134247

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

Closed
wants to merge 3 commits into from
Closed

Don't suggest a semicolon when one already exists #134247

wants to merge 3 commits into from

Conversation

joculatrix
Copy link
Contributor

In cases where it can be confirmed that an expression with borrow conflicts is already followed by an expression, the compiler will no longer suggest adding a second semicolon.

This is my first time contributing to the compiler; I eagerly accept any feedback on improvements or how this could be done differently.

closes #133941

@rustbot
Copy link
Collaborator

rustbot commented Dec 13, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @lcnr (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 Dec 13, 2024
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

Hi 👋 please add a regression test to an appropriate subfolder of tests/ui

match source_map.span_to_snippet(span) {
Ok(span_str) => !span_str.contains(';'),
Err(_) => true,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we probably want to change BlockTailInfo::tail_result_is_ignored instead. Using spans for such checks does not work in case the error involves macro calls. The current check may also have issues if something like tail_expr ; or tail_expr/* */; or tail_expr<new-line>; is used

I could imagine that we should either change tail_result_is_ignored to an enum tracking why it's ignored or alternatively change LocalInfo::BlockTailTemp to track whether the tail is an expr or a statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! Thanks for the suggestion - I knew someone who knew more than me would steer me in a better direction. I'll look into that. 👍

@joculatrix joculatrix marked this pull request as draft December 13, 2024 17:46
@joculatrix
Copy link
Contributor Author

@rustbot author

@rustbot rustbot 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 Dec 13, 2024
@joculatrix
Copy link
Contributor Author

@lcnr Sorry if you're not a good person to ask -- as far as I can tell, information about whether or not a statement/block ends with a semicolon is lost when hir::StmtKind::Expr and hir::StmtKind::Semi both get lowered to the same representation in the THIR, which then doesn't pass it on to the MIR. The error message in question is caught during borrow-checking, which uses the MIR. I just want to ask before doing it because I'm a new contributor and don't want to go beyond the scope of this issue/PR: is it appropriate to go back as far as editing how the HIR is lowered to THIR and how that then is lowered to MIR in order to preserve whether statements end with semicolons? Or, if not, is there some other way of getting this information that I'm missing?

@lcnr
Copy link
Contributor

lcnr commented Dec 23, 2024

: is it appropriate to go back as far as editing how the HIR is lowered to THIR and how that then is lowered to MIR in order to preserve whether statements end with semicolons?

If we currently end up erasing that information, making sure it's tracked somewhere during lowering is appropriate

This commit pivots from the previous naive solution of checking spans
towards preserving semicolon information during THIR and MIR lowering
via BlockTailInfo, BlockTailTemp, and an enum for tracking if a tail
result is ignored and whether the block has a trailing semicolon.

This commit currently isn't successful.
@joculatrix
Copy link
Contributor Author

I've pivoted towards preserving that info in an enum as suggested. The current commit doesn't work yet and breaks a lot of tests, so it's still a work in progress, but I think I'm close (and wanted to push my work so far just so it's clear I'm working on it).

@joculatrix joculatrix closed this Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

E0499 error shouldn't suggest adding a semicolon when there already is one
3 participants