summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
authorNadrieril2019-04-08 18:23:55 +0200
committerNadrieril2019-04-08 18:23:55 +0200
commit47c0a3ca296a9b775275c2c7118a172b9f0bcc54 (patch)
treec84f253528fdbea2f7d14aac1c909ec51c7b3184 /dhall/src
parent00fa24b851ff6337cf4c5c63f82d95488180a413 (diff)
clippy
Diffstat (limited to 'dhall/src')
-rw-r--r--dhall/src/binary.rs30
-rw-r--r--dhall/src/lib.rs1
-rw-r--r--dhall/src/normalize.rs35
-rw-r--r--dhall/src/typecheck.rs5
4 files changed, 40 insertions, 31 deletions
diff --git a/dhall/src/binary.rs b/dhall/src/binary.rs
index 87972cf..c785daf 100644
--- a/dhall/src/binary.rs
+++ b/dhall/src/binary.rs
@@ -237,11 +237,11 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {
};
let path = rest
.map(|s| {
- s.as_string().ok_or(
+ s.as_string().ok_or_else(|| {
DecodeError::WrongFormatError(
"import/remote/path".to_owned(),
- ),
- )
+ )
+ })
})
.collect::<Result<_, _>>()?;
ImportLocation::Remote(URL {
@@ -264,11 +264,11 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {
};
let path = rest
.map(|s| {
- s.as_string().ok_or(
+ s.as_string().ok_or_else(|| {
DecodeError::WrongFormatError(
"import/local/path".to_owned(),
- ),
- )
+ )
+ })
})
.collect::<Result<_, _>>()?;
ImportLocation::Local(prefix, path)
@@ -296,11 +296,11 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {
let mut tuples = bindings.iter().tuples();
let bindings = (&mut tuples)
.map(|(x, t, v)| {
- let x = x.as_string().ok_or(
+ let x = x.as_string().ok_or_else(|| {
DecodeError::WrongFormatError(
"let/label".to_owned(),
- ),
- )?;
+ )
+ })?;
let x = Label::from(x.as_str());
let t = match t {
Null => None,
@@ -310,9 +310,9 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {
Ok((x, t, v))
})
.collect::<Result<Vec<_>, _>>()?;
- let expr = tuples.into_buffer().next().ok_or(
- DecodeError::WrongFormatError("let/expr".to_owned()),
- )?;
+ let expr = tuples.into_buffer().next().ok_or_else(|| {
+ DecodeError::WrongFormatError("let/expr".to_owned())
+ })?;
let expr = cbor_value_to_dhall(expr)?;
return Ok(bindings
.into_iter()
@@ -334,9 +334,9 @@ fn cbor_map_to_dhall_map(
) -> Result<std::collections::BTreeMap<Label, ParsedExpr>, DecodeError> {
map.iter()
.map(|(k, v)| -> Result<(_, _), _> {
- let k = k
- .as_string()
- .ok_or(DecodeError::WrongFormatError("map/key".to_owned()))?;
+ let k = k.as_string().ok_or_else(|| {
+ DecodeError::WrongFormatError("map/key".to_owned())
+ })?;
let v = cbor_value_to_dhall(v)?;
Ok((Label::from(k.as_ref()), v))
})
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs
index 6436927..5c5a641 100644
--- a/dhall/src/lib.rs
+++ b/dhall/src/lib.rs
@@ -1,6 +1,7 @@
#![feature(trace_macros)]
#![feature(proc_macro_hygiene)]
#![feature(slice_patterns)]
+#![feature(label_break_value)]
#![cfg_attr(test, feature(custom_inner_attributes))]
#![allow(
clippy::type_complexity,
diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs
index a43f73f..2454db4 100644
--- a/dhall/src/normalize.rs
+++ b/dhall/src/normalize.rs
@@ -14,7 +14,7 @@ impl Typed {
}
}
-fn apply_builtin<S, A>(b: Builtin, args: &Vec<Expr<S, A>>) -> WhatNext<S, A>
+fn apply_builtin<S, A>(b: Builtin, args: &[Expr<S, A>]) -> WhatNext<S, A>
where
S: fmt::Debug + Clone,
A: fmt::Debug + Clone,
@@ -22,7 +22,7 @@ where
use dhall_core::Builtin::*;
use dhall_core::ExprF::*;
use WhatNext::*;
- let (ret, rest) = match (b, args.as_slice()) {
+ let (ret, rest) = match (b, args) {
(OptionalSome, [x, rest..]) => (rc(NEOptionalLit(x.roll())), rest),
(OptionalNone, [t, rest..]) => (rc(EmptyOptionalLit(t.roll())), rest),
(NaturalIsZero, [NaturalLit(n), rest..]) => {
@@ -80,19 +80,22 @@ where
(rc(NEListLit(xs)), rest)
}
(ListBuild, [a0, g, rest..]) => {
- loop {
+ 'ret: {
if let App(f2, args2) = g {
if let (Builtin(ListFold), [_, x, rest_inner..]) =
(f2.as_ref(), args2.as_slice())
{
// fold/build fusion
- break (rc(App(x.clone(), rest_inner.to_vec())), rest);
+ break 'ret (
+ rc(App(x.clone(), rest_inner.to_vec())),
+ rest,
+ );
}
};
let a0 = a0.roll();
let a1 = shift(1, &V("a".into(), 0), &a0);
let g = g.roll();
- break (
+ break 'ret (
dhall_expr!(
g
(List a0)
@@ -104,18 +107,21 @@ where
}
}
(OptionalBuild, [a0, g, rest..]) => {
- loop {
+ 'ret: {
if let App(f2, args2) = g {
if let (Builtin(OptionalFold), [_, x, rest_inner..]) =
(f2.as_ref(), args2.as_slice())
{
// fold/build fusion
- break (rc(App(x.clone(), rest_inner.to_vec())), rest);
+ break 'ret (
+ rc(App(x.clone(), rest_inner.to_vec())),
+ rest,
+ );
}
};
let a0 = a0.roll();
let g = g.roll();
- break (
+ break 'ret (
dhall_expr!(
g
(Optional a0)
@@ -155,17 +161,20 @@ where
// normalize_ref(&App(bx(x.clone()), rest.to_vec()))
// }
(NaturalBuild, [g, rest..]) => {
- loop {
+ 'ret: {
if let App(f2, args2) = g {
if let (Builtin(NaturalFold), [x, rest_inner..]) =
(f2.as_ref(), args2.as_slice())
{
// fold/build fusion
- break (rc(App(x.clone(), rest_inner.to_vec())), rest);
+ break 'ret (
+ rc(App(x.clone(), rest_inner.to_vec())),
+ rest,
+ );
}
};
let g = g.roll();
- break (
+ break 'ret (
dhall_expr!(g Natural (λ(x : Natural) -> x + 1) 0),
rest,
);
@@ -270,8 +279,8 @@ where
BinOp(ListAppend, EmptyListLit(_), y) => DoneRef(y),
BinOp(ListAppend, x, EmptyListLit(_)) => DoneRef(x),
BinOp(ListAppend, NEListLit(xs), NEListLit(ys)) => {
- let xs = xs.into_iter().cloned();
- let ys = ys.into_iter().cloned();
+ let xs = xs.iter().cloned();
+ let ys = ys.iter().cloned();
Done(NEListLit(xs.chain(ys).collect()))
}
Merge(RecordLit(handlers), UnionLit(k, v, _), _) => {
diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs
index 5230aab..998d3ca 100644
--- a/dhall/src/typecheck.rs
+++ b/dhall/src/typecheck.rs
@@ -419,10 +419,9 @@ pub fn type_with(
None => Err(mkerr(UnboundVariable)),
},
App(f, args) => {
- let mut iter = args.into_iter();
let mut seen_args: Vec<SubExpr<_, _>> = vec![];
let mut tf = f.get_type().clone();
- while let Some(a) = iter.next() {
+ for a in args {
seen_args.push(a.as_expr().clone());
let (x, tx, tb) = ensure_matches!(tf,
Pi(x, tx, tb) => (x, tx, tb),
@@ -656,7 +655,7 @@ impl<S> TypeError<S> {
) -> Self {
TypeError {
context: context.clone(),
- current: current,
+ current,
type_message,
}
}