File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,30 @@ mod tests {
162162 check_assist_not_applicable ( remove_parentheses, r#"fn f() { if $0(return) {} }"# ) ;
163163 }
164164
165+ #[ test]
166+ fn remove_parens_prefix_with_return_no_value ( ) {
167+ // removing `()` from !(return) would make `!return` which is invalid syntax
168+ check_assist_not_applicable (
169+ remove_parentheses,
170+ r#"fn main() { let _x = true && !$0(return) || true; }"# ,
171+ ) ;
172+ check_assist_not_applicable ( remove_parentheses, r#"fn f() { !$0(return) }"# ) ;
173+ check_assist_not_applicable ( remove_parentheses, r#"fn f() { !$0(break) }"# ) ;
174+ check_assist_not_applicable ( remove_parentheses, r#"fn f() { !$0(continue) }"# ) ;
175+
176+ // Binary operators should still allow removal
177+ check_assist (
178+ remove_parentheses,
179+ r#"fn f() { true || $0(return) }"# ,
180+ r#"fn f() { true || return }"# ,
181+ ) ;
182+ check_assist (
183+ remove_parentheses,
184+ r#"fn f() { cond && $0(return) }"# ,
185+ r#"fn f() { cond && return }"# ,
186+ ) ;
187+ }
188+
165189 #[ test]
166190 fn remove_parens_return_with_value_followed_by_block ( ) {
167191 check_assist (
Original file line number Diff line number Diff line change @@ -226,6 +226,12 @@ impl Expr {
226226 return false ;
227227 }
228228
229+ // Special-case prefix operators with return/break/etc without value
230+ // e.g., `!(return)` - parentheses are necessary
231+ if self . is_ret_like_with_no_value ( ) && parent. is_prefix ( ) {
232+ return true ;
233+ }
234+
229235 if self . is_paren_like ( )
230236 || parent. is_paren_like ( )
231237 || self . is_prefix ( )
You can’t perform that action at this time.
0 commit comments