Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix linting false positive when block used as value #141987

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

Open
ChAoSUnItY wants to merge 2 commits into rust-lang:master
base: master
Choose a base branch
Loading
from ChAoSUnItY:fix/unused_braces

Conversation

Copy link
Contributor

@ChAoSUnItY ChAoSUnItY commented Jun 3, 2025
edited by rustbot
Loading

Fix #141783.

Copy link
Collaborator

rustbot commented Jun 3, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Jun 3, 2025
@ChAoSUnItY ChAoSUnItY changed the title (削除) Fix linting false positive when block used as val (削除ここまで) (追記) Fix linting false positive when block used as value (追記ここまで) Jun 3, 2025

This comment has been minimized.

declare_lint_pass!(UnusedBraces => [UNUSED_BRACES]);
#[derive(Default)]
pub(crate) struct UnusedBraces {
parent_followed_by_block: Vec<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
parent_followed_by_block: Vec<bool>,
followed_by_block: Vec<bool>,

and please add a short comment why this is used

Copy link
Contributor Author

@ChAoSUnItY ChAoSUnItY Jun 5, 2025

Choose a reason for hiding this comment

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

I think this should be informative enough?

// Used for tracking parent expressions that would immediately followed
// by block. Storing false here indicates that expression itself is Block
// expression. This is meant for to prevent report false positive cases where
// expressions with stronger block bind being linted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Storing false here indicates that expression itself is Block expression.

that's for the current impl, I think storing false should mean: while we may be inside of an expression which has a trailing block expression, there exists an expression between that one and the current which acts like a block, but may also be a function call or a try-block

ChAoSUnItY reacted with thumbs up emoji

impl UnusedBraces {
#[inline]
fn should_mark_block(e: &ast::Expr) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn should_mark_block(e: &ast::Expr) -> bool {
fn impacts_followed_by_block(e: &ast::Expr) -> bool {

Copy link
Contributor

lcnr commented Jun 5, 2025

we also need this for unused parens:

#![allow(unused)]
#![warn(unused_parens)]
struct Foo;
fn main() {
 loop {
 if break (Foo) {}
 };
}

please add this as a test, also test if fn_call({ return }) {}. This should lint (i.e. recursing into function calls should update followed_by_block to false

same for try { { return } }. In general, anything that "wraps" its nested expr should set followed_by_block to false

Copy link
Contributor

lcnr commented Jul 3, 2025

@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 Jul 3, 2025
Copy link
Collaborator

rustbot commented Jul 3, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Copy link
Collaborator

bors commented Jul 28, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@lcnr lcnr lcnr left review comments

Assignees

@lcnr lcnr

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
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

False positive unused_braces

AltStyle によって変換されたページ (->オリジナル) /