File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -298,6 +298,13 @@ pub enum FunctionLiteralKind {
298
298
}
299
299
300
300
impl FunctionLiteralKind {
301
+ pub fn is_anonymous ( & self ) -> bool {
302
+ match self {
303
+ FunctionLiteralKind :: Anonymous { .. } => true ,
304
+ FunctionLiteralKind :: Capture { .. } | FunctionLiteralKind :: Use { .. } => false ,
305
+ }
306
+ }
307
+
301
308
pub fn is_capture ( & self ) -> bool {
302
309
match self {
303
310
FunctionLiteralKind :: Capture { .. } => true ,
Original file line number Diff line number Diff line change @@ -8285,7 +8285,14 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
8285
8285
return ;
8286
8286
}
8287
8287
8288
- if let Type :: Fn { ref arguments, .. } = * expression. type_ ( ) {
8288
+ let is_excluded = match expression {
8289
+ TypedExpr :: Fn { kind, .. } if kind. is_anonymous ( ) => true ,
8290
+ _ => false ,
8291
+ } ;
8292
+
8293
+ if let Type :: Fn { arguments, .. } = & * expression. type_ ( )
8294
+ && !is_excluded
8295
+ {
8289
8296
self . functions . push ( FunctionToWrap {
8290
8297
location : expression. location ( ) ,
8291
8298
arguments : arguments. clone ( ) ,
@@ -8299,7 +8306,7 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
8299
8306
/// We don't want to apply to functions that are being explicitly called
8300
8307
/// already, so we need to intercept visits to function calls and bounce
8301
8308
/// them out again so they don't end up in our impl for visit_typed_expr.
8302
- /// Otherwise this is the same as [ast::visit::visit_typed_expr_call ].
8309
+ /// Otherwise this is the same as [].
8303
8310
fn visit_typed_expr_call (
8304
8311
& mut self ,
8305
8312
_location : & ' ast SrcSpan ,
Original file line number Diff line number Diff line change @@ -9901,8 +9901,8 @@ pub fn main() {
9901
9901
}
9902
9902
9903
9903
#[ test]
9904
- fn wrap_anonymous_function_in_anonymous_function ( ) {
9905
- assert_code_action ! (
9904
+ fn dont_wrap_anonymous_function_in_anonymous_function ( ) {
9905
+ assert_no_code_actions ! (
9906
9906
WRAP_IN_ANONYMOUS_FUNCTION ,
9907
9907
"pub fn main() {
9908
9908
let f = fn(in) { ception(in) }
You can’t perform that action at this time.
0 commit comments