diff options
author | Nadrieril Feneanar | 2020-03-17 23:36:12 +0000 |
---|---|---|
committer | GitHub | 2020-03-17 23:36:12 +0000 |
commit | 6c18f2b698874d125532625e2bedaa6621962074 (patch) | |
tree | dc8eec542bdbbb39bc24b8b43e1abf20490e6702 /dhall/src/syntax | |
parent | 681dad33cf27b2be4f4b3cefd83998af1d7eefb2 (diff) | |
parent | 715a941333887c4a29c2c49102bf1455d88a5417 (diff) |
Merge pull request #144 from Nadrieril/clippy
Clippy
Diffstat (limited to '')
-rw-r--r-- | dhall/src/syntax/ast/map.rs | 4 | ||||
-rw-r--r-- | dhall/src/syntax/binary/decode.rs | 131 | ||||
-rw-r--r-- | dhall/src/syntax/binary/encode.rs | 4 | ||||
-rw-r--r-- | dhall/src/syntax/text/parser.rs | 35 | ||||
-rw-r--r-- | dhall/src/syntax/text/printer.rs | 2 |
5 files changed, 111 insertions, 65 deletions
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)); |