summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadrieril2020-03-17 23:01:35 +0000
committerNadrieril2020-03-17 23:14:32 +0000
commitc22e161f7bd97d4f6c063513cc051f6af2683d84 (patch)
tree7ebb20c3e9db1657a731c5871716e82685dcab6d
parent681dad33cf27b2be4f4b3cefd83998af1d7eefb2 (diff)
Run clippy
-rw-r--r--abnf_to_pest/src/lib.rs2
-rw-r--r--dhall/build.rs7
-rw-r--r--dhall/src/error/builder.rs5
-rw-r--r--dhall/src/lib.rs10
-rw-r--r--dhall/src/semantics/builtins.rs6
-rw-r--r--dhall/src/semantics/nze/env.rs4
-rw-r--r--dhall/src/semantics/nze/nir.rs10
-rw-r--r--dhall/src/semantics/nze/normalize.rs43
-rw-r--r--dhall/src/semantics/resolve/env.rs2
-rw-r--r--dhall/src/semantics/resolve/hir.rs6
-rw-r--r--dhall/src/semantics/resolve/resolve.rs22
-rw-r--r--dhall/src/semantics/tck/env.rs12
-rw-r--r--dhall/src/semantics/tck/typecheck.rs2
-rw-r--r--dhall/src/syntax/ast/map.rs4
-rw-r--r--dhall/src/syntax/binary/decode.rs131
-rw-r--r--dhall/src/syntax/binary/encode.rs4
-rw-r--r--dhall/src/syntax/text/parser.rs35
-rw-r--r--dhall/src/syntax/text/printer.rs2
18 files changed, 178 insertions, 129 deletions
diff --git a/abnf_to_pest/src/lib.rs b/abnf_to_pest/src/lib.rs
index 8615fc2..ba8bdf2 100644
--- a/abnf_to_pest/src/lib.rs
+++ b/abnf_to_pest/src/lib.rs
@@ -110,7 +110,7 @@ pub fn escape_rulename(x: &str) -> String {
{
x + "_"
} else {
- x.clone()
+ x
}
}
diff --git a/dhall/build.rs b/dhall/build.rs
index 366f8a4..e6ed0da 100644
--- a/dhall/build.rs
+++ b/dhall/build.rs
@@ -52,7 +52,7 @@ fn dhall_files_in_dir<'a>(
.filter_map(move |path| {
let path = path.path().strip_prefix(dir).unwrap();
let ext = path.extension()?;
- if ext != &OsString::from(filetype.to_ext()) {
+ if *ext != OsString::from(filetype.to_ext()) {
return None;
}
let path = path.to_string_lossy();
@@ -152,6 +152,7 @@ fn generate_tests() -> std::io::Result<()> {
let spec_tests_dirs =
vec![Path::new("../dhall-lang/tests/"), Path::new("tests/")];
+ #[allow(clippy::nonminimal_bool)]
let tests = vec![
TestFeature {
module_name: "parser_success",
@@ -363,7 +364,9 @@ fn convert_abnf_to_pest() -> std::io::Result<()> {
for line in BufReader::new(File::open(visibility_path)?).lines() {
let line = line?;
if line.len() >= 2 && &line[0..2] == "# " {
- rules.get_mut(&line[2..]).map(|x| x.silent = true);
+ if let Some(x) = rules.get_mut(&line[2..]) {
+ x.silent = true;
+ }
}
}
diff --git a/dhall/src/error/builder.rs b/dhall/src/error/builder.rs
index b4c5073..f444518 100644
--- a/dhall/src/error/builder.rs
+++ b/dhall/src/error/builder.rs
@@ -116,11 +116,12 @@ impl ErrorBuilder {
}
// TODO: handle multiple files
+ #[allow(clippy::drop_ref)]
pub fn format(&mut self) -> String {
if self.consumed {
panic!("tried to format the same ErrorBuilder twice")
}
- let this = std::mem::replace(self, ErrorBuilder::default());
+ let this = std::mem::take(self);
self.consumed = true;
drop(self); // Get rid of the self reference so we don't use it by mistake.
@@ -154,7 +155,7 @@ impl ErrorBuilder {
};
let dl = DisplayList::from(snippet);
let dlf = DisplayListFormatter::new(true, false);
- format!("{}", dlf.format(&dl))
+ dlf.format(&dl)
}
}
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs
index d68ad6b..d7d7f05 100644
--- a/dhall/src/lib.rs
+++ b/dhall/src/lib.rs
@@ -1,12 +1,10 @@
#![doc(html_root_url = "https://docs.rs/dhall/0.3.0")]
#![feature(never_type)]
#![allow(
- clippy::type_complexity,
- clippy::infallible_destructuring_match,
- clippy::many_single_char_names,
- clippy::match_wild_err_arm,
- clippy::redundant_closure,
- clippy::ptr_arg
+ clippy::int_plus_one, // Comes from pest_consume macro
+ clippy::module_inception,
+ clippy::needless_lifetimes,
+ clippy::useless_format
)]
mod tests;
diff --git a/dhall/src/semantics/builtins.rs b/dhall/src/semantics/builtins.rs
index 61de0c7..803630b 100644
--- a/dhall/src/semantics/builtins.rs
+++ b/dhall/src/semantics/builtins.rs
@@ -33,7 +33,7 @@ impl BuiltinClosure<Nir> {
pub fn apply(&self, a: Nir) -> NirKind {
use std::iter::once;
- let args = self.args.iter().cloned().chain(once(a.clone())).collect();
+ let args = self.args.iter().cloned().chain(once(a)).collect();
apply_builtin(self.b, args, self.env.clone())
}
/// This doesn't break the invariant because we already checked that the appropriate arguments
@@ -415,7 +415,7 @@ fn apply_builtin(b: Builtin, args: Vec<Nir>, env: NzEnv) -> NirKind {
(Builtin::ListBuild, [t, f]) => {
let list_t = Nir::from_builtin(Builtin::List).app(t.clone());
Ret::Nir(
- f.app(list_t.clone())
+ f.app(list_t)
.app(
make_closure(make_closure!(
λ(T : Type) ->
@@ -443,7 +443,7 @@ fn apply_builtin(b: Builtin, args: Vec<Nir>, env: NzEnv) -> NirKind {
let optional_t =
Nir::from_builtin(Builtin::Optional).app(t.clone());
Ret::Nir(
- f.app(optional_t.clone())
+ f.app(optional_t)
.app(
make_closure(make_closure!(
λ(T : Type) ->
diff --git a/dhall/src/semantics/nze/env.rs b/dhall/src/semantics/nze/env.rs
index 55050ed..ef2bee6 100644
--- a/dhall/src/semantics/nze/env.rs
+++ b/dhall/src/semantics/nze/env.rs
@@ -72,14 +72,14 @@ impl<Type: Clone> ValEnv<Type> {
env.items.push(EnvItem::Replaced(e, ty));
env
}
- pub fn lookup_val(&self, var: &AlphaVar) -> NirKind {
+ pub fn lookup_val(&self, var: AlphaVar) -> NirKind {
let idx = self.items.len() - 1 - var.idx();
match &self.items[idx] {
EnvItem::Kept(_) => NirKind::Var(NzVar::new(idx)),
EnvItem::Replaced(x, _) => x.kind().clone(),
}
}
- pub fn lookup_ty(&self, var: &AlphaVar) -> Type {
+ pub fn lookup_ty(&self, var: AlphaVar) -> Type {
let idx = self.items.len() - 1 - var.idx();
match &self.items[idx] {
EnvItem::Kept(ty) | EnvItem::Replaced(_, ty) => ty.clone(),
diff --git a/dhall/src/semantics/nze/nir.rs b/dhall/src/semantics/nze/nir.rs
index 4ed66b7..32ef590 100644
--- a/dhall/src/semantics/nze/nir.rs
+++ b/dhall/src/semantics/nze/nir.rs
@@ -162,8 +162,8 @@ impl Nir {
)
};
- let hir = match &*self.kind() {
- NirKind::Var(v) => HirKind::Var(venv.lookup(v)),
+ let hir = match self.kind() {
+ NirKind::Var(v) => HirKind::Var(venv.lookup(*v)),
NirKind::AppliedBuiltin(closure) => closure.to_hirkind(venv),
self_kind => HirKind::Expr(match self_kind {
NirKind::Var(..) | NirKind::AppliedBuiltin(..) => {
@@ -317,13 +317,13 @@ impl NirKind {
}
}
NirKind::UnionType(kts) | NirKind::UnionConstructor(_, kts) => {
- for x in kts.values().flat_map(|opt| opt) {
+ for x in kts.values().flatten() {
x.normalize();
}
}
NirKind::UnionLit(_, v, kts) => {
v.normalize();
- for x in kts.values().flat_map(|opt| opt) {
+ for x in kts.values().flatten() {
x.normalize();
}
}
@@ -503,7 +503,7 @@ impl std::fmt::Debug for Nir {
if let NirKind::Const(c) = kind {
return write!(fmt, "{:?}", c);
}
- let mut x = fmt.debug_struct(&format!("Nir@WHNF"));
+ let mut x = fmt.debug_struct("Nir");
x.field("kind", kind);
x.finish()
}
diff --git a/dhall/src/semantics/nze/normalize.rs b/dhall/src/semantics/nze/normalize.rs
index 27862ee..08e3e87 100644
--- a/dhall/src/semantics/nze/normalize.rs
+++ b/dhall/src/semantics/nze/normalize.rs
@@ -209,6 +209,7 @@ fn apply_binop<'a>(o: BinOp, x: &'a Nir, y: &'a Nir) -> Option<Ret<'a>> {
})
}
+#[allow(clippy::cognitive_complexity)]
pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
use LitKind::Bool;
use NirKind::{
@@ -286,17 +287,17 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
None => Ret::Expr(expr),
},
- ExprKind::Field(ref v, ref l) => match v.kind() {
- RecordLit(kvs) => match kvs.get(l) {
+ ExprKind::Field(ref v, ref field) => match v.kind() {
+ RecordLit(kvs) => match kvs.get(field) {
Some(r) => Ret::Nir(r.clone()),
None => Ret::Expr(expr),
},
UnionType(kts) => {
- Ret::NirKind(UnionConstructor(l.clone(), kts.clone()))
+ Ret::NirKind(UnionConstructor(field.clone(), kts.clone()))
}
PartialExpr(ExprKind::Projection(x, _)) => {
return normalize_one_layer(
- ExprKind::Field(x.clone(), l.clone()),
+ ExprKind::Field(x.clone(), field.clone()),
env,
)
}
@@ -305,31 +306,31 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
x,
y,
)) => match (x.kind(), y.kind()) {
- (_, RecordLit(kvs)) => match kvs.get(l) {
+ (_, RecordLit(kvs)) => match kvs.get(field) {
Some(r) => Ret::Nir(r.clone()),
None => {
return normalize_one_layer(
- ExprKind::Field(x.clone(), l.clone()),
+ ExprKind::Field(x.clone(), field.clone()),
env,
)
}
},
- (RecordLit(kvs), _) => match kvs.get(l) {
+ (RecordLit(kvs), _) => match kvs.get(field) {
Some(r) => Ret::Expr(ExprKind::Field(
Nir::from_kind(PartialExpr(ExprKind::BinOp(
BinOp::RightBiasedRecordMerge,
Nir::from_kind(RecordLit(
- Some((l.clone(), r.clone()))
+ Some((field.clone(), r.clone()))
.into_iter()
.collect(),
)),
y.clone(),
))),
- l.clone(),
+ field.clone(),
)),
None => {
return normalize_one_layer(
- ExprKind::Field(y.clone(), l.clone()),
+ ExprKind::Field(y.clone(), field.clone()),
env,
)
}
@@ -338,42 +339,42 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
},
PartialExpr(ExprKind::BinOp(BinOp::RecursiveRecordMerge, x, y)) => {
match (x.kind(), y.kind()) {
- (RecordLit(kvs), _) => match kvs.get(l) {
+ (RecordLit(kvs), _) => match kvs.get(field) {
Some(r) => Ret::Expr(ExprKind::Field(
Nir::from_kind(PartialExpr(ExprKind::BinOp(
BinOp::RecursiveRecordMerge,
Nir::from_kind(RecordLit(
- Some((l.clone(), r.clone()))
+ Some((field.clone(), r.clone()))
.into_iter()
.collect(),
)),
y.clone(),
))),
- l.clone(),
+ field.clone(),
)),
None => {
return normalize_one_layer(
- ExprKind::Field(y.clone(), l.clone()),
+ ExprKind::Field(y.clone(), field.clone()),
env,
)
}
},
- (_, RecordLit(kvs)) => match kvs.get(l) {
+ (_, RecordLit(kvs)) => match kvs.get(field) {
Some(r) => Ret::Expr(ExprKind::Field(
Nir::from_kind(PartialExpr(ExprKind::BinOp(
BinOp::RecursiveRecordMerge,
x.clone(),
Nir::from_kind(RecordLit(
- Some((l.clone(), r.clone()))
+ Some((field.clone(), r.clone()))
.into_iter()
.collect(),
)),
))),
- l.clone(),
+ field.clone(),
)),
None => {
return normalize_one_layer(
- ExprKind::Field(x.clone(), l.clone()),
+ ExprKind::Field(x.clone(), field.clone()),
env,
)
}
@@ -452,7 +453,7 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
}
RecordLit(kvs) => Ret::NirKind(NEListLit(
kvs.iter()
- .sorted_by_key(|(k, _)| k.clone())
+ .sorted_by_key(|(k, _)| *k)
.map(|(k, v)| {
let mut rec = HashMap::new();
rec.insert("mapKey".into(), Nir::from_text(k));
@@ -476,13 +477,13 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
/// Normalize Hir into WHNF
pub(crate) fn normalize_hir_whnf(env: &NzEnv, hir: &Hir) -> NirKind {
match hir.kind() {
- HirKind::Var(var) => env.lookup_val(var),
+ HirKind::Var(var) => env.lookup_val(*var),
HirKind::Import(hir, _) => normalize_hir_whnf(env, hir),
HirKind::Expr(ExprKind::Lam(binder, annot, body)) => {
let annot = annot.eval(env);
NirKind::LamClosure {
binder: Binder::new(binder.clone()),
- annot: annot,
+ annot,
closure: Closure::new(env, body.clone()),
}
}
diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs
index 5a7f139..fe8c178 100644
--- a/dhall/src/semantics/resolve/env.rs
+++ b/dhall/src/semantics/resolve/env.rs
@@ -51,7 +51,7 @@ impl NameEnv {
.nth(*idx)?;
Some(AlphaVar::new(idx))
}
- pub fn label_var(&self, var: &AlphaVar) -> V {
+ pub fn label_var(&self, var: AlphaVar) -> V {
let name = &self.names[self.names.len() - 1 - var.idx()];
let idx = self
.names
diff --git a/dhall/src/semantics/resolve/hir.rs b/dhall/src/semantics/resolve/hir.rs
index 317708a..fa2989f 100644
--- a/dhall/src/semantics/resolve/hir.rs
+++ b/dhall/src/semantics/resolve/hir.rs
@@ -30,7 +30,7 @@ impl AlphaVar {
pub(crate) fn new(idx: usize) -> Self {
AlphaVar { idx }
}
- pub(crate) fn idx(&self) -> usize {
+ pub(crate) fn idx(self) -> usize {
self.idx
}
}
@@ -100,7 +100,7 @@ fn hir_to_expr(
) -> NormalizedExpr {
let kind = match hir.kind() {
HirKind::Var(v) if opts.alpha => ExprKind::Var(V("_".into(), v.idx())),
- HirKind::Var(v) => ExprKind::Var(env.label_var(v)),
+ HirKind::Var(v) => ExprKind::Var(env.label_var(*v)),
HirKind::Import(hir, _) => {
return hir_to_expr(hir, opts, &mut NameEnv::new())
}
@@ -110,7 +110,7 @@ fn hir_to_expr(
env.insert_mut(l);
}
let e = hir_to_expr(hir, opts, env);
- if let Some(_) = l {
+ if l.is_some() {
env.remove_mut();
}
e
diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs
index d29271d..f3fda4b 100644
--- a/dhall/src/semantics/resolve/resolve.rs
+++ b/dhall/src/semantics/resolve/resolve.rs
@@ -46,13 +46,13 @@ impl ImportLocation {
) -> Result<ImportLocation, Error> {
Ok(match target {
ImportTarget::Local(prefix, path) => {
- self.chain_local(prefix, path)?
+ self.chain_local(*prefix, path)?
}
ImportTarget::Remote(remote) => {
if sanity_check {
if let ImportLocation::Remote(..) = self {
// TODO: allow if CORS check passes
- Err(ImportError::SanityCheck)?
+ return Err(ImportError::SanityCheck.into());
}
}
let mut url = Url::parse(&format!(
@@ -66,7 +66,7 @@ impl ImportLocation {
ImportTarget::Env(var_name) => {
if sanity_check {
if let ImportLocation::Remote(..) = self {
- Err(ImportError::SanityCheck)?
+ return Err(ImportError::SanityCheck.into());
}
}
ImportLocation::Env(var_name.clone())
@@ -77,7 +77,7 @@ impl ImportLocation {
fn chain_local(
&self,
- prefix: &FilePrefix,
+ prefix: FilePrefix,
path: &FilePath,
) -> Result<ImportLocation, Error> {
Ok(match self {
@@ -146,11 +146,11 @@ impl ImportLocation {
ImportLocation::Env(var_name) => {
let val = match env::var(var_name) {
Ok(val) => val,
- Err(_) => Err(ImportError::MissingEnvVar)?,
+ Err(_) => return Err(ImportError::MissingEnvVar.into()),
};
Parsed::parse_str(&val)?
}
- ImportLocation::Missing => Err(ImportError::Missing)?,
+ ImportLocation::Missing => return Err(ImportError::Missing.into()),
})
}
@@ -162,9 +162,9 @@ impl ImportLocation {
}
ImportLocation::Env(var_name) => match env::var(var_name) {
Ok(val) => val,
- Err(_) => Err(ImportError::MissingEnvVar)?,
+ Err(_) => return Err(ImportError::MissingEnvVar.into()),
},
- ImportLocation::Missing => Err(ImportError::Missing)?,
+ ImportLocation::Missing => return Err(ImportError::Missing.into()),
})
}
@@ -199,7 +199,7 @@ fn make_aslocation_uniontype() -> Expr {
let mut union = DupTreeMap::default();
union.insert("Local".into(), Some(text_type.clone()));
union.insert("Remote".into(), Some(text_type.clone()));
- union.insert("Environment".into(), Some(text_type.clone()));
+ union.insert("Environment".into(), Some(text_type));
union.insert("Missing".into(), None);
mkexpr(ExprKind::UnionType(union))
}
@@ -298,7 +298,7 @@ fn traverse_resolve_expr(
name_env.insert_mut(l);
}
let hir = traverse_resolve_expr(name_env, e, f)?;
- if let Some(_) = l {
+ if l.is_some() {
name_env.remove_mut();
}
Ok::<_, Error>(hir)
@@ -395,7 +395,7 @@ impl<SE: Copy> Canonicalize for ImportTarget<SE> {
authority: url.authority.clone(),
path: url.path.canonicalize(),
query: url.query.clone(),
- headers: url.headers.clone(),
+ headers: url.headers,
}),
ImportTarget::Env(name) => ImportTarget::Env(name.to_string()),
ImportTarget::Missing => ImportTarget::Missing,
diff --git a/dhall/src/semantics/tck/env.rs b/dhall/src/semantics/tck/env.rs
index 17b3cfe..6dd5076 100644
--- a/dhall/src/semantics/tck/env.rs
+++ b/dhall/src/semantics/tck/env.rs
@@ -21,18 +21,18 @@ impl VarEnv {
pub fn from_size(size: usize) -> Self {
VarEnv { size }
}
- pub fn size(&self) -> usize {
+ pub fn size(self) -> usize {
self.size
}
- pub fn insert(&self) -> Self {
+ pub fn insert(self) -> Self {
VarEnv {
size: self.size + 1,
}
}
- pub fn lookup(&self, var: &NzVar) -> AlphaVar {
+ pub fn lookup(self, var: NzVar) -> AlphaVar {
self.lookup_fallible(var).unwrap()
}
- pub fn lookup_fallible(&self, var: &NzVar) -> Option<AlphaVar> {
+ pub fn lookup_fallible(self, var: NzVar) -> Option<AlphaVar> {
let idx = self.size.checked_sub(var.idx() + 1)?;
Some(AlphaVar::new(idx))
}
@@ -67,8 +67,8 @@ impl TyEnv {
items: self.items.insert_value(e, ty),
}
}
- pub fn lookup(&self, var: &AlphaVar) -> Type {
- self.items.lookup_ty(&var)
+ pub fn lookup(&self, var: AlphaVar) -> Type {
+ self.items.lookup_ty(var)
}
}
diff --git a/dhall/src/semantics/tck/typecheck.rs b/dhall/src/semantics/tck/typecheck.rs
index 319bb9d..365df25 100644
--- a/dhall/src/semantics/tck/typecheck.rs
+++ b/dhall/src/semantics/tck/typecheck.rs
@@ -712,7 +712,7 @@ pub(crate) fn type_with<'hir>(
annot: Option<Type>,
) -> Result<Tir<'hir>, TypeError> {
let tir = match hir.kind() {
- HirKind::Var(var) => Tir::from_hir(hir, env.lookup(var)),
+ HirKind::Var(var) => Tir::from_hir(hir, env.lookup(*var)),
HirKind::Import(_, ty) => Tir::from_hir(hir, ty.clone()),
HirKind::Expr(ExprKind::Var(_)) => {
unreachable!("Hir should contain no unresolved variables")
diff --git a/dhall/src/syntax/ast/map.rs b/dhall/src/syntax/ast/map.rs
index 8b896c0..7a88204 100644
--- a/dhall/src/syntax/ast/map.rs
+++ b/dhall/src/syntax/ast/map.rs
@@ -73,7 +73,7 @@ mod dup_tree_map {
>,
>;
- fn zip_repeat<'a, K, I>((k, iter): (K, I)) -> ZipRepeatIter<(K, I)>
+ fn zip_repeat<K, I>((k, iter): (K, I)) -> ZipRepeatIter<(K, I)>
where
K: Clone,
I: IntoIterator,
@@ -229,7 +229,7 @@ mod dup_tree_set {
self.map.is_empty()
}
- pub fn iter<'a>(&'a self) -> Iter<'a, K> {
+ pub fn iter(&self) -> Iter<'_, K> {
self.map.iter().map(drop_second)
}
}
diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs
index bebc800..2ecd7e0 100644
--- a/dhall/src/syntax/binary/decode.rs
+++ b/dhall/src/syntax/binary/decode.rs
@@ -36,7 +36,11 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
"Type" => Const(Const::Type),
"Kind" => Const(Const::Kind),
"Sort" => Const(Const::Sort),
- _ => Err(DecodeError::WrongFormatError("builtin".to_owned()))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(
+ "builtin".to_owned(),
+ ))
+ }
},
},
U64(n) => Var(V(Label::from("_"), *n as usize)),
@@ -45,19 +49,19 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
Array(vec) => match vec.as_slice() {
[String(l), U64(n)] => {
if l.as_str() == "_" {
- Err(DecodeError::WrongFormatError(
+ return Err(DecodeError::WrongFormatError(
"`_` variable was encoded incorrectly".to_owned(),
- ))?
+ ));
}
let l = Label::from(l.as_str());
Var(V(l, *n as usize))
}
[U64(0), f, args @ ..] => {
if args.is_empty() {
- Err(DecodeError::WrongFormatError(
+ return Err(DecodeError::WrongFormatError(
"Function application must have at least one argument"
.to_owned(),
- ))?
+ ));
}
let mut f = cbor_value_to_dhall(&f)?;
for a in args {
@@ -73,9 +77,9 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
}
[U64(1), String(l), x, y] => {
if l.as_str() == "_" {
- Err(DecodeError::WrongFormatError(
+ return Err(DecodeError::WrongFormatError(
"`_` variable was encoded incorrectly".to_owned(),
- ))?
+ ));
}
let x = cbor_value_to_dhall(&x)?;
let y = cbor_value_to_dhall(&y)?;
@@ -89,9 +93,9 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
}
[U64(2), String(l), x, y] => {
if l.as_str() == "_" {
- Err(DecodeError::WrongFormatError(
+ return Err(DecodeError::WrongFormatError(
"`_` variable was encoded incorrectly".to_owned(),
- ))?
+ ));
}
let x = cbor_value_to_dhall(&x)?;
let y = cbor_value_to_dhall(&y)?;
@@ -122,7 +126,9 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
11 => ImportAlt,
12 => Equivalence,
_ => {
- Err(DecodeError::WrongFormatError("binop".to_owned()))?
+ return Err(DecodeError::WrongFormatError(
+ "binop".to_owned(),
+ ))
}
};
BinOp(op, x, y)
@@ -185,9 +191,9 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
let y = cbor_value_to_dhall(&y)?;
ProjectionByExpr(x, y)
} else {
- Err(DecodeError::WrongFormatError(
+ return Err(DecodeError::WrongFormatError(
"projection-by-expr".to_owned(),
- ))?
+ ));
}
}
[U64(10), x, rest @ ..] => {
@@ -207,9 +213,11 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
let map = cbor_map_to_dhall_opt_map(map)?;
UnionType(map)
}
- [U64(12), ..] => Err(DecodeError::WrongFormatError(
- "Union literals are not supported anymore".to_owned(),
- ))?,
+ [U64(12), ..] => {
+ return Err(DecodeError::WrongFormatError(
+ "Union literals are not supported anymore".to_owned(),
+ ))
+ }
[U64(14), x, y, z] => {
let x = cbor_value_to_dhall(&x)?;
let y = cbor_value_to_dhall(&y)?;
@@ -228,9 +236,11 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
let x = cbor_value_to_dhall(&x)?;
let y = match y {
String(s) => s.clone(),
- _ => Err(DecodeError::WrongFormatError(
- "text".to_owned(),
- ))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(
+ "text".to_owned(),
+ ))
+ }
};
Ok((x, y))
})
@@ -246,10 +256,12 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
0 => ImportMode::Code,
1 => ImportMode::RawText,
2 => ImportMode::Location,
- _ => Err(DecodeError::WrongFormatError(format!(
- "import/mode/unknown_mode: {:?}",
- mode
- )))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(format!(
+ "import/mode/unknown_mode: {:?}",
+ mode
+ )))
+ }
};
let hash = match hash {
Null => None,
@@ -257,14 +269,18 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
[18, 32, rest @ ..] => {
Some(Hash::SHA256(rest.to_vec()))
}
- _ => Err(DecodeError::WrongFormatError(format!(
- "import/hash/unknown_multihash: {:?}",
- bytes
- )))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(format!(
+ "import/hash/unknown_multihash: {:?}",
+ bytes
+ )))
+ }
},
- _ => Err(DecodeError::WrongFormatError(
- "import/hash/should_be_bytes".to_owned(),
- ))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(
+ "import/hash/should_be_bytes".to_owned(),
+ ))
+ }
};
let mut rest = rest.iter();
let location = match scheme {
@@ -279,22 +295,28 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
let x = cbor_value_to_dhall(&x)?;
Some(x)
}
- _ => Err(DecodeError::WrongFormatError(
- "import/remote/headers".to_owned(),
- ))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(
+ "import/remote/headers".to_owned(),
+ ))
+ }
};
let authority = match rest.next() {
Some(String(s)) => s.to_owned(),
- _ => Err(DecodeError::WrongFormatError(
- "import/remote/authority".to_owned(),
- ))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(
+ "import/remote/authority".to_owned(),
+ ))
+ }
};
let query = match rest.next_back() {
Some(Null) => None,
Some(String(s)) => Some(s.to_owned()),
- _ => Err(DecodeError::WrongFormatError(
- "import/remote/query".to_owned(),
- ))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(
+ "import/remote/query".to_owned(),
+ ))
+ }
};
let file_path = rest
.map(|s| match s.as_string() {
@@ -319,9 +341,11 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
3 => FilePrefix::Here,
4 => FilePrefix::Parent,
5 => FilePrefix::Home,
- _ => Err(DecodeError::WrongFormatError(
- "import/local/prefix".to_owned(),
- ))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(
+ "import/local/prefix".to_owned(),
+ ))
+ }
};
let file_path = rest
.map(|s| match s.as_string() {
@@ -337,16 +361,20 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
6 => {
let env = match rest.next() {
Some(String(s)) => s.to_owned(),
- _ => Err(DecodeError::WrongFormatError(
- "import/env".to_owned(),
- ))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(
+ "import/env".to_owned(),
+ ))
+ }
};
ImportTarget::Env(env)
}
7 => ImportTarget::Missing,
- _ => Err(DecodeError::WrongFormatError(
- "import/type".to_owned(),
- ))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(
+ "import/type".to_owned(),
+ ))
+ }
};
Import(syntax::Import {
mode,
@@ -399,9 +427,14 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
let x = cbor_value_to_dhall(&x)?;
EmptyListLit(x)
}
- _ => Err(DecodeError::WrongFormatError(format!("{:?}", data)))?,
+ _ => {
+ return Err(DecodeError::WrongFormatError(format!(
+ "{:?}",
+ data
+ )))
+ }
},
- _ => Err(DecodeError::WrongFormatError(format!("{:?}", data)))?,
+ _ => return Err(DecodeError::WrongFormatError(format!("{:?}", data))),
}))
}
diff --git a/dhall/src/syntax/binary/encode.rs b/dhall/src/syntax/binary/encode.rs
index 2484d8d..9e6948e 100644
--- a/dhall/src/syntax/binary/encode.rs
+++ b/dhall/src/syntax/binary/encode.rs
@@ -12,7 +12,7 @@ use crate::syntax::{
pub(crate) fn encode(expr: &Expr) -> Result<Vec<u8>, EncodeError> {
serde_cbor::ser::to_vec(&Serialize::Expr(expr))
- .map_err(|e| EncodeError::CBORError(e))
+ .map_err(EncodeError::CBORError)
}
enum Serialize<'a> {
@@ -126,7 +126,7 @@ where
use syntax::InterpolatedTextContents::{Expr, Text};
ser.collect_seq(once(tag(18)).chain(xs.iter().map(|x| match x {
Expr(x) => expr(x),
- Text(x) => cbor(String(x.clone())),
+ Text(x) => cbor(String(x)),
})))
}
RecordType(map) => ser_seq!(ser; tag(7), RecordDupMap(map)),
diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs
index b3c2c40..5686300 100644
--- a/dhall/src/syntax/text/parser.rs
+++ b/dhall/src/syntax/text/parser.rs
@@ -267,9 +267,10 @@ impl DhallParser {
};
if s.len() > 8 {
- Err(input.error(format!(
+ return Err(input.error(
"Escape sequences can't have more than 8 chars"
- )))?
+ .to_string(),
+ ));
}
// pad with zeroes
@@ -282,9 +283,12 @@ impl DhallParser {
let bytes: &[u8] = &hex::decode(s).unwrap();
let i = u32::from_be_bytes(bytes.try_into().unwrap());
match i {
- 0xD800..=0xDFFF => Err(input.error(format!(
- "Escape sequences can't contain surrogate pairs"
- )))?,
+ 0xD800..=0xDFFF => {
+ return Err(input.error(
+ "Escape sequences can't contain surrogate pairs"
+ .to_string(),
+ ))
+ }
0x0FFFE..=0x0FFFF
| 0x1FFFE..=0x1FFFF
| 0x2FFFE..=0x2FFFF
@@ -301,9 +305,12 @@ impl DhallParser {
| 0xDFFFE..=0xDFFFF
| 0xEFFFE..=0xEFFFF
| 0xFFFFE..=0xFFFFF
- | 0x10_FFFE..=0x10_FFFF => Err(input.error(format!(
- "Escape sequences can't contain non-characters"
- )))?,
+ | 0x10_FFFE..=0x10_FFFF => {
+ return Err(input.error(
+ "Escape sequences can't contain non-characters"
+ .to_string(),
+ ))
+ }
_ => {}
}
let c: char = i.try_into().unwrap();
@@ -389,7 +396,9 @@ impl DhallParser {
"Kind" => Const(crate::syntax::Const::Kind),
"Sort" => Const(crate::syntax::Const::Sort),
_ => {
- Err(input.error(format!("Unrecognized builtin: '{}'", s)))?
+ return Err(
+ input.error(format!("Unrecognized builtin: '{}'", s))
+ )
}
},
};
@@ -620,7 +629,9 @@ impl DhallParser {
let protocol = &s[..6];
let hash = &s[7..];
if protocol != "sha256" {
- Err(input.error(format!("Unknown hashing protocol '{}'", protocol)))?
+ return Err(
+ input.error(format!("Unknown hashing protocol '{}'", protocol))
+ );
}
Ok(Hash::SHA256(hex::decode(hash).unwrap()))
}
@@ -767,7 +778,9 @@ impl DhallParser {
bool_eq => BoolEQ,
bool_ne => BoolNE,
equivalent => Equivalence,
- r => Err(op.error(format!("Rule {:?} isn't an operator", r)))?,
+ r => {
+ return Err(op.error(format!("Rule {:?} isn't an operator", r)))
+ }
};
Ok(spanned_union(l.span(), r.span(), BinOp(op, l, r)))
diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs
index a8991b0..e9584bb 100644
--- a/dhall/src/syntax/text/printer.rs
+++ b/dhall/src/syntax/text/printer.rs
@@ -29,7 +29,7 @@ impl<'a> PhasedExpr<'a> {
impl UnspannedExpr {
// Annotate subexpressions with the appropriate phase, defaulting to Base
- fn annotate_with_phases<'a>(&'a self) -> ExprKind<PhasedExpr<'a>> {
+ fn annotate_with_phases(&self) -> ExprKind<PhasedExpr<'_>> {
use crate::syntax::ExprKind::*;
use PrintPhase::*;
let with_base = self.map_ref(|e| PhasedExpr(e, Base));