Skip to content

Commit 7d8386f

Browse files
committed
Auto merge of rust-lang#114719 - compiler-errors:rollup-bf1vr51, r=compiler-errors
Rollup of 5 pull requests Successful merges: - rust-lang#114194 (Inline trivial (noop) flush calls) - rust-lang#114257 (Avoid using `ptr::Unique` in `LinkedList` code) - rust-lang#114359 ([library/std] Replace condv while loop with `cvar.wait_while`.) - rust-lang#114402 (Fix documentation of impl From<Vec<T>> for Rc<[T]>) - rust-lang#114715 (Revert clippy lint [`filter_map_bool_then`]) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a07bc13 + 35a76a6 commit 7d8386f

File tree

19 files changed

+31
-224
lines changed

19 files changed

+31
-224
lines changed

library/alloc/src/collections/linked_list.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use core::hash::{Hash, Hasher};
1818
use core::iter::FusedIterator;
1919
use core::marker::PhantomData;
2020
use core::mem;
21-
use core::ptr::{NonNull, Unique};
21+
use core::ptr::NonNull;
2222

2323
use super::SpecExtend;
2424
use crate::alloc::{Allocator, Global};
@@ -168,15 +168,16 @@ impl<T, A: Allocator> LinkedList<T, A> {
168168
/// Adds the given node to the front of the list.
169169
///
170170
/// # Safety
171-
/// `node` must point to a valid node that was boxed using the list's allocator.
171+
/// `node` must point to a valid node that was boxed and leaked using the list's allocator.
172+
/// This method takes ownership of the node, so the pointer should not be used again.
172173
#[inline]
173-
unsafe fn push_front_node(&mut self, node: Unique<Node<T>>) {
174+
unsafe fn push_front_node(&mut self, node: NonNull<Node<T>>) {
174175
// This method takes care not to create mutable references to whole nodes,
175176
// to maintain validity of aliasing pointers into `element`.
176177
unsafe {
177178
(*node.as_ptr()).next = self.head;
178179
(*node.as_ptr()).prev = None;
179-
let node = Some(NonNull::from(node));
180+
let node = Some(node);
180181

181182
match self.head {
182183
None => self.tail = node,
@@ -212,15 +213,16 @@ impl<T, A: Allocator> LinkedList<T, A> {
212213
/// Adds the given node to the back of the list.
213214
///
214215
/// # Safety
215-
/// `node` must point to a valid node that was boxed using the list's allocator.
216+
/// `node` must point to a valid node that was boxed and leaked using the list's allocator.
217+
/// This method takes ownership of the node, so the pointer should not be used again.
216218
#[inline]
217-
unsafe fn push_back_node(&mut self, node: Unique<Node<T>>) {
219+
unsafe fn push_back_node(&mut self, node: NonNull<Node<T>>) {
218220
// This method takes care not to create mutable references to whole nodes,
219221
// to maintain validity of aliasing pointers into `element`.
220222
unsafe {
221223
(*node.as_ptr()).next = None;
222224
(*node.as_ptr()).prev = self.tail;
223-
let node = Some(NonNull::from(node));
225+
let node = Some(node);
224226

225227
match self.tail {
226228
None => self.head = node,
@@ -842,8 +844,8 @@ impl<T, A: Allocator> LinkedList<T, A> {
842844
#[stable(feature = "rust1", since = "1.0.0")]
843845
pub fn push_front(&mut self, elt: T) {
844846
let node = Box::new_in(Node::new(elt), &self.alloc);
845-
let node_ptr = Unique::from(Box::leak(node));
846-
// SAFETY: node_ptr is a unique pointer to a node we boxed with self.alloc
847+
let node_ptr = NonNull::from(Box::leak(node));
848+
// SAFETY: node_ptr is a unique pointer to a node we boxed with self.alloc and leaked
847849
unsafe {
848850
self.push_front_node(node_ptr);
849851
}
@@ -890,8 +892,8 @@ impl<T, A: Allocator> LinkedList<T, A> {
890892
#[stable(feature = "rust1", since = "1.0.0")]
891893
pub fn push_back(&mut self, elt: T) {
892894
let node = Box::new_in(Node::new(elt), &self.alloc);
893-
let node_ptr = Unique::from(Box::leak(node));
894-
// SAFETY: node_ptr is a unique pointer to a node we boxed with self.alloc
895+
let node_ptr = NonNull::from(Box::leak(node));
896+
// SAFETY: node_ptr is a unique pointer to a node we boxed with self.alloc and leaked
895897
unsafe {
896898
self.push_back_node(node_ptr);
897899
}

library/alloc/src/rc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2491,9 +2491,9 @@ impl<T, A: Allocator> From<Vec<T, A>> for Rc<[T], A> {
24912491
///
24922492
/// ```
24932493
/// # use std::rc::Rc;
2494-
/// let original: Box<Vec<i32>> = Box::new(vec![1, 2, 3]);
2495-
/// let shared: Rc<Vec<i32>> = Rc::from(original);
2496-
/// assert_eq!(vec![1, 2, 3], *shared);
2494+
/// let unique: Vec<i32> = vec![1, 2, 3];
2495+
/// let shared: Rc<[i32]> = Rc::from(unique);
2496+
/// assert_eq!(&[1, 2, 3], &shared[..]);
24972497
/// ```
24982498
#[inline]
24992499
fn from(v: Vec<T, A>) -> Rc<[T], A> {

library/std/src/fs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ impl Write for &File {
791791
self.inner.is_write_vectored()
792792
}
793793

794+
#[inline]
794795
fn flush(&mut self) -> io::Result<()> {
795796
self.inner.flush()
796797
}
@@ -836,6 +837,7 @@ impl Write for File {
836837
fn is_write_vectored(&self) -> bool {
837838
(&&*self).is_write_vectored()
838839
}
840+
#[inline]
839841
fn flush(&mut self) -> io::Result<()> {
840842
(&*self).flush()
841843
}
@@ -881,6 +883,7 @@ impl Write for Arc<File> {
881883
fn is_write_vectored(&self) -> bool {
882884
(&**self).is_write_vectored()
883885
}
886+
#[inline]
884887
fn flush(&mut self) -> io::Result<()> {
885888
(&**self).flush()
886889
}

library/std/src/io/readbuf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ impl<'a> Write for BorrowedCursor<'a> {
310310
Ok(buf.len())
311311
}
312312

313+
#[inline]
313314
fn flush(&mut self) -> Result<()> {
314315
Ok(())
315316
}

library/std/src/net/tcp.rs

+2
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ impl Write for TcpStream {
647647
self.0.is_write_vectored()
648648
}
649649

650+
#[inline]
650651
fn flush(&mut self) -> io::Result<()> {
651652
Ok(())
652653
}
@@ -685,6 +686,7 @@ impl Write for &TcpStream {
685686
self.0.is_write_vectored()
686687
}
687688

689+
#[inline]
688690
fn flush(&mut self) -> io::Result<()> {
689691
Ok(())
690692
}

library/std/src/os/unix/net/stream.rs

+1
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ impl<'a> io::Write for &'a UnixStream {
712712
self.0.is_write_vectored()
713713
}
714714

715+
#[inline]
715716
fn flush(&mut self) -> io::Result<()> {
716717
Ok(())
717718
}

library/std/src/process.rs

+2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ impl Write for ChildStdin {
280280
io::Write::is_write_vectored(&&*self)
281281
}
282282

283+
#[inline]
283284
fn flush(&mut self) -> io::Result<()> {
284285
(&*self).flush()
285286
}
@@ -299,6 +300,7 @@ impl Write for &ChildStdin {
299300
self.inner.is_write_vectored()
300301
}
301302

303+
#[inline]
302304
fn flush(&mut self) -> io::Result<()> {
303305
Ok(())
304306
}

library/std/src/sync/barrier.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,8 @@ impl Barrier {
130130
let local_gen = lock.generation_id;
131131
lock.count += 1;
132132
if lock.count < self.num_threads {
133-
// We need a while loop to guard against spurious wakeups.
134-
// https://en.wikipedia.org/wiki/Spurious_wakeup
135-
while local_gen == lock.generation_id {
136-
lock = self.cvar.wait(lock).unwrap();
137-
}
133+
let _guard =
134+
self.cvar.wait_while(lock, |state| local_gen == state.generation_id).unwrap();
138135
BarrierWaitResult(false)
139136
} else {
140137
lock.count = 0;

library/std/src/sys/hermit/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ impl File {
335335
false
336336
}
337337

338+
#[inline]
338339
pub fn flush(&self) -> io::Result<()> {
339340
Ok(())
340341
}

library/std/src/sys/unix/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,7 @@ impl File {
12041204
self.0.write_vectored_at(bufs, offset)
12051205
}
12061206

1207+
#[inline]
12071208
pub fn flush(&self) -> io::Result<()> {
12081209
Ok(())
12091210
}

library/std/src/sys/unix/stdio.rs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl io::Write for Stdout {
5454
true
5555
}
5656

57+
#[inline]
5758
fn flush(&mut self) -> io::Result<()> {
5859
Ok(())
5960
}
@@ -81,6 +82,7 @@ impl io::Write for Stderr {
8182
true
8283
}
8384

85+
#[inline]
8486
fn flush(&mut self) -> io::Result<()> {
8587
Ok(())
8688
}

src/tools/clippy/CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -4844,7 +4844,6 @@ Released 2018-09-13
48444844
[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
48454845
[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file
48464846
[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map
4847-
[`filter_map_bool_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_bool_then
48484847
[`filter_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity
48494848
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
48504849
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next

src/tools/clippy/clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
337337
crate::methods::EXPECT_USED_INFO,
338338
crate::methods::EXTEND_WITH_DRAIN_INFO,
339339
crate::methods::FILETYPE_IS_FILE_INFO,
340-
crate::methods::FILTER_MAP_BOOL_THEN_INFO,
341340
crate::methods::FILTER_MAP_IDENTITY_INFO,
342341
crate::methods::FILTER_MAP_NEXT_INFO,
343342
crate::methods::FILTER_NEXT_INFO,

src/tools/clippy/clippy_lints/src/methods/filter_map_bool_then.rs

-45
This file was deleted.

src/tools/clippy/clippy_lints/src/methods/mod.rs

-34
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ mod expect_used;
2121
mod extend_with_drain;
2222
mod filetype_is_file;
2323
mod filter_map;
24-
mod filter_map_bool_then;
2524
mod filter_map_identity;
2625
mod filter_map_next;
2726
mod filter_next;
@@ -3477,37 +3476,6 @@ declare_clippy_lint! {
34773476
"disallows `.skip(0)`"
34783477
}
34793478

3480-
declare_clippy_lint! {
3481-
/// ### What it does
3482-
/// Checks for usage of `bool::then` in `Iterator::filter_map`.
3483-
///
3484-
/// ### Why is this bad?
3485-
/// This can be written with `filter` then `map` instead, which would reduce nesting and
3486-
/// separates the filtering from the transformation phase. This comes with no cost to
3487-
/// performance and is just cleaner.
3488-
///
3489-
/// ### Limitations
3490-
/// Does not lint `bool::then_some`, as it eagerly evaluates its arguments rather than lazily.
3491-
/// This can create differing behavior, so better safe than sorry.
3492-
///
3493-
/// ### Example
3494-
/// ```rust
3495-
/// # fn really_expensive_fn(i: i32) -> i32 { i }
3496-
/// # let v = vec![];
3497-
/// _ = v.into_iter().filter_map(|i| (i % 2 == 0).then(|| really_expensive_fn(i)));
3498-
/// ```
3499-
/// Use instead:
3500-
/// ```rust
3501-
/// # fn really_expensive_fn(i: i32) -> i32 { i }
3502-
/// # let v = vec![];
3503-
/// _ = v.into_iter().filter(|i| i % 2 == 0).map(|i| really_expensive_fn(i));
3504-
/// ```
3505-
#[clippy::version = "1.72.0"]
3506-
pub FILTER_MAP_BOOL_THEN,
3507-
style,
3508-
"checks for usage of `bool::then` in `Iterator::filter_map`"
3509-
}
3510-
35113479
declare_clippy_lint! {
35123480
/// ### What it does
35133481
/// Looks for calls to `RwLock::write` where the lock is only used for reading.
@@ -3676,7 +3644,6 @@ impl_lint_pass!(Methods => [
36763644
FORMAT_COLLECT,
36773645
STRING_LIT_CHARS_ANY,
36783646
ITER_SKIP_ZERO,
3679-
FILTER_MAP_BOOL_THEN,
36803647
READONLY_WRITE_LOCK
36813648
]);
36823649

@@ -3955,7 +3922,6 @@ impl Methods {
39553922
},
39563923
("filter_map", [arg]) => {
39573924
unnecessary_filter_map::check(cx, expr, arg, name);
3958-
filter_map_bool_then::check(cx, expr, arg, call_span);
39593925
filter_map_identity::check(cx, expr, arg, span);
39603926
},
39613927
("find_map", [arg]) => {

src/tools/clippy/clippy_utils/src/paths.rs

-2
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,3 @@ pub const OPTION_EXPECT: [&str; 4] = ["core", "option", "Option", "expect"];
163163
pub const FORMATTER: [&str; 3] = ["core", "fmt", "Formatter"];
164164
pub const DEBUG_STRUCT: [&str; 4] = ["core", "fmt", "builders", "DebugStruct"];
165165
pub const ORD_CMP: [&str; 4] = ["core", "cmp", "Ord", "cmp"];
166-
#[expect(clippy::invalid_paths)] // not sure why it thinks this, it works so
167-
pub const BOOL_THEN: [&str; 4] = ["core", "bool", "<impl bool>", "then"];

src/tools/clippy/tests/ui/filter_map_bool_then.fixed

-44
This file was deleted.

0 commit comments

Comments
 (0)