diff --git a/src/call.rs b/src/call.rs index a18f05da91..9aa3ae667f 100644 --- a/src/call.rs +++ b/src/call.rs @@ -44,9 +44,7 @@ pub fn c_try(ret: libc::c_int) -> Result { } pub fn last_error(code: libc::c_int) -> Error { - // nowadays this unwrap is safe as `Error::last_error` always returns - // `Some`. - Error::last_error(code).unwrap() + Error::last_error(code) } mod impls { diff --git a/src/error.rs b/src/error.rs index e57bae27dd..076667af98 100644 --- a/src/error.rs +++ b/src/error.rs @@ -32,12 +32,7 @@ impl Error { /// /// The `code` argument typically comes from the return value of a function /// call. This code will later be returned from the `code` function. - /// - /// Historically this function returned `Some` or `None` based on the return - /// value of `git_error_last` but nowadays it always returns `Some` so it's - /// safe to unwrap the return value. This API will change in the next major - /// version. - pub fn last_error(code: c_int) -> Option { + pub fn last_error(code: c_int) -> Error { crate::init(); unsafe { // Note that whenever libgit2 returns an error any negative value @@ -64,7 +59,7 @@ impl Error { Error::from_raw(code, ptr) }; raw::git_error_clear(); - Some(err) + err } } diff --git a/src/indexer.rs b/src/indexer.rs index 0aaf353d53..ddca5fa2d5 100644 --- a/src/indexer.rs +++ b/src/indexer.rs @@ -188,10 +188,7 @@ impl io::Write for Indexer<'_> { let res = raw::git_indexer_append(self.raw, ptr, len, &mut self.progress); if res < 0 { - Err(io::Error::new( - io::ErrorKind::Other, - Error::last_error(res).unwrap(), - )) + Err(io::Error::new(io::ErrorKind::Other, Error::last_error(res))) } else { Ok(buf.len()) } diff --git a/src/odb.rs b/src/odb.rs index d01c70ae67..2019908c48 100644 --- a/src/odb.rs +++ b/src/odb.rs @@ -458,7 +458,7 @@ impl<'repo> OdbPackwriter<'repo> { }; if res < 0 { - Err(Error::last_error(res).unwrap()) + Err(Error::last_error(res)) } else { Ok(res) } diff --git a/src/repo.rs b/src/repo.rs index efdb49259e..074955f623 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -860,7 +860,7 @@ impl Repository { match value { 0 => Ok(false), 1 => Ok(true), - _ => Err(Error::last_error(value).unwrap()), + _ => Err(Error::last_error(value)), } } } diff --git a/src/tracing.rs b/src/tracing.rs index f06460d240..9872571dd3 100644 --- a/src/tracing.rs +++ b/src/tracing.rs @@ -76,8 +76,7 @@ pub fn trace_set(level: TraceLevel, cb: TracingCb) -> Result<(), Error> { let return_code: c_int = unsafe { raw::git_trace_set(level.raw(), Some(tracing_cb_c)) }; if return_code != 0 { - // Unwrap here is fine since `Error::last_error` always returns `Some`. - Err(Error::last_error(return_code).unwrap()) + Err(Error::last_error(return_code)) } else { Ok(()) }