Skip to content

Commit ca6a094

Browse files
committed
don't offer to re-wrap anonymous functions
1 parent 2670a2f commit ca6a094

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
@@ -7588,7 +7588,14 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
75887588
return;
75897589
}
75907590

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+
{
75927599
self.functions.push(FunctionToWrap {
75937600
location: expression.location(),
75947601
arguments: arguments.clone(),
@@ -7602,7 +7609,7 @@ impl<'ast> ast::visit::Visit<'ast> for WrapInAnonymousFunction<'ast> {
76027609
/// We don't want to apply to functions that are being explicitly called
76037610
/// already, so we need to intercept visits to function calls and bounce
76047611
/// 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 [].
76067613
fn visit_typed_expr_call(
76077614
&mut self,
76087615
_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
@@ -9237,8 +9237,8 @@ pub fn main() {
92379237
}
92389238

92399239
#[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!(
92429242
WRAP_IN_ANONYMOUS_FUNCTION,
92439243
"pub fn main() {
92449244
let f = fn(in) { ception(in) }

0 commit comments

Comments
 (0)