Skip to content

Commit 4acb822

Browse files
committed
Update tests for unnecessary_refs lint
1 parent 061697a commit 4acb822

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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/alloctests/tests/boxed.rs

Lines changed: 1 addition & 0 deletions
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+
#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
89
fn uninitialized_zero_size_box() {
910
assert_eq!(
1011
&*Box::<()>::new_uninit() as *const _,

library/alloctests/tests/str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,7 @@ fn test_str_escapes() {
22282228
}
22292229

22302230
#[test]
2231+
#[cfg_attr(not(bootstrap), 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/alloctests/tests/sync.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ fn weak_self_cyclic() {
330330
}
331331

332332
#[test]
333+
#[cfg_attr(not(bootstrap), 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+
#[cfg_attr(not(bootstrap), 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/alloctests/tests/vec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,7 @@ fn assert_covariance() {
13801380
}
13811381

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

library/alloctests/tests/vec_deque.rs

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ impl<T: ?Sized> Pointer for &T {
28812881
#[stable(feature = "rust1", since = "1.0.0")]
28822882
impl<T: ?Sized> Pointer for &mut T {
28832883
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
2884-
Pointer::fmt(&(&**self as *const T), f)
2884+
Pointer::fmt(&(&raw const **self), f)
28852885
}
28862886
}
28872887

library/core/src/hash/sip.rs

Lines changed: 1 addition & 1 deletion
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()

0 commit comments

Comments
 (0)