Skip to content

fix: Prevent wrong invocations of needs_parens_in with non-ancestral "parent"s #19324

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

Merged
merged 2 commits into from
Mar 9, 2025

Conversation

ShoyuVanilla
Copy link
Member

Fixes #19323

This also migrates inline_local_variable to SyntaxEditor as a part of #18285

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 9, 2025
check_assist(
apply_demorgan,
"fn() { let x = a && !(!b |$0| !c); }",
"fn() { let x = a && b && c; }",
"fn() { let x = a && (b && c); }",
)
Copy link
Member Author

Choose a reason for hiding this comment

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

These test chages might be a regression, but I think that the changed ones are more consistent with other test cases

@ShoyuVanilla ShoyuVanilla changed the title fix: Prevent wrong invocations of need_parens_in with non-ancestral "parent"s fix: Prevent wrong invocations of needs_parens_in with non-ancestral "parent"s Mar 9, 2025
};
Some((range, name_ref, initializer_expr.needs_parens_in(&usage_parent)))
let should_wrap = initializer_expr
.needs_parens_in_place_of(&usage_parent, usage_node.as_ref().unwrap());
Copy link
Member Author

Choose a reason for hiding this comment

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

let a = 123 < 456;
let b = !a;

In the above code, initializer_expr is 123 < 456 and usage_parent is let b = !a. So, inside needs_parens_in, it assumes that initializer_expr "comes before parent" because its text range is earlier, and decides that it needs no parentheses

@Veykril Veykril added this pull request to the merge queue Mar 9, 2025
Merged via the queue into rust-lang:master with commit 5e7dd31 Mar 9, 2025
9 checks passed
@ShoyuVanilla ShoyuVanilla deleted the migrate-inline-var branch March 9, 2025 11:31
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.

inline variable assist changes semantics (forgets to add parantheses)
3 participants