Skip to content

Commit 61b447d

Browse files
Rollup merge of rust-lang#130115 - eduardosm:needless-returns-libs, r=workingjubilee
Remove needless returns detected by clippy in libraries
2 parents 1d371d0 + 5f3fdd1 commit 61b447d

File tree

9 files changed

+20
-19
lines changed

9 files changed

+20
-19
lines changed

library/alloc/src/collections/vec_deque/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
7373
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
7474
let remaining = self.i1.advance_by(n);
7575
match remaining {
76-
Ok(()) => return Ok(()),
76+
Ok(()) => Ok(()),
7777
Err(n) => {
7878
mem::swap(&mut self.i1, &mut self.i2);
7979
self.i1.advance_by(n.get())
@@ -144,7 +144,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
144144

145145
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
146146
match self.i2.advance_back_by(n) {
147-
Ok(()) => return Ok(()),
147+
Ok(()) => Ok(()),
148148
Err(n) => {
149149
mem::swap(&mut self.i1, &mut self.i2);
150150
self.i2.advance_back_by(n.get())

library/alloc/src/collections/vec_deque/iter_mut.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
6464

6565
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
6666
match self.i1.advance_by(n) {
67-
Ok(()) => return Ok(()),
67+
Ok(()) => Ok(()),
6868
Err(remaining) => {
6969
mem::swap(&mut self.i1, &mut self.i2);
7070
self.i1.advance_by(remaining.get())
@@ -135,7 +135,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
135135

136136
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
137137
match self.i2.advance_back_by(n) {
138-
Ok(()) => return Ok(()),
138+
Ok(()) => Ok(()),
139139
Err(remaining) => {
140140
mem::swap(&mut self.i1, &mut self.i2);
141141
self.i2.advance_back_by(remaining.get())

library/alloc/src/vec/in_place_collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const fn needs_realloc<SRC, DEST>(src_cap: usize, dst_cap: usize) -> bool {
208208

209209
// type layouts don't guarantee a fit, so do a runtime check to see if
210210
// the allocations happen to match
211-
return src_cap > 0 && src_cap * mem::size_of::<SRC>() != dst_cap * mem::size_of::<DEST>();
211+
src_cap > 0 && src_cap * mem::size_of::<SRC>() != dst_cap * mem::size_of::<DEST>()
212212
}
213213

214214
/// This provides a shorthand for the source type since local type aliases aren't a thing.

library/alloc/src/vec/into_iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,11 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
288288

289289
// Safety: `len` is larger than the array size. Copy a fixed amount here to fully initialize
290290
// the array.
291-
return unsafe {
291+
unsafe {
292292
ptr::copy_nonoverlapping(self.ptr.as_ptr(), raw_ary.as_mut_ptr() as *mut T, N);
293293
self.ptr = self.ptr.add(N);
294294
Ok(raw_ary.transpose().assume_init())
295-
};
295+
}
296296
}
297297

298298
fn fold<B, F>(mut self, mut accum: B, mut f: F) -> B

library/core/src/ptr/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ impl<Dyn: ?Sized> DynMetadata<Dyn> {
187187
// Consider a reference like `&(i32, dyn Send)`: the vtable will only store the size of the
188188
// `Send` part!
189189
// SAFETY: DynMetadata always contains a valid vtable pointer
190-
return unsafe { crate::intrinsics::vtable_size(self.vtable_ptr() as *const ()) };
190+
unsafe { crate::intrinsics::vtable_size(self.vtable_ptr() as *const ()) }
191191
}
192192

193193
/// Returns the alignment of the type associated with this vtable.
194194
#[inline]
195195
pub fn align_of(self) -> usize {
196196
// SAFETY: DynMetadata always contains a valid vtable pointer
197-
return unsafe { crate::intrinsics::vtable_align(self.vtable_ptr() as *const ()) };
197+
unsafe { crate::intrinsics::vtable_align(self.vtable_ptr() as *const ()) }
198198
}
199199

200200
/// Returns the size and alignment together as a `Layout`

library/core/src/str/pattern.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ fn simd_contains(needle: &str, haystack: &str) -> Option<bool> {
18141814
}
18151815
mask &= !(1 << trailing);
18161816
}
1817-
return false;
1817+
false
18181818
};
18191819

18201820
let test_chunk = |idx| -> u16 {
@@ -1830,7 +1830,7 @@ fn simd_contains(needle: &str, haystack: &str) -> Option<bool> {
18301830
let both = eq_first.bitand(eq_last);
18311831
let mask = both.to_bitmask() as u16;
18321832

1833-
return mask;
1833+
mask
18341834
};
18351835

18361836
let mut i = 0;

library/std/src/sys/pal/unix/linux/pidfd.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) struct PidFd(FileDesc);
1313

1414
impl PidFd {
1515
pub fn kill(&self) -> io::Result<()> {
16-
return cvt(unsafe {
16+
cvt(unsafe {
1717
libc::syscall(
1818
libc::SYS_pidfd_send_signal,
1919
self.0.as_raw_fd(),
@@ -22,15 +22,15 @@ impl PidFd {
2222
0,
2323
)
2424
})
25-
.map(drop);
25+
.map(drop)
2626
}
2727

2828
pub fn wait(&self) -> io::Result<ExitStatus> {
2929
let mut siginfo: libc::siginfo_t = unsafe { crate::mem::zeroed() };
3030
cvt(unsafe {
3131
libc::waitid(libc::P_PIDFD, self.0.as_raw_fd() as u32, &mut siginfo, libc::WEXITED)
3232
})?;
33-
return Ok(ExitStatus::from_waitid_siginfo(siginfo));
33+
Ok(ExitStatus::from_waitid_siginfo(siginfo))
3434
}
3535

3636
pub fn try_wait(&self) -> io::Result<Option<ExitStatus>> {
@@ -45,9 +45,10 @@ impl PidFd {
4545
)
4646
})?;
4747
if unsafe { siginfo.si_pid() } == 0 {
48-
return Ok(None);
48+
Ok(None)
49+
} else {
50+
Ok(Some(ExitStatus::from_waitid_siginfo(siginfo)))
4951
}
50-
return Ok(Some(ExitStatus::from_waitid_siginfo(siginfo)));
5152
}
5253
}
5354

library/std/src/sys/pal/wasi/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl OpenOptions {
265265
pub fn new() -> OpenOptions {
266266
let mut base = OpenOptions::default();
267267
base.dirflags = wasi::LOOKUPFLAGS_SYMLINK_FOLLOW;
268-
return base;
268+
base
269269
}
270270

271271
pub fn read(&mut self, read: bool) {
@@ -382,7 +382,7 @@ impl OpenOptions {
382382
base |= wasi::RIGHTS_PATH_UNLINK_FILE;
383383
base |= wasi::RIGHTS_POLL_FD_READWRITE;
384384

385-
return base;
385+
base
386386
}
387387

388388
fn rights_inheriting(&self) -> wasi::Rights {

library/std/src/sys/pal/wasi/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn hashmap_random_keys() -> (u64, u64) {
115115
let len = mem::size_of_val(&ret);
116116
wasi::random_get(base, len).expect("random_get failure");
117117
}
118-
return ret;
118+
ret
119119
}
120120

121121
#[inline]

0 commit comments

Comments
 (0)