From f6de4434c3838431c8d5c0782f786c07ac46b212 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 28 Aug 2022 00:04:47 +0300 Subject: feat(tvix/eval): allow ignoring locals by prefixing with _ This is a common idiom in both Nix and other languages when a local is declared without actually being used. Since Tvix warns for unused locals, having this available is useful and can be included in the final error message as a suggestion if an unused variable is intentional. Change-Id: Ia85f704ba183499a3bae657c58166e2e29f9bde5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6320 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/compiler/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index bf5c55db2a..ffc7daf8e9 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -884,10 +884,11 @@ impl Compiler { if let Some(Local { node: Some(node), used, + name, .. }) = self.scope_mut().locals.pop() { - if !used { + if !used && !name.starts_with('_') { self.emit_warning(node, WarningKind::UnusedBinding); } } -- cgit 1.4.1