Skip to content

Commit 8884ab1

Browse files
committed
don't offer to re-wrap anonymous functions
1 parent 631d821 commit 8884ab1

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

compiler-core/src/ast/untyped.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ pub enum FunctionLiteralKind {
298298
}
299299

300300
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+
301308
pub fn is_capture(&self) -> bool {
302309
match self {
303310
FunctionLiteralKind::Capture { .. } => true,

compiler-core/src/language_server/code_action.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8285,7 +8285,14 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
82858285
return;
82868286
}
82878287

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+
{
82898296
self.functions.push(FunctionToWrap {
82908297
location: expression.location(),
82918298
arguments: arguments.clone(),
@@ -8299,7 +8306,7 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
82998306
/// We don't want to apply to functions that are being explicitly called
83008307
/// already, so we need to intercept visits to function calls and bounce
83018308
/// 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 [].
83038310
fn visit_typed_expr_call(
83048311
&mut self,
83058312
_location: &'ast SrcSpan,

compiler-core/src/language_server/tests/action.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9901,8 +9901,8 @@ pub fn main() {
99019901
}
99029902

99039903
#[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!(
99069906
WRAP_IN_ANONYMOUS_FUNCTION,
99079907
"pub fn main() {
99089908
let f = fn(in) { ception(in) }

0 commit comments

Comments
 (0)