From aead2001d7c3535be0f2f49daf73fe8a658d0c51 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 19 Aug 2023 17:31:48 +0200 Subject: refactor(tvix/eval): impl Default for SourceCode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … instead of new(). Suggested by clippy. Change-Id: Iac7be733392afefc2b4ff2e38386eee95f3bce94 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9103 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: raitobezarius --- tvix/eval/src/lib.rs | 2 +- tvix/eval/src/source.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs index deb48b50078e..3ce98bc47097 100644 --- a/tvix/eval/src/lib.rs +++ b/tvix/eval/src/lib.rs @@ -145,7 +145,7 @@ impl<'code, 'co, 'ro> Evaluation<'code, 'co, 'ro> { /// Initialise an `Evaluation` for the given Nix source code snippet, and /// an optional code location. pub fn new(code: &'code str, location: Option) -> Self { - let source_map = SourceCode::new(); + let source_map = SourceCode::default(); let location_str = location .as_ref() diff --git a/tvix/eval/src/source.rs b/tvix/eval/src/source.rs index 649679536080..5a7f10abb8da 100644 --- a/tvix/eval/src/source.rs +++ b/tvix/eval/src/source.rs @@ -19,11 +19,6 @@ use codemap::{CodeMap, Span}; pub struct SourceCode(Rc>); impl SourceCode { - /// Create a new SourceCode instance. - pub fn new() -> Self { - SourceCode(Rc::new(RefCell::new(CodeMap::new()))) - } - /// Access a read-only reference to the codemap. pub fn codemap(&self) -> Ref { self.0.borrow() @@ -61,3 +56,10 @@ impl SourceCode { self.codemap().look_up_span(span).file } } + +impl Default for SourceCode { + /// Create a new SourceCode instance. + fn default() -> Self { + Self(Rc::new(RefCell::new(CodeMap::new()))) + } +} -- cgit 1.4.1