Skip to content

Commit

Permalink
clippy pass
Browse files Browse the repository at this point in the history
  • Loading branch information
francois-caddet committed Jan 23, 2023
1 parent 02aeff9 commit 4d8fee6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/bin/nickel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 7 additions & 8 deletions src/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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()),
Expand Down Expand Up @@ -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::<Ident, _, _, _>(
None,
Expand Down Expand Up @@ -230,7 +230,6 @@ impl ToNickel for rnix::ast::Expr {
};
Term::FunPattern(at, dest, n.body().unwrap().translate(state))
}
_ => unreachable!(),
}
}
.into(),
Expand Down
1 change: 0 additions & 1 deletion src/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
5 changes: 2 additions & 3 deletions tests/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4d8fee6

Please sign in to comment.