Skip to content

Commit

Permalink
Remove redundant imports of size_of
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtriplett committed Mar 29, 2024
1 parent 878cb3d commit 04f4ff5
Show file tree
Hide file tree
Showing 98 changed files with 79 additions and 96 deletions.
2 changes: 0 additions & 2 deletions compiler/rustc_index/src/vec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ crate::newtype_index! {

#[test]
fn index_size_is_optimized() {
use std::mem::size_of;

assert_eq!(size_of::<MyIdx>(), 4);
// Uses 0xFFFF_FFFB
assert_eq!(size_of::<Option<MyIdx>>(), 4);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/erase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::traits;
use crate::ty::adjustment::CoerceUnsizedInfo;
use crate::ty::{self, Ty};
use std::intrinsics::transmute_unchecked;
use std::mem::{size_of, MaybeUninit};
use std::mem::MaybeUninit;

#[derive(Copy, Clone)]
pub struct Erased<T: Copy> {
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/boxed/thin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use core::ptr::{self, NonNull};
/// let five = ThinBox::new(5);
/// let thin_slice = ThinBox::<[i32]>::new_unsize([1, 2, 3, 4]);
///
/// use std::mem::{size_of, size_of_val};
/// let size_of_ptr = size_of::<*const ()>();
/// assert_eq!(size_of_ptr, size_of_val(&five));
/// assert_eq!(size_of_ptr, size_of_val(&thin_slice));
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/raw_vec/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::*;
use core::mem::size_of;
use std::cell::Cell;

#[test]
Expand Down
2 changes: 0 additions & 2 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ use core::intrinsics::abort;
#[cfg(not(no_global_oom_handling))]
use core::iter;
use core::marker::{PhantomData, Unsize};
#[cfg(not(no_global_oom_handling))]
use core::mem::size_of_val;
use core::mem::{self, align_of_val_raw, forget, ManuallyDrop};
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, Receiver};
use core::panic::{RefUnwindSafe, UnwindSafe};
Expand Down
2 changes: 0 additions & 2 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use core::intrinsics::abort;
#[cfg(not(no_global_oom_handling))]
use core::iter;
use core::marker::{PhantomData, Unsize};
#[cfg(not(no_global_oom_handling))]
use core::mem::size_of_val;
use core::mem::{self, align_of_val_raw};
use core::ops::{CoerceUnsized, Deref, DerefPure, DispatchFromDyn, Receiver};
use core::panic::{RefUnwindSafe, UnwindSafe};
Expand Down
1 change: 0 additions & 1 deletion library/alloc/tests/thin_box.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::fmt::Debug;
use core::mem::size_of;
use std::boxed::ThinBox;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fmt::Debug;
use std::hint;
use std::iter::InPlaceIterable;
use std::mem;
use std::mem::{size_of, swap};
use std::mem::swap;
use std::ops::Bound::*;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::rc::Rc;
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
use crate::cmp::Ordering;
use crate::fmt::{self, Debug, Display};
use crate::marker::{PhantomData, Unsize};
use crate::mem::{self, size_of};
use crate::mem::self;
use crate::ops::{CoerceUnsized, Deref, DerefMut, DispatchFromDyn};
use crate::ptr::{self, NonNull};

Expand Down
4 changes: 2 additions & 2 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ use crate::slice;
/// `MaybeUninit<T>` is guaranteed to have the same size, alignment, and ABI as `T`:
///
/// ```rust
/// use std::mem::{MaybeUninit, size_of, align_of};
/// use std::mem::{MaybeUninit, align_of};
/// assert_eq!(size_of::<MaybeUninit<u64>>(), size_of::<u64>());
/// assert_eq!(align_of::<MaybeUninit<u64>>(), align_of::<u64>());
/// ```
Expand All @@ -224,7 +224,7 @@ use crate::slice;
/// optimizations, potentially resulting in a larger size:
///
/// ```rust
/// # use std::mem::{MaybeUninit, size_of};
/// # use std::mem::MaybeUninit;
/// assert_eq!(size_of::<Option<bool>>(), 1);
/// assert_eq!(size_of::<Option<MaybeUninit<bool>>>(), 2);
/// ```
Expand Down
1 change: 0 additions & 1 deletion library/core/src/num/dec2flt/fpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub use fpu_precision::set_precision;
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
mod fpu_precision {
use core::arch::asm;
use core::mem::size_of;

/// A structure used to preserve the original value of the FPU control word, so that it can be
/// restored when the structure is dropped.
Expand Down
4 changes: 1 addition & 3 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ impl_zeroable_primitive!(
///
/// ```
/// #![feature(generic_nonzero)]
/// use core::mem::size_of;
///
/// assert_eq!(size_of::<Option<core::num::NonZero<u32>>>(), size_of::<u32>());
/// ```
Expand Down Expand Up @@ -467,7 +466,6 @@ macro_rules! nonzero_integer {
#[doc = concat!("For example, `Option<", stringify!($Ty), ">` is the same size as `", stringify!($Int), "`:")]
///
/// ```rust
/// use std::mem::size_of;
#[doc = concat!("assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", stringify!($Int), ">());")]
/// ```
///
Expand All @@ -483,7 +481,7 @@ macro_rules! nonzero_integer {
/// are guaranteed to have the same size and alignment:
///
/// ```
/// # use std::mem::{size_of, align_of};
/// # use std::mem::align_of;
#[doc = concat!("use std::num::", stringify!($Ty), ";")]
///
#[doc = concat!("assert_eq!(size_of::<", stringify!($Ty), ">(), size_of::<Option<", stringify!($Ty), ">>());")]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ use crate::intrinsics;
use crate::marker::FnPtr;
use crate::ub_checks;

use crate::mem::{self, align_of, size_of, MaybeUninit};
use crate::mem::{self, align_of, MaybeUninit};

mod alignment;
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::ub_checks::assert_unsafe_precondition;
/// are guaranteed to have the same size and alignment:
///
/// ```
/// # use std::mem::{size_of, align_of};
/// # use std::mem::align_of;
/// use std::ptr::NonNull;
///
/// assert_eq!(size_of::<NonNull<i16>>(), size_of::<Option<NonNull<i16>>>());
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/slice/raw.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Free functions to create `&[T]` and `&mut [T]`.
use crate::array;
use crate::mem::{align_of, size_of};
use crate::mem::align_of;
use crate::ops::Range;
use crate::ptr;
use crate::ub_checks;
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::alloc::Layout;
use core::mem::size_of;
use core::ptr::{self, NonNull};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn atomic_access_bool() {

#[test]
fn atomic_alignment() {
use std::mem::{align_of, size_of};
use std::mem::align_of;

#[cfg(target_has_atomic = "8")]
assert_eq!(align_of::<AtomicBool>(), size_of::<AtomicBool>());
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/nonzero.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core::num::{IntErrorKind, NonZero};
use core::option::Option::None;
use std::mem::size_of;

#[test]
fn test_create_nonzero_instance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ where
fn cast<U>(self) -> Self::CastPtr<U> {
// SimdElement currently requires zero-sized metadata, so this should never fail.
// If this ever changes, `simd_cast_ptr` should produce a post-mono error.
use core::{mem::size_of, ptr::Pointee};
use core::ptr::Pointee;
assert_eq!(size_of::<<T as Pointee>::Metadata>(), 0);
assert_eq!(size_of::<<U as Pointee>::Metadata>(), 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ where
fn cast<U>(self) -> Self::CastPtr<U> {
// SimdElement currently requires zero-sized metadata, so this should never fail.
// If this ever changes, `simd_cast_ptr` should produce a post-mono error.
use core::{mem::size_of, ptr::Pointee};
use core::ptr::Pointee;
assert_eq!(size_of::<<T as Pointee>::Metadata>(), 0);
assert_eq!(size_of::<<U as Pointee>::Metadata>(), 0);

Expand Down
1 change: 0 additions & 1 deletion library/proc_macro/src/bridge/fxhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use std::collections::HashMap;
use std::hash::BuildHasherDefault;
use std::hash::Hasher;
use std::mem::size_of;
use std::ops::BitXor;

/// Type alias for a hashmap using the `fx` hash algorithm.
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/error/repr_bitpacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
use super::{Custom, ErrorData, ErrorKind, RawOsError, SimpleMessage};
use core::marker::PhantomData;
use core::mem::{align_of, size_of};
use core::mem::align_of;
use core::ptr::{self, NonNull};

// The 2 least-significant bits are used as tag.
Expand Down
1 change: 0 additions & 1 deletion library/std/src/io/error/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::{const_io_error, Custom, Error, ErrorData, ErrorKind, Repr, SimpleMes
use crate::assert_matches::assert_matches;
use crate::error;
use crate::fmt;
use crate::mem::size_of;
use crate::sys::decode_error_kind;
use crate::sys::os::error_string;

Expand Down
1 change: 0 additions & 1 deletion library/std/src/os/fd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ fn test_fd() {
#[cfg(any(unix, target_os = "wasi"))]
#[test]
fn test_niche_optimizations() {
use crate::mem::size_of;
#[cfg(unix)]
use crate::os::unix::io::{BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
#[cfg(target_os = "wasi")]
Expand Down
1 change: 0 additions & 1 deletion library/std/src/os/unix/io/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::mem::size_of;
use crate::os::unix::io::RawFd;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/unix/net/ancillary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::{sockaddr_un, SocketAddr};
use crate::io::{self, IoSlice, IoSliceMut};
use crate::marker::PhantomData;
use crate::mem::{size_of, zeroed};
use crate::mem::zeroed;
use crate::os::unix::io::RawFd;
use crate::path::Path;
use crate::ptr::{eq, read_unaligned};
Expand Down
1 change: 0 additions & 1 deletion library/std/src/os/wasi/io/fd/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::mem::size_of;
use crate::os::wasi::io::RawFd;

#[test]
Expand Down
1 change: 0 additions & 1 deletion library/std/src/os/windows/io/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[test]
fn test_niche_optimizations_socket() {
use crate::mem::size_of;
use crate::os::windows::io::{
BorrowedSocket, FromRawSocket, IntoRawSocket, OwnedSocket, RawSocket,
};
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/uefi/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::env::current_exe;
use crate::ffi::OsString;
use crate::fmt;
use crate::iter::Iterator;
use crate::mem::size_of;
use crate::vec;

pub struct Args {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/uefi/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use r_efi::protocols::{device_path, device_path_to_text};

use crate::ffi::OsString;
use crate::io::{self, const_io_error};
use crate::mem::{size_of, MaybeUninit};
use crate::mem::MaybeUninit;
use crate::os::uefi::{self, env::boot_services, ffi::OsStringExt};
use crate::ptr::NonNull;
use crate::slice;
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,6 @@ impl<'a> DirBuffIter<'a> {
impl<'a> Iterator for DirBuffIter<'a> {
type Item = (Cow<'a, [u16]>, bool);
fn next(&mut self) -> Option<Self::Item> {
use crate::mem::size_of;
let buffer = &self.buffer?[self.cursor..];

// Get the name and next entry from the buffer.
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/windows/io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::marker::PhantomData;
use crate::mem::size_of;
use crate::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle};
use crate::slice;
use crate::sys::c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare_clippy_lint! {
/// ### Example
/// ```rust,no_run
/// # use std::ptr::copy_nonoverlapping;
/// # #[allow(unused_imports)]
/// # use std::mem::size_of;
/// const SIZE: usize = 128;
/// let x = [2u8; SIZE];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::redundant_clone, clippy::unnecessary_operation, clippy::incompatible_msrv)]
#![warn(clippy::manual_non_exhaustive, clippy::borrow_as_ptr, clippy::manual_bits)]

#[allow(unused_imports)]
use std::mem::{size_of, size_of_val};
use std::ops::Deref;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::redundant_clone, clippy::unnecessary_operation, clippy::incompatible_msrv)]
#![warn(clippy::manual_non_exhaustive, clippy::borrow_as_ptr, clippy::manual_bits)]

#[allow(unused_imports)]
use std::mem::{size_of, size_of_val};
use std::ops::Deref;

Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/manual_bits.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
clippy::unnecessary_cast
)]

#[allow(unused_imports)]
use std::mem::{size_of, size_of_val};

fn main() {
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/manual_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
clippy::unnecessary_cast
)]

#[allow(unused_imports)]
use std::mem::{size_of, size_of_val};

fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

extern crate proc_macros;

#[allow(unused_imports)]
use core::mem::{align_of, size_of};
use proc_macros::external;

Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/manual_slice_size_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

extern crate proc_macros;

#[allow(unused_imports)]
use core::mem::{align_of, size_of};
use proc_macros::external;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![warn(clippy::size_of_in_element_count)]
#![allow(clippy::ptr_offset_with_cast)]

#[allow(unused_imports)]
use std::mem::{size_of, size_of_val};
use std::ptr::{copy, copy_nonoverlapping, write_bytes};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![warn(clippy::size_of_in_element_count)]
#![allow(clippy::ptr_offset_with_cast)]

#[allow(unused_imports)]
use std::mem::{size_of, size_of_val};
use std::ptr::{
copy, copy_nonoverlapping, slice_from_raw_parts, slice_from_raw_parts_mut, swap_nonoverlapping, write_bytes,
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/size_of_ref.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(unused)]
#![warn(clippy::size_of_ref)]

#[allow(unused_imports)]
use std::mem::size_of_val;

fn main() {
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/transmute_undefined_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use core::any::TypeId;
use core::ffi::c_void;
#[allow(unused_imports)]
use core::mem::{size_of, transmute, MaybeUninit};
use core::ptr::NonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![warn(clippy::transmute_ptr_to_ptr)]
#![allow(unused, clippy::borrow_as_ptr)]

#[allow(unused_imports)]
use std::mem::{size_of, transmute};

// rustc_hir_analysis::check::cast contains documentation about when a cast `e as U` is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![warn(clippy::transmute_ptr_to_ptr)]
#![allow(unused, clippy::borrow_as_ptr)]

#[allow(unused_imports)]
use std::mem::{size_of, transmute};

// rustc_hir_analysis::check::cast contains documentation about when a cast `e as U` is
Expand Down
1 change: 0 additions & 1 deletion src/tools/compiletest/src/raise_fd_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
pub unsafe fn raise_fd_limit() {
use std::cmp;
use std::io;
use std::mem::size_of_val;
use std::ptr::null_mut;

static CTL_KERN: libc::c_int = 1;
Expand Down
Loading

0 comments on commit 04f4ff5

Please sign in to comment.