Skip to content

Rollup of 5 pull requests #114719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions library/alloc/src/collections/linked_list.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ use core::hash::{Hash, Hasher};
use core::iter::FusedIterator;
use core::marker::PhantomData;
use core::mem;
use core::ptr::{NonNull, Unique};
use core::ptr::NonNull;

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

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

match self.tail {
None => self.head = node,
@@ -842,8 +844,8 @@ impl<T, A: Allocator> LinkedList<T, A> {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_front(&mut self, elt: T) {
let node = Box::new_in(Node::new(elt), &self.alloc);
let node_ptr = Unique::from(Box::leak(node));
// SAFETY: node_ptr is a unique pointer to a node we boxed with self.alloc
let node_ptr = NonNull::from(Box::leak(node));
// SAFETY: node_ptr is a unique pointer to a node we boxed with self.alloc and leaked
unsafe {
self.push_front_node(node_ptr);
}
@@ -890,8 +892,8 @@ impl<T, A: Allocator> LinkedList<T, A> {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_back(&mut self, elt: T) {
let node = Box::new_in(Node::new(elt), &self.alloc);
let node_ptr = Unique::from(Box::leak(node));
// SAFETY: node_ptr is a unique pointer to a node we boxed with self.alloc
let node_ptr = NonNull::from(Box::leak(node));
// SAFETY: node_ptr is a unique pointer to a node we boxed with self.alloc and leaked
unsafe {
self.push_back_node(node_ptr);
}
6 changes: 3 additions & 3 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
@@ -2491,9 +2491,9 @@ impl<T, A: Allocator> From<Vec<T, A>> for Rc<[T], A> {
///
/// ```
/// # use std::rc::Rc;
/// let original: Box<Vec<i32>> = Box::new(vec![1, 2, 3]);
/// let shared: Rc<Vec<i32>> = Rc::from(original);
/// assert_eq!(vec![1, 2, 3], *shared);
/// let unique: Vec<i32> = vec![1, 2, 3];
/// let shared: Rc<[i32]> = Rc::from(unique);
/// assert_eq!(&[1, 2, 3], &shared[..]);
/// ```
#[inline]
fn from(v: Vec<T, A>) -> Rc<[T], A> {
3 changes: 3 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
@@ -791,6 +791,7 @@ impl Write for &File {
self.inner.is_write_vectored()
}

#[inline]
fn flush(&mut self) -> io::Result<()> {
self.inner.flush()
}
@@ -836,6 +837,7 @@ impl Write for File {
fn is_write_vectored(&self) -> bool {
(&&*self).is_write_vectored()
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
(&*self).flush()
}
@@ -881,6 +883,7 @@ impl Write for Arc<File> {
fn is_write_vectored(&self) -> bool {
(&**self).is_write_vectored()
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
(&**self).flush()
}
1 change: 1 addition & 0 deletions library/std/src/io/readbuf.rs
Original file line number Diff line number Diff line change
@@ -310,6 +310,7 @@ impl<'a> Write for BorrowedCursor<'a> {
Ok(buf.len())
}

#[inline]
fn flush(&mut self) -> Result<()> {
Ok(())
}
2 changes: 2 additions & 0 deletions library/std/src/net/tcp.rs
Original file line number Diff line number Diff line change
@@ -647,6 +647,7 @@ impl Write for TcpStream {
self.0.is_write_vectored()
}

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

#[inline]
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
1 change: 1 addition & 0 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
@@ -712,6 +712,7 @@ impl<'a> io::Write for &'a UnixStream {
self.0.is_write_vectored()
}

#[inline]
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
2 changes: 2 additions & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
@@ -280,6 +280,7 @@ impl Write for ChildStdin {
io::Write::is_write_vectored(&&*self)
}

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

#[inline]
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
7 changes: 2 additions & 5 deletions library/std/src/sync/barrier.rs
Original file line number Diff line number Diff line change
@@ -130,11 +130,8 @@ impl Barrier {
let local_gen = lock.generation_id;
lock.count += 1;
if lock.count < self.num_threads {
// We need a while loop to guard against spurious wakeups.
// https://en.wikipedia.org/wiki/Spurious_wakeup
while local_gen == lock.generation_id {
lock = self.cvar.wait(lock).unwrap();
}
let _guard =
self.cvar.wait_while(lock, |state| local_gen == state.generation_id).unwrap();
BarrierWaitResult(false)
} else {
lock.count = 0;
1 change: 1 addition & 0 deletions library/std/src/sys/hermit/fs.rs
Original file line number Diff line number Diff line change
@@ -335,6 +335,7 @@ impl File {
false
}

#[inline]
pub fn flush(&self) -> io::Result<()> {
Ok(())
}
1 change: 1 addition & 0 deletions library/std/src/sys/unix/fs.rs
Original file line number Diff line number Diff line change
@@ -1204,6 +1204,7 @@ impl File {
self.0.write_vectored_at(bufs, offset)
}

#[inline]
pub fn flush(&self) -> io::Result<()> {
Ok(())
}
2 changes: 2 additions & 0 deletions library/std/src/sys/unix/stdio.rs
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ impl io::Write for Stdout {
true
}

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

#[inline]
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
1 change: 0 additions & 1 deletion src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4844,7 +4844,6 @@ Released 2018-09-13
[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file
[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map
[`filter_map_bool_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_bool_then
[`filter_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
1 change: 0 additions & 1 deletion src/tools/clippy/clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
@@ -337,7 +337,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::methods::EXPECT_USED_INFO,
crate::methods::EXTEND_WITH_DRAIN_INFO,
crate::methods::FILETYPE_IS_FILE_INFO,
crate::methods::FILTER_MAP_BOOL_THEN_INFO,
crate::methods::FILTER_MAP_IDENTITY_INFO,
crate::methods::FILTER_MAP_NEXT_INFO,
crate::methods::FILTER_NEXT_INFO,
45 changes: 0 additions & 45 deletions src/tools/clippy/clippy_lints/src/methods/filter_map_bool_then.rs

This file was deleted.

34 changes: 0 additions & 34 deletions src/tools/clippy/clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ mod expect_used;
mod extend_with_drain;
mod filetype_is_file;
mod filter_map;
mod filter_map_bool_then;
mod filter_map_identity;
mod filter_map_next;
mod filter_next;
@@ -3477,37 +3476,6 @@ declare_clippy_lint! {
"disallows `.skip(0)`"
}

declare_clippy_lint! {
/// ### What it does
/// Checks for usage of `bool::then` in `Iterator::filter_map`.
///
/// ### Why is this bad?
/// This can be written with `filter` then `map` instead, which would reduce nesting and
/// separates the filtering from the transformation phase. This comes with no cost to
/// performance and is just cleaner.
///
/// ### Limitations
/// Does not lint `bool::then_some`, as it eagerly evaluates its arguments rather than lazily.
/// This can create differing behavior, so better safe than sorry.
///
/// ### Example
/// ```rust
/// # fn really_expensive_fn(i: i32) -> i32 { i }
/// # let v = vec![];
/// _ = v.into_iter().filter_map(|i| (i % 2 == 0).then(|| really_expensive_fn(i)));
/// ```
/// Use instead:
/// ```rust
/// # fn really_expensive_fn(i: i32) -> i32 { i }
/// # let v = vec![];
/// _ = v.into_iter().filter(|i| i % 2 == 0).map(|i| really_expensive_fn(i));
/// ```
#[clippy::version = "1.72.0"]
pub FILTER_MAP_BOOL_THEN,
style,
"checks for usage of `bool::then` in `Iterator::filter_map`"
}

declare_clippy_lint! {
/// ### What it does
/// Looks for calls to `RwLock::write` where the lock is only used for reading.
@@ -3676,7 +3644,6 @@ impl_lint_pass!(Methods => [
FORMAT_COLLECT,
STRING_LIT_CHARS_ANY,
ITER_SKIP_ZERO,
FILTER_MAP_BOOL_THEN,
READONLY_WRITE_LOCK
]);

@@ -3955,7 +3922,6 @@ impl Methods {
},
("filter_map", [arg]) => {
unnecessary_filter_map::check(cx, expr, arg, name);
filter_map_bool_then::check(cx, expr, arg, call_span);
filter_map_identity::check(cx, expr, arg, span);
},
("find_map", [arg]) => {
2 changes: 0 additions & 2 deletions src/tools/clippy/clippy_utils/src/paths.rs
Original file line number Diff line number Diff line change
@@ -163,5 +163,3 @@ pub const OPTION_EXPECT: [&str; 4] = ["core", "option", "Option", "expect"];
pub const FORMATTER: [&str; 3] = ["core", "fmt", "Formatter"];
pub const DEBUG_STRUCT: [&str; 4] = ["core", "fmt", "builders", "DebugStruct"];
pub const ORD_CMP: [&str; 4] = ["core", "cmp", "Ord", "cmp"];
#[expect(clippy::invalid_paths)] // not sure why it thinks this, it works so
pub const BOOL_THEN: [&str; 4] = ["core", "bool", "<impl bool>", "then"];
44 changes: 0 additions & 44 deletions src/tools/clippy/tests/ui/filter_map_bool_then.fixed

This file was deleted.

44 changes: 0 additions & 44 deletions src/tools/clippy/tests/ui/filter_map_bool_then.rs

This file was deleted.

34 changes: 0 additions & 34 deletions src/tools/clippy/tests/ui/filter_map_bool_then.stderr

This file was deleted.