Skip to content

Commit

Permalink
cargo clippy Rust 1.48
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 22, 2020
1 parent b3b4aba commit 475a68c
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 43 deletions.
6 changes: 3 additions & 3 deletions git-commitgraph/src/file/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ impl TryFrom<&Path> for File {
)));
}

let fan_offset = fan_offset.ok_or_else(|| Error::MissingChunk(OID_FAN_CHUNK_ID))?;
let oid_lookup_offset = oid_lookup_offset.ok_or_else(|| Error::MissingChunk(OID_LOOKUP_CHUNK_ID))?;
let commit_data_offset = commit_data_offset.ok_or_else(|| Error::MissingChunk(COMMIT_DATA_CHUNK_ID))?;
let fan_offset = fan_offset.ok_or(Error::MissingChunk(OID_FAN_CHUNK_ID))?;
let oid_lookup_offset = oid_lookup_offset.ok_or(Error::MissingChunk(OID_LOOKUP_CHUNK_ID))?;
let commit_data_offset = commit_data_offset.ok_or(Error::MissingChunk(COMMIT_DATA_CHUNK_ID))?;
if base_graph_count > 0 && base_graphs_list_offset == None {
return Err(Error::MissingChunk(BASE_GRAPHS_LIST_CHUNK_ID));
}
Expand Down
2 changes: 1 addition & 1 deletion git-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ mod decode {
.as_entry()
.expect("entry")
.value
.ok_or_else(|| Error::NoValue)?,
.ok_or(Error::NoValue)?,
),
)
.map_err(Into::into)
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/loose/object/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn decode(input: &[u8]) -> Result<(object::Kind, u64, usize), Error> {
let header_end = input
.iter()
.position(|&b| b == 0)
.ok_or_else(|| Error::InvalidHeader("Did not find 0 byte in header"))?;
.ok_or(Error::InvalidHeader("Did not find 0 byte in header"))?;
let header = &input[..header_end];
let mut split = header.split(|&b| b == b' ');
match (split.next(), split.next()) {
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/pack/index/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl pack::index::File {
RefDelta { .. } => return Err(Error::IteratorInvariantNoRefDelta),
OfsDelta { base_distance } => {
let base_pack_offset = pack::data::Header::verified_base_pack_offset(pack_offset, base_distance)
.ok_or_else(|| Error::IteratorInvariantBaseOffset {
.ok_or(Error::IteratorInvariantBaseOffset {
pack_offset,
distance: base_distance,
})?;
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/pack/tree/from_offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<T> Tree<T> {
}
RefDelta { base_id } => {
resolve_in_pack_id(base_id.to_borrowed())
.ok_or_else(|| Error::UnresolvedRefDelta { id: base_id })
.ok_or(Error::UnresolvedRefDelta { id: base_id })
.and_then(|base_pack_offset| {
tree.add_child(base_pack_offset, pack_offset, data).map_err(Into::into)
})?;
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/pack/tree/traverse/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
let decompress_from_resolver = |slice: EntrySlice| -> Result<(pack::data::Entry, u64, Vec<u8>), Error> {
let mut bytes_buf = bytes_buf.borrow_mut();
bytes_buf.resize((slice.end - slice.start) as usize, 0);
resolve(slice.clone(), &mut bytes_buf).ok_or_else(|| Error::ResolveFailed {
resolve(slice.clone(), &mut bytes_buf).ok_or(Error::ResolveFailed {
pack_offset: slice.start,
})?;
let entry = pack::data::Entry::from_bytes(&bytes_buf, slice.start);
Expand Down
70 changes: 38 additions & 32 deletions git-protocol/src/fetch/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,41 +213,47 @@ pub(crate) fn from_v1_refs_received_as_part_of_handshake(
if path.is_empty() {
return Err(Error::MalformedV1RefLine(trimmed.to_owned()));
}
if path.ends_with("^{}") {
let (previous_path, tag) = out_refs
.pop()
.and_then(InternalRef::unpack_direct)
.ok_or_else(|| Error::InvariantViolation("Expecting peeled refs to be preceeded by direct refs"))?;
if previous_path != path[..path.len() - "^{}".len()] {
return Err(Error::InvariantViolation(
"Expecting peeled refs to have the same base path as the previous, unpeeled one",
));
match path.strip_suffix("^{}") {
Some(stripped) => {
let (previous_path, tag) =
out_refs
.pop()
.and_then(InternalRef::unpack_direct)
.ok_or(Error::InvariantViolation(
"Expecting peeled refs to be preceded by direct refs",
))?;
if previous_path != stripped {
return Err(Error::InvariantViolation(
"Expecting peeled refs to have the same base path as the previous, unpeeled one",
));
}
out_refs.push(InternalRef::Peeled {
path: previous_path,
tag,
object: owned::Id::from_40_bytes_in_hex(hex_hash.as_bytes())?,
});
}
out_refs.push(InternalRef::Peeled {
path: previous_path,
tag,
object: owned::Id::from_40_bytes_in_hex(hex_hash.as_bytes())?,
});
} else {
let object = owned::Id::from_40_bytes_in_hex(hex_hash.as_bytes())?;
match out_refs
.iter()
.take(number_of_possible_symbolic_refs_for_lookup)
.position(|r| r.lookup_symbol_has_path(path))
{
Some(position) => match out_refs.swap_remove(position) {
InternalRef::SymbolicForLookup { path: _, target } => out_refs.push(InternalRef::Symbolic {
path: path.into(),
None => {
let object = owned::Id::from_40_bytes_in_hex(hex_hash.as_bytes())?;
match out_refs
.iter()
.take(number_of_possible_symbolic_refs_for_lookup)
.position(|r| r.lookup_symbol_has_path(path))
{
Some(position) => match out_refs.swap_remove(position) {
InternalRef::SymbolicForLookup { path: _, target } => out_refs.push(InternalRef::Symbolic {
path: path.into(),
object,
target,
}),
_ => unreachable!("Bug in lookup_symbol_has_path - must return lookup symbols"),
},
None => out_refs.push(InternalRef::Direct {
object,
target,
path: path.into(),
}),
_ => unreachable!("Bug in lookup_symbol_has_path - must return lookup symbols"),
},
None => out_refs.push(InternalRef::Direct {
object,
path: path.into(),
}),
};
};
}
}
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions git-transport/src/client/http/curl/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Handler {
let code = data
.split(|b| *b == b' ')
.nth(1)
.ok_or_else(|| "Expected HTTP/<VERSION> STATUS")?;
.ok_or("Expected HTTP/<VERSION> STATUS")?;
let code = std::str::from_utf8(code)?;
code.parse().map_err(Into::into)
}
Expand All @@ -44,7 +44,7 @@ impl curl::easy::Handler for Handler {
fn write(&mut self, data: &[u8]) -> Result<usize, curl::easy::WriteError> {
drop(self.send_header.take()); // signal header readers to stop trying
match self.send_data.as_mut() {
Some(writer) => writer.write_all(data).map(|_| data.len()).or_else(|_| Ok(0)),
Some(writer) => writer.write_all(data).map(|_| data.len()).or(Ok(0)),
None => Ok(0), // nothing more to receive, reader is done
}
}
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/pack/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub fn pack_or_pack_index(
}
if let Some(verifier) = object_verifier.as_ref() {
let mut obj = verifier.locate(written_id.to_borrowed())
.ok_or_else(|| Error::WrittenFileMissing(written_id))?
.ok_or(Error::WrittenFileMissing(written_id))?
.map_err(|err| Error::WrittenFileCorrupt(err, written_id))?;
obj.verify_checksum(written_id.to_borrowed())?;
}
Expand Down

0 comments on commit 475a68c

Please sign in to comment.