From 4d8fee64b31ec485dc5f99b378e1def2e0cafc72 Mon Sep 17 00:00:00 2001 From: francois-caddet Date: Mon, 23 Jan 2023 19:59:42 +0100 Subject: [PATCH] clippy pass --- src/bin/nickel.rs | 2 +- src/cache.rs | 2 +- src/nix.rs | 15 +++++++-------- src/stdlib.rs | 1 - tests/nix.rs | 5 ++--- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/bin/nickel.rs b/src/bin/nickel.rs index 75302ebf9..30e2bf5d9 100644 --- a/src/bin/nickel.rs +++ b/src/bin/nickel.rs @@ -127,7 +127,7 @@ fn main() { opts.file .map(std::fs::File::open) .map(|f| f.and_then(|mut f| f.read_to_string(&mut buf))) - .unwrap_or(std::io::stdin().read_to_string(&mut buf)) + .unwrap_or_else(|| std::io::stdin().read_to_string(&mut buf)) .unwrap_or_else(|err| { eprintln!("Error when reading input: {}", err); process::exit(1) diff --git a/src/cache.rs b/src/cache.rs index c7651aa17..1ccf7c138 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -456,7 +456,7 @@ impl Cache { Ok((t, parse_errs)) } InputFormat::Nix => Ok(( - crate::nix::parse(&self, file_id).unwrap(), + crate::nix::parse(self, file_id).unwrap(), ParseErrors::default(), )), InputFormat::Json => serde_json::from_str(self.files.source(file_id)) diff --git a/src/nix.rs b/src/nix.rs index 97035d7c7..fca5e9c4d 100644 --- a/src/nix.rs +++ b/src/nix.rs @@ -8,7 +8,7 @@ use crate::term::make::{self, if_then_else}; use crate::term::{record::RecordData, BinaryOp, UnaryOp}; use crate::term::{MergePriority, MetaValue, RichTerm, Term}; use codespan::FileId; -use rnix::ast::{BinOp as NixBinOp, Path as NixPath, Str as NixStr, UnaryOp as NixUniOp}; +use rnix::ast::{BinOp as NixBinOp, Str as NixStr, UnaryOp as NixUniOp}; use std::collections::HashMap; impl ToNickel for NixStr { @@ -71,10 +71,10 @@ impl ToNickel for NixBinOp { impl ToNickel for rnix::ast::Expr { fn translate(self, state: &State) -> RichTerm { - use rnix::ast::{self, Expr}; + use rnix::ast::Expr; use rowan::ast::AstNode; let pos = self.syntax().text_range(); - let file_id = state.file_id.clone(); + let file_id = state.file_id; let span = mk_span(file_id, pos.start().into(), pos.end().into()); println!("{:?}: {}", self, self); match self { @@ -85,7 +85,7 @@ impl ToNickel for rnix::ast::Expr { Expr::Root(n) => n.expr().unwrap().translate(state), Expr::Paren(n) => n.expr().unwrap().translate(state), - Expr::Assert(n) => unimplemented!(), + Expr::Assert(_) => unimplemented!(), Expr::Literal(n) => match n.kind() { rnix::ast::LiteralKind::Float(v) => Term::Num(v.value().unwrap()), @@ -169,13 +169,13 @@ impl ToNickel for rnix::ast::Expr { let id: Ident = match id.to_string().as_str() { "true" | "false" | "null" => panic!( "`let {}` is forbiden. Can not redifine `true`, `false` or `nul`", - id.to_string() + id ), s => s.into(), }; let rt = kv.value().unwrap().translate(&state); - destruct_vec.push(destruct::Match::Simple(id.clone(), Default::default())); - fields.insert(id.into(), rt); + destruct_vec.push(destruct::Match::Simple(id, Default::default())); + fields.insert(id, rt); } make::let_pat::( None, @@ -230,7 +230,6 @@ impl ToNickel for rnix::ast::Expr { }; Term::FunPattern(at, dest, n.body().unwrap().translate(state)) } - _ => unreachable!(), } } .into(), diff --git a/src/stdlib.rs b/src/stdlib.rs index 4cbb73df7..e46f32d04 100644 --- a/src/stdlib.rs +++ b/src/stdlib.rs @@ -146,7 +146,6 @@ pub mod internals { /// Contains functions helper for Nix evaluation by Nickel. pub mod compat { use super::*; - use crate::identifier::*; use crate::mk_app; use crate::term::make::op1; use crate::term::{array::Array, Term, UnaryOp}; diff --git a/tests/nix.rs b/tests/nix.rs index 73dafd0ca..c154ff13d 100644 --- a/tests/nix.rs +++ b/tests/nix.rs @@ -2,13 +2,12 @@ use nickel_lang::term::Term; use nickel_lang_utilities::eval; fn run(path: &str) { - let res = eval(format!( + eval(format!( "let t = import \"{}/tests/nix/{}\" in array.fold (fun x acc => acc && x) true t", env!("CARGO_MANIFEST_DIR"), path )) - .map(|rt| { - let term = Term::from(rt); + .map(|term| { assert_eq!(term, Term::Bool(true), "error in test {}", path,); }) .unwrap();