From 3c0a49289cb5916ad4f3f55e0cb7e364724fe1d4 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Fri, 23 Apr 2021 06:44:16 +0300 Subject: [PATCH] binding_rust: Improve implementation of fmt::Display for QueryError trait, avoid multiple format!() calls --- lib/binding_rust/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 7138d8bc..73c310fc 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -1917,20 +1917,20 @@ impl fmt::Display for LanguageError { impl fmt::Display for QueryError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let msg = match self.kind { - QueryErrorKind::Capture => format!("Invalid capture name {}", self.message), - QueryErrorKind::Field => format!("Invalid field name {}", self.message), - QueryErrorKind::NodeType => format!("Invalid node type {}", self.message), - QueryErrorKind::Syntax => format!("Invalid syntax:\n{}", self.message), - QueryErrorKind::Structure => format!("Impossible pattern:\n{}", self.message), - QueryErrorKind::Predicate => format!("Invalid predicate: {}", self.message), - }; write!( f, - "Query error at {}:{}. {}", + "Query error at {}:{}. {}{}", self.row + 1, self.column + 1, - msg + match self.kind { + QueryErrorKind::Field => "Invalid field name ", + QueryErrorKind::NodeType => "Invalid node type ", + QueryErrorKind::Capture => "Invalid capture name ", + QueryErrorKind::Predicate => "Invalid predicate: ", + QueryErrorKind::Structure => "Impossible pattern:\n", + QueryErrorKind::Syntax => "Invalid syntax:\n", + }, + self.message ) } }