summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--abnf_to_pest/src/lib.rs12
-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
-rw-r--r--dhall_core/src/core.rs14
-rw-r--r--dhall_core/src/lib.rs3
-rw-r--r--dhall_core/src/parser.rs6
-rw-r--r--dhall_core/src/printer.rs2
-rw-r--r--dhall_generator/src/quote.rs4
10 files changed, 62 insertions, 50 deletions
diff --git a/abnf_to_pest/src/lib.rs b/abnf_to_pest/src/lib.rs
index b2fcbbd..88f5930 100644
--- a/abnf_to_pest/src/lib.rs
+++ b/abnf_to_pest/src/lib.rs
@@ -81,9 +81,11 @@ impl Pretty for Range {
use abnf::abnf::Range::*;
Doc::text(match self {
Range(x, y) => {
- format!("'{}'..'{}'", format_char(x), format_char(y))
+ format!("'{}'..'{}'", format_char(*x), format_char(*y))
+ }
+ OneOf(v) => {
+ format!("\"{}\"", v.iter().map(|x| format_char(*x)).join(""))
}
- OneOf(v) => format!("\"{}\"", v.iter().map(format_char).join("")),
})
}
}
@@ -105,9 +107,9 @@ pub fn escape_rulename(x: &str) -> String {
}
}
-fn format_char(x: &u64) -> String {
- if *x <= u64::from(u8::max_value()) {
- let x: u8 = *x as u8;
+fn format_char(x: u64) -> String {
+ if x <= u64::from(u8::max_value()) {
+ let x: u8 = x as u8;
if x.is_ascii_graphic() {
let x: char = x as char;
if x != '"' && x != '\'' && x != '\\' {
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,
}
}
diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs
index 89506ec..39dea37 100644
--- a/dhall_core/src/core.rs
+++ b/dhall_core/src/core.rs
@@ -25,7 +25,7 @@ pub struct NaiveDouble(f64);
impl PartialEq for NaiveDouble {
fn eq(&self, other: &Self) -> bool {
- return self.0.to_bits() == other.0.to_bits();
+ self.0.to_bits() == other.0.to_bits()
}
}
@@ -283,7 +283,7 @@ impl<S, A> Expr<S, A> {
F: Fn(&A) -> B,
{
let recurse = |e: &Expr<S, A>| -> Expr<S, B> { e.map_embed(map_embed) };
- self.map_shallow(recurse, |x| x.clone(), map_embed, |x| x.clone())
+ self.map_shallow(recurse, S::clone, map_embed, Label::clone)
}
#[inline(always)]
@@ -315,7 +315,7 @@ impl<S, A> Expr<S, A> {
F: Fn(&Label) -> Label,
{
let recurse = |e: &Self| -> Self { e.map_label(map_label) };
- self.map_shallow(recurse, |x| x.clone(), |x| x.clone(), map_label)
+ self.map_shallow(recurse, S::clone, A::clone, map_label)
}
#[inline(always)]
@@ -333,10 +333,10 @@ impl<S: Clone, A: Clone> Expr<S, Expr<S, A>> {
match self {
ExprF::Embed(e) => e.clone(),
e => e.map_shallow(
- |e| e.squash_embed(),
- |x| x.clone(),
+ <Expr<S, Expr<S, A>>>::squash_embed,
+ S::clone,
|_| unreachable!(),
- |x| x.clone(),
+ Label::clone,
),
}
}
@@ -368,7 +368,7 @@ impl<SE, L, N, E> ExprF<SE, L, N, E> {
fn opt<T>(x: &Option<T>) -> Option<&T> {
x.as_ref()
}
- fn vec<T>(x: &Vec<T>) -> Vec<&T> {
+ fn vec<T>(x: &[T]) -> Vec<&T> {
x.iter().collect()
}
fn btmap<L: Ord, SE>(x: &BTreeMap<L, SE>) -> BTreeMap<&L, &SE> {
diff --git a/dhall_core/src/lib.rs b/dhall_core/src/lib.rs
index 2042b04..9fddd1f 100644
--- a/dhall_core/src/lib.rs
+++ b/dhall_core/src/lib.rs
@@ -4,7 +4,8 @@
#![allow(
clippy::many_single_char_names,
clippy::should_implement_trait,
- clippy::new_without_default
+ clippy::new_without_default,
+ clippy::type_complexity
)]
mod core;
diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs
index 41a2ce7..9d77f52 100644
--- a/dhall_core/src/parser.rs
+++ b/dhall_core/src/parser.rs
@@ -180,7 +180,7 @@ macro_rules! make_parser {
);
($( $submac:ident!( $name:ident<$o:ty> $($args:tt)* ); )*) => (
- #[allow(non_camel_case_types, dead_code)]
+ #[allow(non_camel_case_types, dead_code, clippy::large_enum_variant)]
#[derive(Debug)]
enum ParsedValue<'a> {
$( $name($o), )*
@@ -283,7 +283,7 @@ make_parser! {
[label(l)] => {
if crate::Builtin::parse(&String::from(&l)).is_some() {
Err(
- format!("Builtin names are not allowed as bound variables")
+ "Builtin names are not allowed as bound variables".to_string()
)?
}
l
@@ -323,7 +323,7 @@ make_parser! {
// "uXXXX"
use std::convert::TryFrom;
let c = u16::from_str_radix(&s[1..5], 16).unwrap();
- let c = char::try_from(c as u32).unwrap();
+ let c = char::try_from(u32::from(c)).unwrap();
std::iter::once(c).collect()
}
}
diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs
index 746b863..4f56fb6 100644
--- a/dhall_core/src/printer.rs
+++ b/dhall_core/src/printer.rs
@@ -318,7 +318,7 @@ impl Display for NaiveDouble {
f.write_str("NaN")
} else {
let s = format!("{}", v);
- if s.contains("e") || s.contains(".") {
+ if s.contains('e') || s.contains('.') {
f.write_str(&s)
} else {
write!(f, "{}.0", s)
diff --git a/dhall_generator/src/quote.rs b/dhall_generator/src/quote.rs
index 8fce89d..8552def 100644
--- a/dhall_generator/src/quote.rs
+++ b/dhall_generator/src/quote.rs
@@ -125,7 +125,7 @@ fn quote_subexpr(
|l, e| quote_subexpr(e, &ctx.insert(l.clone(), ())),
|_| unreachable!(),
|_| unreachable!(),
- |l| l.clone(),
+ Label::clone,
) {
Var(V(ref s, n)) => {
match ctx.lookup(s, n) {
@@ -160,7 +160,7 @@ fn quote_expr(expr: &Expr<X, X>, ctx: &Context<Label, ()>) -> TokenStream {
|l, e| quote_subexpr(e, &ctx.insert(l.clone(), ())),
|_| unreachable!(),
|_| unreachable!(),
- |l| l.clone(),
+ Label::clone,
) {
Var(V(ref s, n)) => {
match ctx.lookup(s, n) {