Skip to content

Commit 3ce62ce

Browse files
authored
Needless operation lint should ignore lambdas (#2406)
Fixes #2039
1 parent 94c8288 commit 3ce62ce

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

compiler/qsc_linter/src/lints/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl HirLintPass for NeedlessOperation {
161161
buffer: &mut Vec<Lint>,
162162
_compilation: Compilation,
163163
) {
164-
if decl.kind == CallableKind::Operation {
164+
if decl.kind == CallableKind::Operation && &*decl.name.name != "<lambda>" {
165165
let mut op_limits = IsQuantumOperation::default();
166166

167167
op_limits.visit_callable_decl(decl);

compiler/qsc_linter/src/tests.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,19 +433,11 @@ fn redundant_semicolons() {
433433
}
434434

435435
#[test]
436-
fn needless_operation_lambda_operations() {
436+
fn needless_operation_no_lint_for_lambda_operations() {
437437
check(
438438
&wrap_in_callable("let a = (a) => a + 1;", CallableKind::Function),
439439
&expect![[r#"
440-
[
441-
SrcLint {
442-
source: "(a) => a + 1",
443-
level: Allow,
444-
message: "operation does not contain any quantum operations",
445-
help: "this callable can be declared as a function instead",
446-
code_action_edits: [],
447-
},
448-
]
440+
[]
449441
"#]],
450442
);
451443
}
@@ -557,6 +549,7 @@ fn needless_operation_partial_application() {
557549
"#]],
558550
);
559551
}
552+
560553
#[test]
561554
fn deprecated_newtype_usage() {
562555
check(

0 commit comments

Comments
 (0)