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 @@ -7588,7 +7588,14 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
7588
7588
return ;
7589
7589
}
7590
7590
7591
- if let Type :: Fn { ref arguments, .. } = * expression. type_ ( ) {
7591
+ let is_excluded = match expression {
7592
+ TypedExpr :: Fn { kind, .. } if kind. is_anonymous ( ) => true ,
7593
+ _ => false ,
7594
+ } ;
7595
+
7596
+ if let Type :: Fn { arguments, .. } = & * expression. type_ ( )
7597
+ && !is_excluded
7598
+ {
7592
7599
self . functions . push ( FunctionToWrap {
7593
7600
location : expression. location ( ) ,
7594
7601
arguments : arguments. clone ( ) ,
@@ -7602,7 +7609,7 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
7602
7609
/// We don't want to apply to functions that are being explicitly called
7603
7610
/// already, so we need to intercept visits to function calls and bounce
7604
7611
/// them out again so they don't end up in our impl for visit_typed_expr.
7605
- /// Otherwise this is the same as [ast::visit::visit_typed_expr_call ].
7612
+ /// Otherwise this is the same as [].
7606
7613
fn visit_typed_expr_call (
7607
7614
& mut self ,
7608
7615
_location : & ' ast SrcSpan ,
Original file line number Diff line number Diff line change @@ -9237,8 +9237,8 @@ pub fn main() {
9237
9237
}
9238
9238
9239
9239
#[ test]
9240
- fn wrap_anonymous_function_in_anonymous_function ( ) {
9241
- assert_code_action ! (
9240
+ fn dont_wrap_anonymous_function_in_anonymous_function ( ) {
9241
+ assert_no_code_actions ! (
9242
9242
WRAP_IN_ANONYMOUS_FUNCTION ,
9243
9243
"pub fn main() {
9244
9244
let f = fn(in) { ception(in) }
You can’t perform that action at this time.
0 commit comments