From 51be6542c98158feb89e0e2d89f6b5165a070914 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 22 Aug 2022 23:01:40 +0300 Subject: refactor(tvix/eval): add helper for emitting compiler warnings Change-Id: I2d98dbb7274d07985f64e7cc8944e316bf42e1bf Reviewed-on: https://cl.tvl.fyi/c/depot/+/6234 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/compiler.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs index 7a27022d96de..0718f45ba777 100644 --- a/tvix/eval/src/compiler.rs +++ b/tvix/eval/src/compiler.rs @@ -135,10 +135,7 @@ impl Compiler { Ok(()) } ast::LiteralKind::Uri(u) => { - self.warnings.push(EvalWarning { - node: node.syntax().clone(), - kind: WarningKind::DeprecatedLiteralURL, - }); + self.emit_warning(node.syntax().clone(), WarningKind::DeprecatedLiteralURL); let idx = self .chunk @@ -610,10 +607,7 @@ impl Compiler { // Within a `let` binding, inheriting from the outer // scope is practically a no-op. None => { - self.warnings.push(EvalWarning { - node: inherit.syntax().clone(), - kind: WarningKind::UselessInherit, - }); + self.emit_warning(inherit.syntax().clone(), WarningKind::UselessInherit); continue; } @@ -827,6 +821,10 @@ impl Compiler { None } + + fn emit_warning(&mut self, node: rnix::SyntaxNode, kind: WarningKind) { + self.warnings.push(EvalWarning { node, kind }) + } } /// Convert a non-dynamic string expression to a string if possible, -- cgit 1.4.1