Skip to content

Conversation

Arc8ne
Copy link

@Arc8ne Arc8ne commented Jun 22, 2025

fixes #812


changelog: [collapsible_if]: handle another type of collapsible if-statement

@rustbot
Copy link
Collaborator

rustbot commented Jun 22, 2025

r? @dswij

rustbot has assigned @dswij.
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 the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 22, 2025
@Arc8ne
Copy link
Author

Arc8ne commented Jun 22, 2025

r? @samueltardieu

This PR is an updated version of PR #15027.

@rustbot rustbot assigned samueltardieu and unassigned dswij Jun 22, 2025
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 23, 2025
… previous commit.

Correct specifying of applicability for calls to functions that modify an `Applicability`.
Update suggestion message to adhere to standard conventions.
Change default value passed to `Sugg::hir_with_applicability` to a suitable one.
Format code.
Update the corresponding `stderr` file for this lint.
@Arc8ne Arc8ne requested a review from samueltardieu June 23, 2025 14:19
@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 from the author. (Use `@rustbot ready` to update this status) labels Jun 23, 2025
@Arc8ne
Copy link
Author

Arc8ne commented Jun 24, 2025

@samueltardieu Thanks for the review, I have implemented your suggested changes in my latest commit and was wondering if you could re-review it?

Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

The suggestion may be wrong when operators other than == or != are used. Please fix, and also add more complicated tests involving conditions with binary operators, including && and || operators.

Comment on lines +236 to +240
let new_bin_op = if let BinOpKind::Ne = bin_op.node {
BinOpKind::Eq
} else {
BinOpKind::Ne
};
Copy link
Member

Choose a reason for hiding this comment

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

What about other binary operations? Right now, the following

    let a = 10;
    let b = 20;

    if a < 20 {
        if b < 30 {
            println!("Hello");
        }
    } else {
        println!("world!");
    }

will be transformed into the (non equivalent)

    if a != 20 || b < 30 {
        println!("Hello world!");
    }

You should look at the ! operator for Sugg and let it invert the operation, it might be beneficial.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 1, 2025
@Arc8ne
Copy link
Author

Arc8ne commented Jul 10, 2025

The suggestion may be wrong when operators other than == or != are used. Please fix, and also add more complicated tests involving conditions with binary operators, including && and || operators.

Thanks for the review, I'll work on implementing those suggestions.

@rustbot
Copy link
Collaborator

rustbot commented Aug 17, 2025

☔ The latest upstream changes (possibly #14896) 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
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

improve collapsible if in complex cases with same expressions
4 participants