Skip to content

Commit dfdf78f

Browse files
committed
ran cargo clippy --fix -- -Wclippy::use_self
1 parent 53442d4 commit dfdf78f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+848
-812
lines changed

src/apply.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ extern "C" fn hunk_cb_c(hunk: *const raw::git_diff_hunk, data: *mut c_void) -> c
8686
.unwrap_or(-1)
8787
}
8888

89+
impl<'cb> Default for ApplyOptions<'cb> {
90+
fn default() -> Self {
91+
Self::new()
92+
}
93+
}
94+
8995
impl<'cb> ApplyOptions<'cb> {
9096
/// Creates a new set of empty options (zeroed).
9197
pub fn new() -> Self {
@@ -102,7 +108,7 @@ impl<'cb> ApplyOptions<'cb> {
102108
}
103109

104110
fn flag(&mut self, opt: raw::git_apply_flags_t, val: bool) -> &mut Self {
105-
let opt = opt as u32;
111+
let opt = opt;
106112
if val {
107113
self.raw.flags |= opt;
108114
} else {

src/blame.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'repo> Blame<'repo> {
9494
}
9595

9696
impl<'blame> BlameHunk<'blame> {
97-
unsafe fn from_raw_const(raw: *const raw::git_blame_hunk) -> BlameHunk<'blame> {
97+
unsafe fn from_raw_const(raw: *const raw::git_blame_hunk) -> Self {
9898
BlameHunk {
9999
raw: raw as *mut raw::git_blame_hunk,
100100
_marker: marker::PhantomData,
@@ -160,7 +160,7 @@ impl<'blame> BlameHunk<'blame> {
160160

161161
/// Returns number of lines in this hunk.
162162
pub fn lines_in_hunk(&self) -> usize {
163-
unsafe { (*self.raw).lines_in_hunk as usize }
163+
unsafe { (*self.raw).lines_in_hunk }
164164
}
165165
}
166166

@@ -172,7 +172,7 @@ impl Default for BlameOptions {
172172

173173
impl BlameOptions {
174174
/// Initialize options
175-
pub fn new() -> BlameOptions {
175+
pub fn new() -> Self {
176176
unsafe {
177177
let mut raw: raw::git_blame_options = mem::zeroed();
178178
assert_eq!(
@@ -184,7 +184,7 @@ impl BlameOptions {
184184
}
185185
}
186186

187-
fn flag(&mut self, opt: u32, val: bool) -> &mut BlameOptions {
187+
fn flag(&mut self, opt: u32, val: bool) -> &mut Self {
188188
if val {
189189
self.raw.flags |= opt;
190190
} else {
@@ -194,69 +194,69 @@ impl BlameOptions {
194194
}
195195

196196
/// Track lines that have moved within a file.
197-
pub fn track_copies_same_file(&mut self, opt: bool) -> &mut BlameOptions {
197+
pub fn track_copies_same_file(&mut self, opt: bool) -> &mut Self {
198198
self.flag(raw::GIT_BLAME_TRACK_COPIES_SAME_FILE, opt)
199199
}
200200

201201
/// Track lines that have moved across files in the same commit.
202-
pub fn track_copies_same_commit_moves(&mut self, opt: bool) -> &mut BlameOptions {
202+
pub fn track_copies_same_commit_moves(&mut self, opt: bool) -> &mut Self {
203203
self.flag(raw::GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES, opt)
204204
}
205205

206206
/// Track lines that have been copied from another file that exists
207207
/// in the same commit.
208-
pub fn track_copies_same_commit_copies(&mut self, opt: bool) -> &mut BlameOptions {
208+
pub fn track_copies_same_commit_copies(&mut self, opt: bool) -> &mut Self {
209209
self.flag(raw::GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES, opt)
210210
}
211211

212212
/// Track lines that have been copied from another file that exists
213213
/// in any commit.
214-
pub fn track_copies_any_commit_copies(&mut self, opt: bool) -> &mut BlameOptions {
214+
pub fn track_copies_any_commit_copies(&mut self, opt: bool) -> &mut Self {
215215
self.flag(raw::GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES, opt)
216216
}
217217

218218
/// Restrict the search of commits to those reachable following only
219219
/// the first parents.
220-
pub fn first_parent(&mut self, opt: bool) -> &mut BlameOptions {
220+
pub fn first_parent(&mut self, opt: bool) -> &mut Self {
221221
self.flag(raw::GIT_BLAME_FIRST_PARENT, opt)
222222
}
223223

224224
/// Use mailmap file to map author and committer names and email addresses
225225
/// to canonical real names and email addresses. The mailmap will be read
226226
/// from the working directory, or HEAD in a bare repository.
227-
pub fn use_mailmap(&mut self, opt: bool) -> &mut BlameOptions {
227+
pub fn use_mailmap(&mut self, opt: bool) -> &mut Self {
228228
self.flag(raw::GIT_BLAME_USE_MAILMAP, opt)
229229
}
230230

231231
/// Ignore whitespace differences.
232-
pub fn ignore_whitespace(&mut self, opt: bool) -> &mut BlameOptions {
232+
pub fn ignore_whitespace(&mut self, opt: bool) -> &mut Self {
233233
self.flag(raw::GIT_BLAME_IGNORE_WHITESPACE, opt)
234234
}
235235

236236
/// Setter for the id of the newest commit to consider.
237-
pub fn newest_commit(&mut self, id: Oid) -> &mut BlameOptions {
237+
pub fn newest_commit(&mut self, id: Oid) -> &mut Self {
238238
unsafe {
239239
self.raw.newest_commit = *id.raw();
240240
}
241241
self
242242
}
243243

244244
/// Setter for the id of the oldest commit to consider.
245-
pub fn oldest_commit(&mut self, id: Oid) -> &mut BlameOptions {
245+
pub fn oldest_commit(&mut self, id: Oid) -> &mut Self {
246246
unsafe {
247247
self.raw.oldest_commit = *id.raw();
248248
}
249249
self
250250
}
251251

252252
/// The first line in the file to blame.
253-
pub fn min_line(&mut self, lineno: usize) -> &mut BlameOptions {
253+
pub fn min_line(&mut self, lineno: usize) -> &mut Self {
254254
self.raw.min_line = lineno;
255255
self
256256
}
257257

258258
/// The last line in the file to blame.
259-
pub fn max_line(&mut self, lineno: usize) -> &mut BlameOptions {
259+
pub fn max_line(&mut self, lineno: usize) -> &mut Self {
260260
self.raw.max_line = lineno;
261261
self
262262
}
@@ -265,7 +265,7 @@ impl BlameOptions {
265265
impl<'repo> Binding for Blame<'repo> {
266266
type Raw = *mut raw::git_blame;
267267

268-
unsafe fn from_raw(raw: *mut raw::git_blame) -> Blame<'repo> {
268+
unsafe fn from_raw(raw: *mut raw::git_blame) -> Self {
269269
Blame {
270270
raw,
271271
_marker: marker::PhantomData,
@@ -286,7 +286,7 @@ impl<'repo> Drop for Blame<'repo> {
286286
impl<'blame> Binding for BlameHunk<'blame> {
287287
type Raw = *mut raw::git_blame_hunk;
288288

289-
unsafe fn from_raw(raw: *mut raw::git_blame_hunk) -> BlameHunk<'blame> {
289+
unsafe fn from_raw(raw: *mut raw::git_blame_hunk) -> Self {
290290
BlameHunk {
291291
raw,
292292
_marker: marker::PhantomData,
@@ -301,8 +301,8 @@ impl<'blame> Binding for BlameHunk<'blame> {
301301
impl Binding for BlameOptions {
302302
type Raw = *mut raw::git_blame_options;
303303

304-
unsafe fn from_raw(opts: *mut raw::git_blame_options) -> BlameOptions {
305-
BlameOptions { raw: *opts }
304+
unsafe fn from_raw(opts: *mut raw::git_blame_options) -> Self {
305+
Self { raw: *opts }
306306
}
307307

308308
fn raw(&self) -> *mut raw::git_blame_options {

src/blob.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'repo> Blob<'repo> {
5454
impl<'repo> Binding for Blob<'repo> {
5555
type Raw = *mut raw::git_blob;
5656

57-
unsafe fn from_raw(raw: *mut raw::git_blob) -> Blob<'repo> {
57+
unsafe fn from_raw(raw: *mut raw::git_blob) -> Self {
5858
Blob {
5959
raw,
6060
_marker: marker::PhantomData,
@@ -108,7 +108,7 @@ impl<'repo> BlobWriter<'repo> {
108108
impl<'repo> Binding for BlobWriter<'repo> {
109109
type Raw = *mut raw::git_writestream;
110110

111-
unsafe fn from_raw(raw: *mut raw::git_writestream) -> BlobWriter<'repo> {
111+
unsafe fn from_raw(raw: *mut raw::git_writestream) -> Self {
112112
BlobWriter {
113113
raw,
114114
need_cleanup: true,
@@ -139,12 +139,12 @@ impl<'repo> io::Write for BlobWriter<'repo> {
139139
if let Some(f) = (*self.raw).write {
140140
let res = f(self.raw, buf.as_ptr() as *const _, buf.len());
141141
if res < 0 {
142-
Err(io::Error::new(io::ErrorKind::Other, "Write error"))
142+
Err(io::Error::other("Write error"))
143143
} else {
144144
Ok(buf.len())
145145
}
146146
} else {
147-
Err(io::Error::new(io::ErrorKind::Other, "no write callback"))
147+
Err(io::Error::other("no write callback"))
148148
}
149149
}
150150
}

src/branch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'repo> Branch<'repo> {
6868
}
6969

7070
/// Move/rename an existing local branch reference.
71-
pub fn rename(&mut self, new_branch_name: &str, force: bool) -> Result<Branch<'repo>, Error> {
71+
pub fn rename(&mut self, new_branch_name: &str, force: bool) -> Result<Self, Error> {
7272
let mut ret = ptr::null_mut();
7373
let new_branch_name = CString::new(new_branch_name)?;
7474
unsafe {
@@ -100,7 +100,7 @@ impl<'repo> Branch<'repo> {
100100

101101
/// Return the reference supporting the remote tracking branch, given a
102102
/// local branch reference.
103-
pub fn upstream(&self) -> Result<Branch<'repo>, Error> {
103+
pub fn upstream(&self) -> Result<Self, Error> {
104104
let mut ret = ptr::null_mut();
105105
unsafe {
106106
try_call!(raw::git_branch_upstream(&mut ret, &*self.get().raw()));
@@ -129,7 +129,7 @@ impl<'repo> Branches<'repo> {
129129
///
130130
/// This function is unsafe as it is not guaranteed that `raw` is a valid
131131
/// pointer.
132-
pub unsafe fn from_raw(raw: *mut raw::git_branch_iterator) -> Branches<'repo> {
132+
pub unsafe fn from_raw(raw: *mut raw::git_branch_iterator) -> Self {
133133
Branches {
134134
raw,
135135
_marker: marker::PhantomData,

src/buf.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Default for Buf {
2222

2323
impl Buf {
2424
/// Creates a new empty buffer.
25-
pub fn new() -> Buf {
25+
pub fn new() -> Self {
2626
crate::init();
2727
unsafe {
2828
Binding::from_raw(&mut raw::git_buf {
@@ -37,27 +37,27 @@ impl Buf {
3737
///
3838
/// Returns `None` if the buffer is not valid utf-8.
3939
pub fn as_str(&self) -> Option<&str> {
40-
str::from_utf8(&**self).ok()
40+
str::from_utf8(self).ok()
4141
}
4242
}
4343

4444
impl Deref for Buf {
4545
type Target = [u8];
4646
fn deref(&self) -> &[u8] {
47-
unsafe { slice::from_raw_parts(self.raw.ptr as *const u8, self.raw.size as usize) }
47+
unsafe { slice::from_raw_parts(self.raw.ptr as *const u8, self.raw.size) }
4848
}
4949
}
5050

5151
impl DerefMut for Buf {
5252
fn deref_mut(&mut self) -> &mut [u8] {
53-
unsafe { slice::from_raw_parts_mut(self.raw.ptr as *mut u8, self.raw.size as usize) }
53+
unsafe { slice::from_raw_parts_mut(self.raw.ptr as *mut u8, self.raw.size) }
5454
}
5555
}
5656

5757
impl Binding for Buf {
5858
type Raw = *mut raw::git_buf;
59-
unsafe fn from_raw(raw: *mut raw::git_buf) -> Buf {
60-
Buf { raw: *raw }
59+
unsafe fn from_raw(raw: *mut raw::git_buf) -> Self {
60+
Self { raw: *raw }
6161
}
6262
fn raw(&self) -> *mut raw::git_buf {
6363
&self.raw as *const _ as *mut _

0 commit comments

Comments
 (0)