Skip to content

fix(assists/replace_match_with_if_let): don't parenthesize if-let guards#22618

Open
ada4a wants to merge 3 commits into
rust-lang:masterfrom
ada4a:replace_match_with_if_let-no-paren-if_let-guard
Open

fix(assists/replace_match_with_if_let): don't parenthesize if-let guards#22618
ada4a wants to merge 3 commits into
rust-lang:masterfrom
ada4a:replace_match_with_if_let-no-paren-if_let-guard

Conversation

@ada4a

@ada4a ada4a commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Parenthesizing added in #21937, cc @A4-Tacks

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 19, 2026
Comment thread crates/ide-assists/src/handlers/replace_if_let_with_match.rs Outdated
}

#[test]
fn test_replace_match_with_if_let_with_if_let_guard() {

@ada4a ada4a Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Those names are getting ridiculously long imo... What do you all think about having replace_match_with_if_let be a submodule of tests, so that all the tests for that don't need to repeat it in the name? This would make the test suite more structured imo, at the cost of some rightward drift

View changes since the review

Comment thread crates/ide-assists/src/handlers/replace_if_let_with_match.rs Outdated
@ada4a ada4a force-pushed the replace_match_with_if_let-no-paren-if_let-guard branch from 35d1adf to 2534980 Compare June 19, 2026 14:40
@ada4a ada4a force-pushed the replace_match_with_if_let-no-paren-if_let-guard branch from 2534980 to 78c94bb Compare June 19, 2026 14:49
ada4a added 2 commits June 19, 2026 17:12
The next commit is going to add a bigger test, so I figured it's time to
collect all of them at the end of the file.
@ada4a ada4a force-pushed the replace_match_with_if_let-no-paren-if_let-guard branch from 03f2dbd to 88d34da Compare June 19, 2026 15:15
@ada4a

ada4a commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

You'd think typos would know to ignore identifiers, as I can't call one true... oh well

/// body
/// }
/// ```
/// won't compile.

@A4-Tacks A4-Tacks Jun 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Redundant documents

View changes since the review

}
}

guard.precedence().needs_parentheses_in(ast::prec::ExprPrecedence::LAnd) && !has_let_expr(guard)

@A4-Tacks A4-Tacks Jun 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use Expr::needs_parens_in_place_of
And if has_let_expr is still needed, then it should be in prec.rs instead of utils.rs

View changes since the review

@ada4a ada4a Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please use Expr::needs_parens_in_guard_chain

No such method exists? Or do you mean I should turn this function into a method on Expr?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry typo, is Expr::needs_parens_in_place_of

}

#[test]
fn test_needs_parens_in_guard_chain() {

@A4-Tacks A4-Tacks Jun 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to test this function

View changes since the review

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants