Skip to content

Commit 976c0a8

Browse files
committed
Update tests for unnecessary_refs lint
1 parent 99f3475 commit 976c0a8

File tree

144 files changed

+691
-276
lines changed

Some content is hidden

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

144 files changed

+691
-276
lines changed

compiler/rustc_query_impl/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ where
8484
}
8585

8686
#[inline(always)]
87+
#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
8788
fn query_state<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a QueryState<Self::Key>
8889
where
8990
QueryCtxt<'tcx>: 'a,
@@ -98,6 +99,7 @@ where
9899
}
99100

100101
#[inline(always)]
102+
#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
101103
fn query_cache<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a Self::Cache
102104
where
103105
'tcx: 'a,

library/alloc/src/boxed.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
17231723
/// # Examples
17241724
///
17251725
/// ```
1726+
/// #![allow(unnecessary_refs)]
17261727
/// let x = Box::new(5);
17271728
/// let y = x.clone();
17281729
///

library/alloc/tests/boxed.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::ptr::NonNull;
55

66
#[test]
77
#[expect(dangling_pointers_from_temporaries)]
8+
#[allow(unnecessary_refs)]
89
fn uninitialized_zero_size_box() {
910
assert_eq!(
1011
&*Box::<()>::new_uninit() as *const _,

library/alloc/tests/str.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,7 @@ fn test_str_escapes() {
22282228
}
22292229

22302230
#[test]
2231+
#[allow(unnecessary_refs)]
22312232
fn const_str_ptr() {
22322233
const A: [u8; 2] = ['h' as u8, 'i' as u8];
22332234
const B: &'static [u8; 2] = &A;

library/alloc/tests/sync.rs

+2
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ fn weak_self_cyclic() {
330330
}
331331

332332
#[test]
333+
#[allow(unnecessary_refs)]
333334
fn drop_arc() {
334335
let mut canary = AtomicUsize::new(0);
335336
let x = Arc::new(Canary(&mut canary as *mut AtomicUsize));
@@ -338,6 +339,7 @@ fn drop_arc() {
338339
}
339340

340341
#[test]
342+
#[allow(unnecessary_refs)]
341343
fn drop_arc_weak() {
342344
let mut canary = AtomicUsize::new(0);
343345
let arc = Arc::new(Canary(&mut canary as *mut AtomicUsize));

library/alloc/tests/vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,7 @@ fn assert_covariance() {
13801380
}
13811381

13821382
#[test]
1383+
#[allow(unnecessary_refs)]
13831384
fn from_into_inner() {
13841385
let vec = vec![1, 2, 3];
13851386
let ptr = vec.as_ptr();

library/alloc/tests/vec_deque.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,7 @@ fn test_collect_from_into_iter_keeps_allocation() {
18381838
v.extend(0..7);
18391839
check(&v[0], &v[v.len() - 1], v.into_iter());
18401840

1841+
#[allow(unnecessary_refs)]
18411842
fn check(buf: *const i32, last: *const i32, mut it: impl Iterator<Item = i32>) {
18421843
assert_eq!(it.next(), Some(0));
18431844
assert_eq!(it.next(), Some(1));

library/core/src/ffi/c_str.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ impl CStr {
498498
const fn as_non_null_ptr(&self) -> NonNull<c_char> {
499499
// FIXME(const_trait_impl) replace with `NonNull::from`
500500
// SAFETY: a reference is never null
501-
unsafe { NonNull::new_unchecked(&self.inner as *const [c_char] as *mut [c_char]) }
502-
.as_non_null_ptr()
501+
unsafe { NonNull::new_unchecked(&raw const self.inner as *mut [c_char]) }.as_non_null_ptr()
503502
}
504503

505504
/// Returns the length of `self`. Like C's `strlen`, this does not include the nul terminator.

library/core/src/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2822,7 +2822,7 @@ impl<T: ?Sized> Pointer for &T {
28222822
#[stable(feature = "rust1", since = "1.0.0")]
28232823
impl<T: ?Sized> Pointer for &mut T {
28242824
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
2825-
Pointer::fmt(&(&**self as *const T), f)
2825+
Pointer::fmt(&(&raw const **self), f)
28262826
}
28272827
}
28282828

library/core/src/hash/sip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ macro_rules! load_int_le {
103103
let mut data = 0 as $int_ty;
104104
ptr::copy_nonoverlapping(
105105
$buf.as_ptr().add($i),
106-
&mut data as *mut _ as *mut u8,
106+
&raw mut data as *mut u8,
107107
size_of::<$int_ty>(),
108108
);
109109
data.to_le()

library/core/src/intrinsics/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3714,6 +3714,7 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
37143714
/// following is an **incorrect** use of this function:
37153715
///
37163716
/// ```rust,no_run
3717+
/// #![allow(unnecessary_refs)]
37173718
/// unsafe {
37183719
/// let mut value: u8 = 0;
37193720
/// let ptr: *mut bool = &mut value as *mut u8 as *mut bool;

library/core/src/mem/maybe_uninit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ impl<T> MaybeUninit<T> {
872872
/// Nor can you use direct field access to do field-by-field gradual initialization:
873873
///
874874
/// ```rust,no_run
875+
/// #![allow(unnecessary_refs)]
875876
/// use std::{mem::MaybeUninit, ptr};
876877
///
877878
/// struct Foo {

library/core/src/pin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@
300300
//! }
301301
//!
302302
//! impl AddrTracker {
303+
//! #[allow(unnecessary_refs)]
303304
//! fn check_for_move(self: Pin<&mut Self>) {
304305
//! let current_addr = &*self as *const Self as usize;
305306
//! match self.prev_addr {

library/core/src/ptr/const_ptr.rs

+9
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl<T: ?Sized> *const T {
103103
///
104104
/// ```rust,no_run
105105
/// #![feature(set_ptr_value)]
106+
/// #![allow(unnecessary_refs)]
106107
/// let x = 0u32;
107108
/// let y = 1u32;
108109
///
@@ -267,6 +268,7 @@ impl<T: ?Sized> *const T {
267268
/// # Examples
268269
///
269270
/// ```
271+
/// #![allow(unnecessary_refs)]
270272
/// let ptr: *const u8 = &10u8 as *const u8;
271273
///
272274
/// unsafe {
@@ -283,6 +285,7 @@ impl<T: ?Sized> *const T {
283285
/// dereference the pointer directly.
284286
///
285287
/// ```
288+
/// #![allow(unnecessary_refs)]
286289
/// let ptr: *const u8 = &10u8 as *const u8;
287290
///
288291
/// unsafe {
@@ -315,6 +318,7 @@ impl<T: ?Sized> *const T {
315318
///
316319
/// ```
317320
/// #![feature(ptr_as_ref_unchecked)]
321+
/// #![allow(unnecessary_refs)]
318322
/// let ptr: *const u8 = &10u8 as *const u8;
319323
///
320324
/// unsafe {
@@ -352,6 +356,7 @@ impl<T: ?Sized> *const T {
352356
///
353357
/// ```
354358
/// #![feature(ptr_as_uninit)]
359+
/// #![allow(unnecessary_refs)]
355360
///
356361
/// let ptr: *const u8 = &10u8 as *const u8;
357362
///
@@ -1417,6 +1422,7 @@ impl<T: ?Sized> *const T {
14171422
/// # Examples
14181423
///
14191424
/// ```
1425+
/// #![allow(unnecessary_refs)]
14201426
/// // On some platforms, the alignment of i32 is less than 4.
14211427
/// #[repr(align(4))]
14221428
/// struct AlignedI32(i32);
@@ -1450,6 +1456,7 @@ impl<T: ?Sized> *const T {
14501456
///
14511457
/// ```
14521458
/// #![feature(pointer_is_aligned_to)]
1459+
/// #![allow(unnecessary_refs)]
14531460
///
14541461
/// // On some platforms, the alignment of i32 is less than 4.
14551462
/// #[repr(align(4))]
@@ -1565,6 +1572,7 @@ impl<T> *const [T] {
15651572
///
15661573
/// ```
15671574
/// #![feature(slice_ptr_get)]
1575+
/// #![allow(unnecessary_refs)]
15681576
///
15691577
/// let x = &[1, 2, 4] as *const [i32];
15701578
///
@@ -1664,6 +1672,7 @@ impl<T, const N: usize> *const [T; N] {
16641672
///
16651673
/// ```
16661674
/// #![feature(array_ptr_get)]
1675+
/// #![allow(unnecessary_refs)]
16671676
///
16681677
/// let arr: *const [i32; 3] = &[1, 2, 4] as *const [i32; 3];
16691678
/// let slice: *const [i32] = arr.as_slice();

library/core/src/ptr/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@
290290
//! represent the tagged pointer as an actual pointer and not a `usize`*. For instance:
291291
//!
292292
//! ```
293+
//! #![allow(unnecessary_refs)]
293294
//! unsafe {
294295
//! // A flag we want to pack into our pointer
295296
//! static HAS_DATA: usize = 0x1;
@@ -492,6 +493,7 @@ mod mut_ptr;
492493
/// Manually remove the last item from a vector:
493494
///
494495
/// ```
496+
/// #![allow(unnecessary_refs)]
495497
/// use std::ptr;
496498
/// use std::rc::Rc;
497499
///
@@ -759,6 +761,7 @@ pub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T {
759761
/// Note that this has subtle interactions with the rules for lifetime extension of temporaries in
760762
/// tail expressions. This code is valid, albeit in a non-obvious way:
761763
/// ```rust
764+
/// #![allow(unnecessary_refs)]
762765
/// # type T = i32;
763766
/// # fn foo() -> T { 42 }
764767
/// // The temporary holding the return value of `foo` has its lifetime extended,
@@ -810,6 +813,7 @@ pub const fn from_ref<T: ?Sized>(r: &T) -> *const T {
810813
/// Note that this has subtle interactions with the rules for lifetime extension of temporaries in
811814
/// tail expressions. This code is valid, albeit in a non-obvious way:
812815
/// ```rust
816+
/// #![allow(unnecessary_refs)]
813817
/// # type T = i32;
814818
/// # fn foo() -> T { 42 }
815819
/// // The temporary holding the return value of `foo` has its lifetime extended,
@@ -1249,6 +1253,7 @@ pub const unsafe fn replace<T>(dst: *mut T, src: T) -> T {
12491253
/// Basic usage:
12501254
///
12511255
/// ```
1256+
/// #![allow(unnecessary_refs)]
12521257
/// let x = 12;
12531258
/// let y = &x as *const i32;
12541259
///
@@ -1501,6 +1506,7 @@ pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
15011506
/// Basic usage:
15021507
///
15031508
/// ```
1509+
/// #![allow(unnecessary_refs)]
15041510
/// let mut x = 0;
15051511
/// let y = &mut x as *mut i32;
15061512
/// let z = 12;
@@ -1722,6 +1728,7 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
17221728
/// Basic usage:
17231729
///
17241730
/// ```
1731+
/// #![allow(unnecessary_refs)]
17251732
/// let x = 12;
17261733
/// let y = &x as *const i32;
17271734
///
@@ -1800,6 +1807,7 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
18001807
/// Basic usage:
18011808
///
18021809
/// ```
1810+
/// #![allow(unnecessary_refs)]
18031811
/// let mut x = 0;
18041812
/// let y = &mut x as *mut i32;
18051813
/// let z = 12;

library/core/src/ptr/mut_ptr.rs

+10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl<T: ?Sized> *mut T {
8585
///
8686
/// ```rust,no_run
8787
/// #![feature(set_ptr_value)]
88+
/// #![allow(unnecessary_refs)]
8889
/// let mut x = 0u32;
8990
/// let mut y = 1u32;
9091
///
@@ -256,6 +257,7 @@ impl<T: ?Sized> *mut T {
256257
/// # Examples
257258
///
258259
/// ```
260+
/// #![allow(unnecessary_refs)]
259261
/// let ptr: *mut u8 = &mut 10u8 as *mut u8;
260262
///
261263
/// unsafe {
@@ -272,6 +274,7 @@ impl<T: ?Sized> *mut T {
272274
/// dereference the pointer directly.
273275
///
274276
/// ```
277+
/// #![allow(unnecessary_refs)]
275278
/// let ptr: *mut u8 = &mut 10u8 as *mut u8;
276279
///
277280
/// unsafe {
@@ -306,6 +309,7 @@ impl<T: ?Sized> *mut T {
306309
///
307310
/// ```
308311
/// #![feature(ptr_as_ref_unchecked)]
312+
/// #![allow(unnecessary_refs)]
309313
/// let ptr: *mut u8 = &mut 10u8 as *mut u8;
310314
///
311315
/// unsafe {
@@ -348,6 +352,7 @@ impl<T: ?Sized> *mut T {
348352
///
349353
/// ```
350354
/// #![feature(ptr_as_uninit)]
355+
/// #![allow(unnecessary_refs)]
351356
///
352357
/// let ptr: *mut u8 = &mut 10u8 as *mut u8;
353358
///
@@ -1670,6 +1675,7 @@ impl<T: ?Sized> *mut T {
16701675
/// # Examples
16711676
///
16721677
/// ```
1678+
/// #![allow(unnecessary_refs)]
16731679
/// // On some platforms, the alignment of i32 is less than 4.
16741680
/// #[repr(align(4))]
16751681
/// struct AlignedI32(i32);
@@ -1703,6 +1709,7 @@ impl<T: ?Sized> *mut T {
17031709
///
17041710
/// ```
17051711
/// #![feature(pointer_is_aligned_to)]
1712+
/// #![allow(unnecessary_refs)]
17061713
///
17071714
/// // On some platforms, the alignment of i32 is less than 4.
17081715
/// #[repr(align(4))]
@@ -1818,6 +1825,7 @@ impl<T> *mut [T] {
18181825
/// ```
18191826
/// #![feature(raw_slice_split)]
18201827
/// #![feature(slice_ptr_get)]
1828+
/// #![allow(unnecessary_refs)]
18211829
///
18221830
/// let mut v = [1, 0, 3, 0, 5, 6];
18231831
/// let ptr = &mut v as *mut [_];
@@ -1858,6 +1866,7 @@ impl<T> *mut [T] {
18581866
///
18591867
/// ```
18601868
/// #![feature(raw_slice_split)]
1869+
/// #![allow(unnecessary_refs)]
18611870
///
18621871
/// let mut v = [1, 0, 3, 0, 5, 6];
18631872
/// // scoped to restrict the lifetime of the borrows
@@ -1917,6 +1926,7 @@ impl<T> *mut [T] {
19171926
///
19181927
/// ```
19191928
/// #![feature(slice_ptr_get)]
1929+
/// #![allow(unnecessary_refs)]
19201930
///
19211931
/// let x = &mut [1, 2, 4] as *mut [i32];
19221932
///

library/core/src/ptr/non_null.rs

+5
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ impl<T: ?Sized> NonNull<T> {
199199
/// # Examples
200200
///
201201
/// ```
202+
/// #![allow(unnecessary_refs)]
202203
/// use std::ptr::NonNull;
203204
///
204205
/// let mut x = 0u32;
@@ -240,6 +241,7 @@ impl<T: ?Sized> NonNull<T> {
240241
/// # Examples
241242
///
242243
/// ```
244+
/// #![allow(unnecessary_refs)]
243245
/// use std::ptr::NonNull;
244246
///
245247
/// let mut x = 0u32;
@@ -407,6 +409,7 @@ impl<T: ?Sized> NonNull<T> {
407409
/// # Examples
408410
///
409411
/// ```
412+
/// #![allow(unnecessary_refs)]
410413
/// use std::ptr::NonNull;
411414
///
412415
/// let mut x = 0u32;
@@ -470,6 +473,7 @@ impl<T: ?Sized> NonNull<T> {
470473
/// # Examples
471474
///
472475
/// ```
476+
/// #![allow(unnecessary_refs)]
473477
/// use std::ptr::NonNull;
474478
///
475479
/// let mut x = 0u32;
@@ -1295,6 +1299,7 @@ impl<T: ?Sized> NonNull<T> {
12951299
///
12961300
/// ```
12971301
/// #![feature(pointer_is_aligned_to)]
1302+
/// #![allow(unnecessary_refs)]
12981303
///
12991304
/// // On some platforms, the alignment of i32 is less than 4.
13001305
/// #[repr(align(4))]

library/core/src/slice/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ impl<T> [T] {
791791
/// element of this slice:
792792
///
793793
/// ```
794+
/// #![allow(unnecessary_refs)]
794795
/// let a = [1, 2, 3];
795796
/// let x = &a[1] as *const _;
796797
/// let y = &5 as *const _;

library/core/src/slice/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use crate::{array, ptr, ub_checks};
4343
/// # Examples
4444
///
4545
/// ```
46+
/// #![allow(unnecessary_refs)]
4647
/// use std::slice;
4748
///
4849
/// // manifest a slice for a single element

0 commit comments

Comments
 (0)