diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl
index d51865810b9a8..ebf594fd2665f 100644
--- a/compiler/rustc_lint/messages.ftl
+++ b/compiler/rustc_lint/messages.ftl
@@ -894,6 +894,9 @@ lint_unnameable_test_items = cannot test inner items
 lint_unnecessary_qualification = unnecessary qualification
     .suggestion = remove the unnecessary path segments
 
+lint_unnecessary_refs = creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+    .suggestion = consider using `&raw {$mutbl}` for a safer and more explicit raw pointer
+
 lint_unpredictable_fn_pointer_comparisons = function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique
     .note_duplicated_fn = the address of the same function can vary between different codegen units
     .note_deduplicated_fn = furthermore, different functions could have the same address after being merged together
diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs
index c38a754001811..c459fe3c44e88 100644
--- a/compiler/rustc_lint/src/lib.rs
+++ b/compiler/rustc_lint/src/lib.rs
@@ -78,6 +78,7 @@ mod static_mut_refs;
 mod traits;
 mod types;
 mod unit_bindings;
+mod unnecessary_refs;
 mod unqualified_local_imports;
 mod unused;
 
@@ -119,6 +120,7 @@ use static_mut_refs::*;
 use traits::*;
 use types::*;
 use unit_bindings::*;
+use unnecessary_refs::*;
 use unqualified_local_imports::*;
 use unused::*;
 
@@ -244,6 +246,7 @@ late_lint_methods!(
             IfLetRescope: IfLetRescope::default(),
             StaticMutRefs: StaticMutRefs,
             UnqualifiedLocalImports: UnqualifiedLocalImports,
+            UnecessaryRefs: UnecessaryRefs,
         ]
     ]
 );
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 0058630957291..0f2fc7f2a89e9 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -3163,3 +3163,20 @@ pub(crate) struct ReservedMultihash {
     #[suggestion(code = " ", applicability = "machine-applicable")]
     pub suggestion: Span,
 }
+
+#[derive(LintDiagnostic)]
+#[diag(lint_unnecessary_refs)]
+pub(crate) struct UnnecessaryRefs<'a> {
+    #[subdiagnostic]
+    pub suggestion: UnnecessaryRefsSuggestion<'a>,
+}
+
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
+pub(crate) struct UnnecessaryRefsSuggestion<'a> {
+    #[suggestion_part(code = "&raw {mutbl} ")]
+    pub left: Span,
+    #[suggestion_part(code = "")]
+    pub right: Span,
+    pub mutbl: &'a str,
+}
diff --git a/compiler/rustc_lint/src/unnecessary_refs.rs b/compiler/rustc_lint/src/unnecessary_refs.rs
new file mode 100644
index 0000000000000..61a47253b0054
--- /dev/null
+++ b/compiler/rustc_lint/src/unnecessary_refs.rs
@@ -0,0 +1,58 @@
+use rustc_ast::BorrowKind;
+use rustc_hir::{Expr, ExprKind, TyKind};
+use rustc_session::{declare_lint, declare_lint_pass};
+
+use crate::lints::{UnnecessaryRefs, UnnecessaryRefsSuggestion};
+use crate::{LateContext, LateLintPass, LintContext};
+
+declare_lint! {
+    /// The `unnecessary_refs` lint checks for unnecessary references.
+    ///
+    /// ### Example
+    ///
+    /// ```rust
+    /// fn via_ref(x: *const (i32, i32)) -> *const i32 {
+    ///     unsafe { &(*x).0 as *const i32 }
+    /// }
+    ///
+    /// fn main() {
+    ///     let x = (0, 1);
+    ///     let _r = via_ref(&x);
+    /// }
+    /// ```
+    ///
+    /// {{produces}}
+    ///
+    /// ### Explanation
+    ///
+    /// Creating unnecessary references is discouraged because it can reduce
+    /// readability, introduce performance overhead, and lead to undefined
+    /// behavior if the reference is unaligned or uninitialized. Avoiding them
+    /// ensures safer and more efficient code.
+    pub UNNECESSARY_REFS,
+    Warn,
+    "creating unecessary reference is discouraged"
+}
+
+declare_lint_pass!(UnecessaryRefs => [UNNECESSARY_REFS]);
+
+impl<'tcx> LateLintPass<'tcx> for UnecessaryRefs {
+    fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) {
+        if let ExprKind::Cast(exp, ty) = expr.kind
+            && let ExprKind::AddrOf(BorrowKind::Ref, mutbl, addr_of_exp) = exp.kind
+            && let TyKind::Ptr(_) = ty.kind
+        {
+            cx.emit_span_lint(
+                UNNECESSARY_REFS,
+                expr.span,
+                UnnecessaryRefs {
+                    suggestion: UnnecessaryRefsSuggestion {
+                        left: expr.span.until(addr_of_exp.span),
+                        right: addr_of_exp.span.shrink_to_hi().until(ty.span.shrink_to_hi()),
+                        mutbl: mutbl.ptr_str(),
+                    },
+                },
+            );
+        }
+    }
+}
diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs
index a83c388c747b6..6fb3b81881c8a 100644
--- a/compiler/rustc_query_impl/src/lib.rs
+++ b/compiler/rustc_query_impl/src/lib.rs
@@ -84,6 +84,7 @@ where
     }
 
     #[inline(always)]
+    #[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
     fn query_state<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a QueryState<Self::Key>
     where
         QueryCtxt<'tcx>: 'a,
@@ -98,6 +99,7 @@ where
     }
 
     #[inline(always)]
+    #[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
     fn query_cache<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a Self::Cache
     where
         'tcx: 'a,
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs
index e77caad65401b..9e505b903f427 100644
--- a/library/alloc/src/boxed.rs
+++ b/library/alloc/src/boxed.rs
@@ -1723,6 +1723,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
     /// # Examples
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// let x = Box::new(5);
     /// let y = x.clone();
     ///
diff --git a/library/alloctests/tests/boxed.rs b/library/alloctests/tests/boxed.rs
index 94389cf2de933..d15f34a648b3c 100644
--- a/library/alloctests/tests/boxed.rs
+++ b/library/alloctests/tests/boxed.rs
@@ -5,6 +5,7 @@ use core::ptr::NonNull;
 
 #[test]
 #[expect(dangling_pointers_from_temporaries)]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn uninitialized_zero_size_box() {
     assert_eq!(
         &*Box::<()>::new_uninit() as *const _,
diff --git a/library/alloctests/tests/str.rs b/library/alloctests/tests/str.rs
index 906fa2d425e77..845a4045a06c6 100644
--- a/library/alloctests/tests/str.rs
+++ b/library/alloctests/tests/str.rs
@@ -2228,6 +2228,7 @@ fn test_str_escapes() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn const_str_ptr() {
     const A: [u8; 2] = ['h' as u8, 'i' as u8];
     const B: &'static [u8; 2] = &A;
diff --git a/library/alloctests/tests/sync.rs b/library/alloctests/tests/sync.rs
index 6d3ab1b1d11e1..51aef3cff00bc 100644
--- a/library/alloctests/tests/sync.rs
+++ b/library/alloctests/tests/sync.rs
@@ -330,6 +330,7 @@ fn weak_self_cyclic() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn drop_arc() {
     let mut canary = AtomicUsize::new(0);
     let x = Arc::new(Canary(&mut canary as *mut AtomicUsize));
@@ -338,6 +339,7 @@ fn drop_arc() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn drop_arc_weak() {
     let mut canary = AtomicUsize::new(0);
     let arc = Arc::new(Canary(&mut canary as *mut AtomicUsize));
diff --git a/library/alloctests/tests/vec.rs b/library/alloctests/tests/vec.rs
index f430d979fa848..2cb6f87441018 100644
--- a/library/alloctests/tests/vec.rs
+++ b/library/alloctests/tests/vec.rs
@@ -1380,6 +1380,7 @@ fn assert_covariance() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn from_into_inner() {
     let vec = vec![1, 2, 3];
     let ptr = vec.as_ptr();
diff --git a/library/alloctests/tests/vec_deque.rs b/library/alloctests/tests/vec_deque.rs
index 1b03c29e5bda1..213f7696f621d 100644
--- a/library/alloctests/tests/vec_deque.rs
+++ b/library/alloctests/tests/vec_deque.rs
@@ -1838,6 +1838,7 @@ fn test_collect_from_into_iter_keeps_allocation() {
     v.extend(0..7);
     check(&v[0], &v[v.len() - 1], v.into_iter());
 
+    #[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
     fn check(buf: *const i32, last: *const i32, mut it: impl Iterator<Item = i32>) {
         assert_eq!(it.next(), Some(0));
         assert_eq!(it.next(), Some(1));
diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs
index 080c0cef53304..625a5e809eafb 100644
--- a/library/core/src/ffi/c_str.rs
+++ b/library/core/src/ffi/c_str.rs
@@ -498,8 +498,7 @@ impl CStr {
     const fn as_non_null_ptr(&self) -> NonNull<c_char> {
         // FIXME(const_trait_impl) replace with `NonNull::from`
         // SAFETY: a reference is never null
-        unsafe { NonNull::new_unchecked(&self.inner as *const [c_char] as *mut [c_char]) }
-            .as_non_null_ptr()
+        unsafe { NonNull::new_unchecked(&raw const self.inner as *mut [c_char]) }.as_non_null_ptr()
     }
 
     /// Returns the length of `self`. Like C's `strlen`, this does not include the nul terminator.
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index 30fd2d7815f51..a7674fc32ae0e 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -2881,7 +2881,7 @@ impl<T: ?Sized> Pointer for &T {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> Pointer for &mut T {
     fn fmt(&self, f: &mut Formatter<'_>) -> Result {
-        Pointer::fmt(&(&**self as *const T), f)
+        Pointer::fmt(&(&raw const **self), f)
     }
 }
 
diff --git a/library/core/src/hash/sip.rs b/library/core/src/hash/sip.rs
index 780e522c48ebf..be860ad7e79c5 100644
--- a/library/core/src/hash/sip.rs
+++ b/library/core/src/hash/sip.rs
@@ -103,7 +103,7 @@ macro_rules! load_int_le {
         let mut data = 0 as $int_ty;
         ptr::copy_nonoverlapping(
             $buf.as_ptr().add($i),
-            &mut data as *mut _ as *mut u8,
+            &raw mut data as *mut u8,
             size_of::<$int_ty>(),
         );
         data.to_le()
diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs
index 81e59a1f349ec..e1e683889f811 100644
--- a/library/core/src/intrinsics/mod.rs
+++ b/library/core/src/intrinsics/mod.rs
@@ -3879,6 +3879,7 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
 /// following is an **incorrect** use of this function:
 ///
 /// ```rust,no_run
+/// #![allow(unnecessary_refs)]
 /// unsafe {
 ///     let mut value: u8 = 0;
 ///     let ptr: *mut bool = &mut value as *mut u8 as *mut bool;
diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs
index d0be82adb6b16..de8eb81af5bf9 100644
--- a/library/core/src/mem/maybe_uninit.rs
+++ b/library/core/src/mem/maybe_uninit.rs
@@ -872,6 +872,7 @@ impl<T> MaybeUninit<T> {
     /// Nor can you use direct field access to do field-by-field gradual initialization:
     ///
     /// ```rust,no_run
+    /// #![allow(unnecessary_refs)]
     /// use std::{mem::MaybeUninit, ptr};
     ///
     /// struct Foo {
diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs
index bc097bf198d03..6af2ad481bfdf 100644
--- a/library/core/src/pin.rs
+++ b/library/core/src/pin.rs
@@ -300,6 +300,7 @@
 //! }
 //!
 //! impl AddrTracker {
+//!     #[allow(unnecessary_refs)]
 //!     fn check_for_move(self: Pin<&mut Self>) {
 //!         let current_addr = &*self as *const Self as usize;
 //!         match self.prev_addr {
diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs
index 7d0839aff3f73..7bac4ec0a9b09 100644
--- a/library/core/src/ptr/const_ptr.rs
+++ b/library/core/src/ptr/const_ptr.rs
@@ -103,6 +103,7 @@ impl<T: ?Sized> *const T {
     ///
     /// ```rust,no_run
     /// #![feature(set_ptr_value)]
+    /// #![allow(unnecessary_refs)]
     /// let x = 0u32;
     /// let y = 1u32;
     ///
@@ -266,6 +267,7 @@ impl<T: ?Sized> *const T {
     /// # Examples
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// let ptr: *const u8 = &10u8 as *const u8;
     ///
     /// unsafe {
@@ -282,6 +284,7 @@ impl<T: ?Sized> *const T {
     /// dereference the pointer directly.
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// let ptr: *const u8 = &10u8 as *const u8;
     ///
     /// unsafe {
@@ -314,6 +317,7 @@ impl<T: ?Sized> *const T {
     ///
     /// ```
     /// #![feature(ptr_as_ref_unchecked)]
+    /// #![allow(unnecessary_refs)]
     /// let ptr: *const u8 = &10u8 as *const u8;
     ///
     /// unsafe {
@@ -351,6 +355,7 @@ impl<T: ?Sized> *const T {
     ///
     /// ```
     /// #![feature(ptr_as_uninit)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// let ptr: *const u8 = &10u8 as *const u8;
     ///
@@ -1416,6 +1421,7 @@ impl<T: ?Sized> *const T {
     /// # Examples
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// // On some platforms, the alignment of i32 is less than 4.
     /// #[repr(align(4))]
     /// struct AlignedI32(i32);
@@ -1449,6 +1455,7 @@ impl<T: ?Sized> *const T {
     ///
     /// ```
     /// #![feature(pointer_is_aligned_to)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// // On some platforms, the alignment of i32 is less than 4.
     /// #[repr(align(4))]
@@ -1564,6 +1571,7 @@ impl<T> *const [T] {
     ///
     /// ```
     /// #![feature(slice_ptr_get)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// let x = &[1, 2, 4] as *const [i32];
     ///
@@ -1663,6 +1671,7 @@ impl<T, const N: usize> *const [T; N] {
     ///
     /// ```
     /// #![feature(array_ptr_get)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// let arr: *const [i32; 3] = &[1, 2, 4] as *const [i32; 3];
     /// let slice: *const [i32] = arr.as_slice();
diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs
index ea53da78d3bd2..a7cf929170623 100644
--- a/library/core/src/ptr/mod.rs
+++ b/library/core/src/ptr/mod.rs
@@ -290,6 +290,7 @@
 //! represent the tagged pointer as an actual pointer and not a `usize`*. For instance:
 //!
 //! ```
+//! #![allow(unnecessary_refs)]
 //! unsafe {
 //!     // A flag we want to pack into our pointer
 //!     static HAS_DATA: usize = 0x1;
@@ -492,6 +493,7 @@ mod mut_ptr;
 /// Manually remove the last item from a vector:
 ///
 /// ```
+/// #![allow(unnecessary_refs)]
 /// use std::ptr;
 /// use std::rc::Rc;
 ///
@@ -759,6 +761,7 @@ pub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T {
 /// Note that this has subtle interactions with the rules for lifetime extension of temporaries in
 /// tail expressions. This code is valid, albeit in a non-obvious way:
 /// ```rust
+/// #![allow(unnecessary_refs)]
 /// # type T = i32;
 /// # fn foo() -> T { 42 }
 /// // 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 {
 /// Note that this has subtle interactions with the rules for lifetime extension of temporaries in
 /// tail expressions. This code is valid, albeit in a non-obvious way:
 /// ```rust
+/// #![allow(unnecessary_refs)]
 /// # type T = i32;
 /// # fn foo() -> T { 42 }
 /// // 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 {
 /// Basic usage:
 ///
 /// ```
+/// #![allow(unnecessary_refs)]
 /// let x = 12;
 /// let y = &x as *const i32;
 ///
@@ -1501,6 +1506,7 @@ pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
 /// Basic usage:
 ///
 /// ```
+/// #![allow(unnecessary_refs)]
 /// let mut x = 0;
 /// let y = &mut x as *mut i32;
 /// let z = 12;
@@ -1722,6 +1728,7 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
 /// Basic usage:
 ///
 /// ```
+/// #![allow(unnecessary_refs)]
 /// let x = 12;
 /// let y = &x as *const i32;
 ///
@@ -1800,6 +1807,7 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
 /// Basic usage:
 ///
 /// ```
+/// #![allow(unnecessary_refs)]
 /// let mut x = 0;
 /// let y = &mut x as *mut i32;
 /// let z = 12;
diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs
index b960a3d86bef0..cc00d4486558b 100644
--- a/library/core/src/ptr/mut_ptr.rs
+++ b/library/core/src/ptr/mut_ptr.rs
@@ -85,6 +85,7 @@ impl<T: ?Sized> *mut T {
     ///
     /// ```rust,no_run
     /// #![feature(set_ptr_value)]
+    /// #![allow(unnecessary_refs)]
     /// let mut x = 0u32;
     /// let mut y = 1u32;
     ///
@@ -256,6 +257,7 @@ impl<T: ?Sized> *mut T {
     /// # Examples
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// let ptr: *mut u8 = &mut 10u8 as *mut u8;
     ///
     /// unsafe {
@@ -272,6 +274,7 @@ impl<T: ?Sized> *mut T {
     /// dereference the pointer directly.
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// let ptr: *mut u8 = &mut 10u8 as *mut u8;
     ///
     /// unsafe {
@@ -306,6 +309,7 @@ impl<T: ?Sized> *mut T {
     ///
     /// ```
     /// #![feature(ptr_as_ref_unchecked)]
+    /// #![allow(unnecessary_refs)]
     /// let ptr: *mut u8 = &mut 10u8 as *mut u8;
     ///
     /// unsafe {
@@ -348,6 +352,7 @@ impl<T: ?Sized> *mut T {
     ///
     /// ```
     /// #![feature(ptr_as_uninit)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// let ptr: *mut u8 = &mut 10u8 as *mut u8;
     ///
@@ -1670,6 +1675,7 @@ impl<T: ?Sized> *mut T {
     /// # Examples
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// // On some platforms, the alignment of i32 is less than 4.
     /// #[repr(align(4))]
     /// struct AlignedI32(i32);
@@ -1703,6 +1709,7 @@ impl<T: ?Sized> *mut T {
     ///
     /// ```
     /// #![feature(pointer_is_aligned_to)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// // On some platforms, the alignment of i32 is less than 4.
     /// #[repr(align(4))]
@@ -1818,6 +1825,7 @@ impl<T> *mut [T] {
     /// ```
     /// #![feature(raw_slice_split)]
     /// #![feature(slice_ptr_get)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// let mut v = [1, 0, 3, 0, 5, 6];
     /// let ptr = &mut v as *mut [_];
@@ -1858,6 +1866,7 @@ impl<T> *mut [T] {
     ///
     /// ```
     /// #![feature(raw_slice_split)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// let mut v = [1, 0, 3, 0, 5, 6];
     /// // scoped to restrict the lifetime of the borrows
@@ -1917,6 +1926,7 @@ impl<T> *mut [T] {
     ///
     /// ```
     /// #![feature(slice_ptr_get)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// let x = &mut [1, 2, 4] as *mut [i32];
     ///
diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs
index c769ba673c61e..f93916556e9c6 100644
--- a/library/core/src/ptr/non_null.rs
+++ b/library/core/src/ptr/non_null.rs
@@ -199,6 +199,7 @@ impl<T: ?Sized> NonNull<T> {
     /// # Examples
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// use std::ptr::NonNull;
     ///
     /// let mut x = 0u32;
@@ -240,6 +241,7 @@ impl<T: ?Sized> NonNull<T> {
     /// # Examples
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// use std::ptr::NonNull;
     ///
     /// let mut x = 0u32;
@@ -407,6 +409,7 @@ impl<T: ?Sized> NonNull<T> {
     /// # Examples
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// use std::ptr::NonNull;
     ///
     /// let mut x = 0u32;
@@ -470,6 +473,7 @@ impl<T: ?Sized> NonNull<T> {
     /// # Examples
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// use std::ptr::NonNull;
     ///
     /// let mut x = 0u32;
@@ -1295,6 +1299,7 @@ impl<T: ?Sized> NonNull<T> {
     ///
     /// ```
     /// #![feature(pointer_is_aligned_to)]
+    /// #![allow(unnecessary_refs)]
     ///
     /// // On some platforms, the alignment of i32 is less than 4.
     /// #[repr(align(4))]
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index 5bb7243c4491b..eea331b862516 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -790,6 +790,7 @@ impl<T> [T] {
     /// element of this slice:
     ///
     /// ```
+    /// #![allow(unnecessary_refs)]
     /// let a = [1, 2, 3];
     /// let x = &a[1] as *const _;
     /// let y = &5 as *const _;
diff --git a/library/core/src/slice/raw.rs b/library/core/src/slice/raw.rs
index 3582c7e8b3f38..f2811fbee0500 100644
--- a/library/core/src/slice/raw.rs
+++ b/library/core/src/slice/raw.rs
@@ -43,6 +43,7 @@ use crate::{array, ptr, ub_checks};
 /// # Examples
 ///
 /// ```
+/// #![allow(unnecessary_refs)]
 /// use std::slice;
 ///
 /// // manifest a slice for a single element
diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs
index 9b1b13e7129ee..dfce4ef2e615b 100644
--- a/library/core/src/sync/atomic.rs
+++ b/library/core/src/sync/atomic.rs
@@ -1426,6 +1426,7 @@ impl<T> AtomicPtr<T> {
     ///
     /// ```
     /// #![feature(atomic_from_mut)]
+    /// #![allow(unnecessary_refs)]
     /// use std::sync::atomic::{AtomicPtr, Ordering};
     ///
     /// let mut data = 123;
@@ -2185,6 +2186,7 @@ impl<T> AtomicPtr<T> {
     ///
     /// ```
     /// #![feature(strict_provenance_atomic_ptr)]
+    /// #![allow(unnecessary_refs)]
     /// use core::sync::atomic::{AtomicPtr, Ordering};
     ///
     /// let pointer = &mut 3i64 as *mut i64;
@@ -2236,6 +2238,7 @@ impl<T> AtomicPtr<T> {
     ///
     /// ```
     /// #![feature(strict_provenance_atomic_ptr)]
+    /// #![allow(unnecessary_refs)]
     /// use core::sync::atomic::{AtomicPtr, Ordering};
     ///
     /// let pointer = &mut 3i64 as *mut i64;
@@ -2286,6 +2289,7 @@ impl<T> AtomicPtr<T> {
     ///
     /// ```
     /// #![feature(strict_provenance_atomic_ptr)]
+    /// #![allow(unnecessary_refs)]
     /// use core::sync::atomic::{AtomicPtr, Ordering};
     ///
     /// let pointer = &mut 3i64 as *mut i64;
diff --git a/library/coretests/tests/atomic.rs b/library/coretests/tests/atomic.rs
index e0c0fe4790c04..39601a79fe69b 100644
--- a/library/coretests/tests/atomic.rs
+++ b/library/coretests/tests/atomic.rs
@@ -146,6 +146,7 @@ fn ptr_add_null() {
 
 #[test]
 #[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn ptr_add_data() {
     let num = 0i64;
     let n = &num as *const i64 as *mut _;
@@ -186,6 +187,7 @@ fn ptr_bitops() {
 
 #[test]
 #[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn ptr_bitops_tagging() {
     #[repr(align(16))]
     struct Tagme(#[allow(dead_code)] u128);
diff --git a/library/coretests/tests/cell.rs b/library/coretests/tests/cell.rs
index d6a401c2b4d98..f5a724c9667f9 100644
--- a/library/coretests/tests/cell.rs
+++ b/library/coretests/tests/cell.rs
@@ -17,6 +17,7 @@ fn smoketest_unsafe_cell() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn unsafe_cell_raw_get() {
     let x = UnsafeCell::new(10);
     let ptr = &x as *const UnsafeCell<i32>;
@@ -89,6 +90,7 @@ fn double_imm_borrow() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn no_mut_then_imm_borrow() {
     let x = RefCell::new(0);
     let _b1 = x.borrow_mut();
diff --git a/library/coretests/tests/const_ptr.rs b/library/coretests/tests/const_ptr.rs
index d874f08317f61..47540009f4c24 100644
--- a/library/coretests/tests/const_ptr.rs
+++ b/library/coretests/tests/const_ptr.rs
@@ -7,6 +7,7 @@ const fn unaligned_ptr() -> *const u16 {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn read() {
     use core::ptr;
 
@@ -23,6 +24,7 @@ fn read() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn const_ptr_read() {
     const FOO: i32 = unsafe { (&42 as *const i32).read() };
     assert_eq!(FOO, 42);
@@ -37,6 +39,7 @@ fn const_ptr_read() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn mut_ptr_read() {
     const FOO: i32 = unsafe { (&42 as *const i32 as *mut i32).read() };
     assert_eq!(FOO, 42);
@@ -51,6 +54,7 @@ fn mut_ptr_read() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn write() {
     use core::ptr;
 
@@ -77,6 +81,7 @@ fn write() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn mut_ptr_write() {
     const fn aligned() -> i32 {
         let mut res = 0;
diff --git a/library/coretests/tests/hash/sip.rs b/library/coretests/tests/hash/sip.rs
index 6add1a33cb931..3e471e6d18581 100644
--- a/library/coretests/tests/hash/sip.rs
+++ b/library/coretests/tests/hash/sip.rs
@@ -304,6 +304,7 @@ fn test_hash_no_concat_alias() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn test_write_short_works() {
     let test_usize = 0xd0c0b0a0usize;
     let mut h1 = SipHasher::new();
diff --git a/library/coretests/tests/ptr.rs b/library/coretests/tests/ptr.rs
index 6091926084a35..6339b582e54ab 100644
--- a/library/coretests/tests/ptr.rs
+++ b/library/coretests/tests/ptr.rs
@@ -108,6 +108,7 @@ fn test_is_null() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn test_as_ref() {
     unsafe {
         let p: *const isize = null();
@@ -165,6 +166,7 @@ fn test_as_ref() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn test_as_mut() {
     unsafe {
         let p: *mut isize = null_mut();
@@ -614,6 +616,7 @@ fn dyn_metadata() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn from_raw_parts() {
     let mut value = 5_u32;
     let address = &mut value as *mut _ as *mut ();
@@ -852,6 +855,7 @@ fn swap_copy_untyped() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn test_const_copy_ptr() {
     // `copy` and `copy_nonoverlapping` are thin layers on top of intrinsics. Ensure they correctly
     // deal with pointers even when the pointers cross the boundary from one "element" being copied
diff --git a/library/coretests/tests/slice.rs b/library/coretests/tests/slice.rs
index d17e681480c70..8f94a279e9f70 100644
--- a/library/coretests/tests/slice.rs
+++ b/library/coretests/tests/slice.rs
@@ -1285,6 +1285,7 @@ fn test_windows_zip() {
 }
 
 #[test]
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn test_iter_ref_consistency() {
     use std::fmt::Debug;
 
diff --git a/library/coretests/tests/waker.rs b/library/coretests/tests/waker.rs
index 4889b8959ece4..fb951ba4e3881 100644
--- a/library/coretests/tests/waker.rs
+++ b/library/coretests/tests/waker.rs
@@ -21,6 +21,7 @@ static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
 );
 
 // https://github.com/rust-lang/rust/issues/102012#issuecomment-1915282956
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 mod nop_waker {
     use core::future::{Future, ready};
     use core::pin::Pin;
diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs
index c07c391892d80..fedd573b71e7b 100644
--- a/library/std/src/keyword_docs.rs
+++ b/library/std/src/keyword_docs.rs
@@ -1399,6 +1399,7 @@ mod self_upper_keyword {}
 /// like [`RefCell`]. See the [Reference] for more information.
 ///
 /// ```rust
+/// # #![allow(unnecessary_refs)]
 /// static FOO: [i32; 5] = [1, 2, 3, 4, 5];
 ///
 /// let r1 = &FOO as *const _;
@@ -1974,6 +1975,7 @@ mod type_keyword {}
 ///
 /// ```rust
 /// # #![allow(dead_code)]
+/// # #![allow(unnecessary_refs)]
 /// #![deny(unsafe_op_in_unsafe_fn)]
 ///
 /// /// Dereference the given pointer.
diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs
index 06bba019393a5..2f58b8364a032 100644
--- a/library/std/src/sys/fs/windows.rs
+++ b/library/std/src/sys/fs/windows.rs
@@ -1149,6 +1149,7 @@ impl DirBuilder {
     }
 }
 
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 pub fn readdir(p: &Path) -> io::Result<ReadDir> {
     // We push a `*` to the end of the path which cause the empty path to be
     // treated as the current directory. So, for consistency with other platforms,
@@ -1420,6 +1421,7 @@ impl ReparsePoint {
     }
 }
 
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn metadata(path: &Path, reparse: ReparsePoint) -> io::Result<FileAttr> {
     let mut opts = OpenOptions::new();
     // No read or write permissions are necessary
diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs
index bdf0cc2c59cf1..b8569e71cd18e 100644
--- a/library/std/src/sys/pal/windows/mod.rs
+++ b/library/std/src/sys/pal/windows/mod.rs
@@ -139,6 +139,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
     }
 }
 
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 pub fn unrolled_find_u16s(needle: u16, haystack: &[u16]) -> Option<usize> {
     let ptr = haystack.as_ptr();
     let mut start = haystack;
diff --git a/library/std/src/thread/tests.rs b/library/std/src/thread/tests.rs
index 59ec48a57d1c6..e33045a3e6022 100644
--- a/library/std/src/thread/tests.rs
+++ b/library/std/src/thread/tests.rs
@@ -147,6 +147,7 @@ fn test_spawn_sched_childs_on_default_sched() {
     rx.recv().unwrap();
 }
 
+#[cfg_attr(not(bootstrap), allow(unnecessary_refs))]
 fn avoid_copying_the_body<F>(spawnfn: F)
 where
     F: FnOnce(Box<dyn Fn() + Send>),
diff --git a/tests/ui/abi/abi-sysv64-arg-passing.rs b/tests/ui/abi/abi-sysv64-arg-passing.rs
index c18752418a1d6..4f2783e237116 100644
--- a/tests/ui/abi/abi-sysv64-arg-passing.rs
+++ b/tests/ui/abi/abi-sysv64-arg-passing.rs
@@ -32,6 +32,7 @@
 // Windows is ignored because bootstrap doesn't yet know to compile rust_test_helpers with
 // the sysv64 ABI on Windows.
 
+#![allow(unnecessary_refs)]
 #[allow(dead_code)]
 #[allow(improper_ctypes)]
 
diff --git a/tests/ui/abi/simd-abi-checks-s390x.rs b/tests/ui/abi/simd-abi-checks-s390x.rs
index 3743c75bf1ed5..8a27072453c89 100644
--- a/tests/ui/abi/simd-abi-checks-s390x.rs
+++ b/tests/ui/abi/simd-abi-checks-s390x.rs
@@ -14,6 +14,7 @@
 #![crate_type = "lib"]
 #![allow(non_camel_case_types, improper_ctypes_definitions)]
 #![deny(abi_unsupported_vector_types)]
+#![allow(unnecessary_refs)]
 
 extern crate minicore;
 use minicore::*;
diff --git a/tests/ui/abi/simd-abi-checks-s390x.z10.stderr b/tests/ui/abi/simd-abi-checks-s390x.z10.stderr
index d2f7abb7c3221..2ac5150ff9c6f 100644
--- a/tests/ui/abi/simd-abi-checks-s390x.z10.stderr
+++ b/tests/ui/abi/simd-abi-checks-s390x.z10.stderr
@@ -1,5 +1,5 @@
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:39:1
+  --> $DIR/simd-abi-checks-s390x.rs:40:1
    |
 LL | extern "C" fn vector_ret_small(x: &i8x8) -> i8x8 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -14,7 +14,7 @@ LL | #![deny(abi_unsupported_vector_types)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:45:1
+  --> $DIR/simd-abi-checks-s390x.rs:46:1
    |
 LL | extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -24,7 +24,7 @@ LL | extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:92:1
+  --> $DIR/simd-abi-checks-s390x.rs:93:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret_small(
 LL | |     x: &TransparentWrapper<i8x8>,
@@ -36,7 +36,7 @@ LL | | ) -> TransparentWrapper<i8x8> {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:100:1
+  --> $DIR/simd-abi-checks-s390x.rs:101:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret(
 LL | |     x: &TransparentWrapper<i8x16>,
@@ -48,7 +48,7 @@ LL | | ) -> TransparentWrapper<i8x16> {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:116:1
+  --> $DIR/simd-abi-checks-s390x.rs:117:1
    |
 LL | extern "C" fn vector_arg_small(x: i8x8) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -58,7 +58,7 @@ LL | extern "C" fn vector_arg_small(x: i8x8) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:122:1
+  --> $DIR/simd-abi-checks-s390x.rs:123:1
    |
 LL | extern "C" fn vector_arg(x: i8x16) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -68,7 +68,7 @@ LL | extern "C" fn vector_arg(x: i8x16) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `Wrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:134:1
+  --> $DIR/simd-abi-checks-s390x.rs:135:1
    |
 LL | extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -78,7 +78,7 @@ LL | extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `Wrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:140:1
+  --> $DIR/simd-abi-checks-s390x.rs:141:1
    |
 LL | extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -88,7 +88,7 @@ LL | extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:152:1
+  --> $DIR/simd-abi-checks-s390x.rs:153:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -98,7 +98,7 @@ LL | extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:158:1
+  --> $DIR/simd-abi-checks-s390x.rs:159:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg(x: TransparentWrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -111,7 +111,7 @@ error: aborting due to 10 previous errors
 
 Future incompatibility report: Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:39:1
+  --> $DIR/simd-abi-checks-s390x.rs:40:1
    |
 LL | extern "C" fn vector_ret_small(x: &i8x8) -> i8x8 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -127,7 +127,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:45:1
+  --> $DIR/simd-abi-checks-s390x.rs:46:1
    |
 LL | extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -143,7 +143,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:92:1
+  --> $DIR/simd-abi-checks-s390x.rs:93:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret_small(
 LL | |     x: &TransparentWrapper<i8x8>,
@@ -161,7 +161,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:100:1
+  --> $DIR/simd-abi-checks-s390x.rs:101:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret(
 LL | |     x: &TransparentWrapper<i8x16>,
@@ -179,7 +179,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:116:1
+  --> $DIR/simd-abi-checks-s390x.rs:117:1
    |
 LL | extern "C" fn vector_arg_small(x: i8x8) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -195,7 +195,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:122:1
+  --> $DIR/simd-abi-checks-s390x.rs:123:1
    |
 LL | extern "C" fn vector_arg(x: i8x16) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -211,7 +211,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `Wrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:134:1
+  --> $DIR/simd-abi-checks-s390x.rs:135:1
    |
 LL | extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -227,7 +227,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `Wrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:140:1
+  --> $DIR/simd-abi-checks-s390x.rs:141:1
    |
 LL | extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -243,7 +243,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:152:1
+  --> $DIR/simd-abi-checks-s390x.rs:153:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -259,7 +259,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:158:1
+  --> $DIR/simd-abi-checks-s390x.rs:159:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg(x: TransparentWrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
diff --git a/tests/ui/abi/simd-abi-checks-s390x.z13_no_vector.stderr b/tests/ui/abi/simd-abi-checks-s390x.z13_no_vector.stderr
index d2f7abb7c3221..2ac5150ff9c6f 100644
--- a/tests/ui/abi/simd-abi-checks-s390x.z13_no_vector.stderr
+++ b/tests/ui/abi/simd-abi-checks-s390x.z13_no_vector.stderr
@@ -1,5 +1,5 @@
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:39:1
+  --> $DIR/simd-abi-checks-s390x.rs:40:1
    |
 LL | extern "C" fn vector_ret_small(x: &i8x8) -> i8x8 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -14,7 +14,7 @@ LL | #![deny(abi_unsupported_vector_types)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:45:1
+  --> $DIR/simd-abi-checks-s390x.rs:46:1
    |
 LL | extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -24,7 +24,7 @@ LL | extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:92:1
+  --> $DIR/simd-abi-checks-s390x.rs:93:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret_small(
 LL | |     x: &TransparentWrapper<i8x8>,
@@ -36,7 +36,7 @@ LL | | ) -> TransparentWrapper<i8x8> {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:100:1
+  --> $DIR/simd-abi-checks-s390x.rs:101:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret(
 LL | |     x: &TransparentWrapper<i8x16>,
@@ -48,7 +48,7 @@ LL | | ) -> TransparentWrapper<i8x16> {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:116:1
+  --> $DIR/simd-abi-checks-s390x.rs:117:1
    |
 LL | extern "C" fn vector_arg_small(x: i8x8) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -58,7 +58,7 @@ LL | extern "C" fn vector_arg_small(x: i8x8) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:122:1
+  --> $DIR/simd-abi-checks-s390x.rs:123:1
    |
 LL | extern "C" fn vector_arg(x: i8x16) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -68,7 +68,7 @@ LL | extern "C" fn vector_arg(x: i8x16) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `Wrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:134:1
+  --> $DIR/simd-abi-checks-s390x.rs:135:1
    |
 LL | extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -78,7 +78,7 @@ LL | extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `Wrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:140:1
+  --> $DIR/simd-abi-checks-s390x.rs:141:1
    |
 LL | extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -88,7 +88,7 @@ LL | extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:152:1
+  --> $DIR/simd-abi-checks-s390x.rs:153:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -98,7 +98,7 @@ LL | extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:158:1
+  --> $DIR/simd-abi-checks-s390x.rs:159:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg(x: TransparentWrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -111,7 +111,7 @@ error: aborting due to 10 previous errors
 
 Future incompatibility report: Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:39:1
+  --> $DIR/simd-abi-checks-s390x.rs:40:1
    |
 LL | extern "C" fn vector_ret_small(x: &i8x8) -> i8x8 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -127,7 +127,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:45:1
+  --> $DIR/simd-abi-checks-s390x.rs:46:1
    |
 LL | extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -143,7 +143,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:92:1
+  --> $DIR/simd-abi-checks-s390x.rs:93:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret_small(
 LL | |     x: &TransparentWrapper<i8x8>,
@@ -161,7 +161,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:100:1
+  --> $DIR/simd-abi-checks-s390x.rs:101:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret(
 LL | |     x: &TransparentWrapper<i8x16>,
@@ -179,7 +179,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:116:1
+  --> $DIR/simd-abi-checks-s390x.rs:117:1
    |
 LL | extern "C" fn vector_arg_small(x: i8x8) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -195,7 +195,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:122:1
+  --> $DIR/simd-abi-checks-s390x.rs:123:1
    |
 LL | extern "C" fn vector_arg(x: i8x16) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -211,7 +211,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `Wrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:134:1
+  --> $DIR/simd-abi-checks-s390x.rs:135:1
    |
 LL | extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -227,7 +227,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `Wrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:140:1
+  --> $DIR/simd-abi-checks-s390x.rs:141:1
    |
 LL | extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -243,7 +243,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:152:1
+  --> $DIR/simd-abi-checks-s390x.rs:153:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -259,7 +259,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:158:1
+  --> $DIR/simd-abi-checks-s390x.rs:159:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg(x: TransparentWrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
diff --git a/tests/ui/abi/simd-abi-checks-s390x.z13_soft_float.stderr b/tests/ui/abi/simd-abi-checks-s390x.z13_soft_float.stderr
index d2f7abb7c3221..2ac5150ff9c6f 100644
--- a/tests/ui/abi/simd-abi-checks-s390x.z13_soft_float.stderr
+++ b/tests/ui/abi/simd-abi-checks-s390x.z13_soft_float.stderr
@@ -1,5 +1,5 @@
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:39:1
+  --> $DIR/simd-abi-checks-s390x.rs:40:1
    |
 LL | extern "C" fn vector_ret_small(x: &i8x8) -> i8x8 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -14,7 +14,7 @@ LL | #![deny(abi_unsupported_vector_types)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:45:1
+  --> $DIR/simd-abi-checks-s390x.rs:46:1
    |
 LL | extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -24,7 +24,7 @@ LL | extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:92:1
+  --> $DIR/simd-abi-checks-s390x.rs:93:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret_small(
 LL | |     x: &TransparentWrapper<i8x8>,
@@ -36,7 +36,7 @@ LL | | ) -> TransparentWrapper<i8x8> {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:100:1
+  --> $DIR/simd-abi-checks-s390x.rs:101:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret(
 LL | |     x: &TransparentWrapper<i8x16>,
@@ -48,7 +48,7 @@ LL | | ) -> TransparentWrapper<i8x16> {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:116:1
+  --> $DIR/simd-abi-checks-s390x.rs:117:1
    |
 LL | extern "C" fn vector_arg_small(x: i8x8) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -58,7 +58,7 @@ LL | extern "C" fn vector_arg_small(x: i8x8) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:122:1
+  --> $DIR/simd-abi-checks-s390x.rs:123:1
    |
 LL | extern "C" fn vector_arg(x: i8x16) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -68,7 +68,7 @@ LL | extern "C" fn vector_arg(x: i8x16) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `Wrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:134:1
+  --> $DIR/simd-abi-checks-s390x.rs:135:1
    |
 LL | extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -78,7 +78,7 @@ LL | extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `Wrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:140:1
+  --> $DIR/simd-abi-checks-s390x.rs:141:1
    |
 LL | extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -88,7 +88,7 @@ LL | extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:152:1
+  --> $DIR/simd-abi-checks-s390x.rs:153:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -98,7 +98,7 @@ LL | extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8
    = help: consider enabling it globally (`-C target-feature=+vector`) or locally (`#[target_feature(enable="vector")]`)
 
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:158:1
+  --> $DIR/simd-abi-checks-s390x.rs:159:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg(x: TransparentWrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -111,7 +111,7 @@ error: aborting due to 10 previous errors
 
 Future incompatibility report: Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:39:1
+  --> $DIR/simd-abi-checks-s390x.rs:40:1
    |
 LL | extern "C" fn vector_ret_small(x: &i8x8) -> i8x8 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -127,7 +127,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:45:1
+  --> $DIR/simd-abi-checks-s390x.rs:46:1
    |
 LL | extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -143,7 +143,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:92:1
+  --> $DIR/simd-abi-checks-s390x.rs:93:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret_small(
 LL | |     x: &TransparentWrapper<i8x8>,
@@ -161,7 +161,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:100:1
+  --> $DIR/simd-abi-checks-s390x.rs:101:1
    |
 LL | / extern "C" fn vector_transparent_wrapper_ret(
 LL | |     x: &TransparentWrapper<i8x16>,
@@ -179,7 +179,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x8` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:116:1
+  --> $DIR/simd-abi-checks-s390x.rs:117:1
    |
 LL | extern "C" fn vector_arg_small(x: i8x8) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -195,7 +195,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `i8x16` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:122:1
+  --> $DIR/simd-abi-checks-s390x.rs:123:1
    |
 LL | extern "C" fn vector_arg(x: i8x16) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -211,7 +211,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `Wrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:134:1
+  --> $DIR/simd-abi-checks-s390x.rs:135:1
    |
 LL | extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -227,7 +227,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `Wrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:140:1
+  --> $DIR/simd-abi-checks-s390x.rs:141:1
    |
 LL | extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -243,7 +243,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x8>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:152:1
+  --> $DIR/simd-abi-checks-s390x.rs:153:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8x8>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -259,7 +259,7 @@ LL | #![deny(abi_unsupported_vector_types)]
 
 Future breakage diagnostic:
 error: this function definition uses SIMD vector type `TransparentWrapper<i8x16>` which (with the chosen ABI) requires the `vector` target feature, which is not enabled
-  --> $DIR/simd-abi-checks-s390x.rs:158:1
+  --> $DIR/simd-abi-checks-s390x.rs:159:1
    |
 LL | extern "C" fn vector_transparent_wrapper_arg(x: TransparentWrapper<i8x16>) -> i64 {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
diff --git a/tests/ui/abi/stack-protector.rs b/tests/ui/abi/stack-protector.rs
index 29332861977b7..42cd85015de6d 100644
--- a/tests/ui/abi/stack-protector.rs
+++ b/tests/ui/abi/stack-protector.rs
@@ -5,6 +5,8 @@
 //@ compile-flags: -C opt-level=2
 //@ compile-flags: -g
 
+#![allow(unnecessary_refs)]
+
 use std::env;
 use std::process::{Command, ExitStatus};
 
diff --git a/tests/ui/asm/issue-97490.rs b/tests/ui/asm/issue-97490.rs
index 5f364a22bc437..1a43a92095d11 100644
--- a/tests/ui/asm/issue-97490.rs
+++ b/tests/ui/asm/issue-97490.rs
@@ -2,6 +2,8 @@
 //@ only-x86_64
 //@ needs-asm-support
 
+#![allow(unnecessary_refs)]
+
 pub type Yes = extern "sysv64" fn(&'static u8) -> !;
 
 fn main() {
diff --git a/tests/ui/asm/issue-99122-2.rs b/tests/ui/asm/issue-99122-2.rs
index 6ac5f059a624e..e88cf2fed3fd8 100644
--- a/tests/ui/asm/issue-99122-2.rs
+++ b/tests/ui/asm/issue-99122-2.rs
@@ -2,6 +2,8 @@
 //@ needs-asm-support
 //@ only-x86_64
 
+#![allow(unnecessary_refs)]
+
 // This demonstrates why we need to erase regions before sized check in intrinsicck
 
 struct NoCopy;
diff --git a/tests/ui/asm/x86_64/sym.rs b/tests/ui/asm/x86_64/sym.rs
index 0a86bd66ccbc1..2ba0819e66a53 100644
--- a/tests/ui/asm/x86_64/sym.rs
+++ b/tests/ui/asm/x86_64/sym.rs
@@ -4,6 +4,7 @@
 //@ run-pass
 
 #![feature(thread_local)]
+#![allow(unnecessary_refs)]
 
 use std::arch::asm;
 
diff --git a/tests/ui/binding/zero_sized_subslice_match.rs b/tests/ui/binding/zero_sized_subslice_match.rs
index 6da9f9593b44f..f9cb2073f1a0d 100644
--- a/tests/ui/binding/zero_sized_subslice_match.rs
+++ b/tests/ui/binding/zero_sized_subslice_match.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 fn main() {
     let x = [(), ()];
 
diff --git a/tests/ui/borrowck/borrow-raw-address-of-deref-mutability-ok.rs b/tests/ui/borrowck/borrow-raw-address-of-deref-mutability-ok.rs
index 234097952274b..9322a4f9993d9 100644
--- a/tests/ui/borrowck/borrow-raw-address-of-deref-mutability-ok.rs
+++ b/tests/ui/borrowck/borrow-raw-address-of-deref-mutability-ok.rs
@@ -1,5 +1,7 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
+
 fn raw_reborrow() {
     let x = &0;
     let y = &mut 0;
diff --git a/tests/ui/borrowck/borrowck-borrow-from-expr-block.rs b/tests/ui/borrowck/borrowck-borrow-from-expr-block.rs
index 3718d7fd23c8f..500a7beb9d2db 100644
--- a/tests/ui/borrowck/borrowck-borrow-from-expr-block.rs
+++ b/tests/ui/borrowck/borrowck-borrow-from-expr-block.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 fn borrow<F>(x: &isize, f: F) where F: FnOnce(&isize) {
     f(x)
 }
diff --git a/tests/ui/cast/cast-region-to-uint.rs b/tests/ui/cast/cast-region-to-uint.rs
index 6f4edadafee51..1469c09d22c08 100644
--- a/tests/ui/cast/cast-region-to-uint.rs
+++ b/tests/ui/cast/cast-region-to-uint.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 pub fn main() {
     let x: isize = 3;
     println!("&x={:x}", (&x as *const isize as usize));
diff --git a/tests/ui/cast/cast-rfc0401.rs b/tests/ui/cast/cast-rfc0401.rs
index f917f93a1c824..a1288a5cd4fb5 100644
--- a/tests/ui/cast/cast-rfc0401.rs
+++ b/tests/ui/cast/cast-rfc0401.rs
@@ -1,6 +1,7 @@
 //@ run-pass
 
 #![allow(dead_code)]
+#![allow(unnecessary_refs)]
 
 use std::vec;
 
diff --git a/tests/ui/cast/issue-84213.fixed b/tests/ui/cast/issue-84213.fixed
index a0dc4a896668d..764ffc98ae6bf 100644
--- a/tests/ui/cast/issue-84213.fixed
+++ b/tests/ui/cast/issue-84213.fixed
@@ -1,5 +1,7 @@
 //@ run-rustfix
 
+#![allow(unnecessary_refs)]
+
 struct Something {
     pub field: u32,
 }
diff --git a/tests/ui/cast/issue-84213.rs b/tests/ui/cast/issue-84213.rs
index 93b584c6d35a3..8b04da34d17ea 100644
--- a/tests/ui/cast/issue-84213.rs
+++ b/tests/ui/cast/issue-84213.rs
@@ -1,5 +1,7 @@
 //@ run-rustfix
 
+#![allow(unnecessary_refs)]
+
 struct Something {
     pub field: u32,
 }
diff --git a/tests/ui/cast/issue-84213.stderr b/tests/ui/cast/issue-84213.stderr
index 025970e54c84a..d5d739133b8fb 100644
--- a/tests/ui/cast/issue-84213.stderr
+++ b/tests/ui/cast/issue-84213.stderr
@@ -1,5 +1,5 @@
 error[E0605]: non-primitive cast: `Something` as `*const Something`
-  --> $DIR/issue-84213.rs:11:33
+  --> $DIR/issue-84213.rs:13:33
    |
 LL |     let _pointer_to_something = something as *const Something;
    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
@@ -10,7 +10,7 @@ LL |     let _pointer_to_something = &something as *const Something;
    |                                 +
 
 error[E0605]: non-primitive cast: `Something` as `*mut Something`
-  --> $DIR/issue-84213.rs:14:37
+  --> $DIR/issue-84213.rs:16:37
    |
 LL |     let _mut_pointer_to_something = something as *mut Something;
    |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
diff --git a/tests/ui/cast/issue-89497.fixed b/tests/ui/cast/issue-89497.fixed
index 4229199fa43a1..ddd2f1841444b 100644
--- a/tests/ui/cast/issue-89497.fixed
+++ b/tests/ui/cast/issue-89497.fixed
@@ -2,6 +2,8 @@
 
 //@ run-rustfix
 
+#![allow(unnecessary_refs)]
+
 fn main() {
     let pointer: usize = &1_i32 as *const i32 as usize;
     let _reference: &'static i32 = unsafe { &*(pointer as *const i32) };
diff --git a/tests/ui/cast/issue-89497.rs b/tests/ui/cast/issue-89497.rs
index e934560ddabab..de8dd45bc36fd 100644
--- a/tests/ui/cast/issue-89497.rs
+++ b/tests/ui/cast/issue-89497.rs
@@ -2,6 +2,8 @@
 
 //@ run-rustfix
 
+#![allow(unnecessary_refs)]
+
 fn main() {
     let pointer: usize = &1_i32 as *const i32 as usize;
     let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 };
diff --git a/tests/ui/cast/issue-89497.stderr b/tests/ui/cast/issue-89497.stderr
index 1208ca45d50ea..ceec23b680a42 100644
--- a/tests/ui/cast/issue-89497.stderr
+++ b/tests/ui/cast/issue-89497.stderr
@@ -1,5 +1,5 @@
 error[E0605]: non-primitive cast: `*const i32` as `&'static i32`
-  --> $DIR/issue-89497.rs:7:45
+  --> $DIR/issue-89497.rs:9:45
    |
 LL |     let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 };
    |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
diff --git a/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs b/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs
index ac8108d8ec41b..e80c89c3680ec 100644
--- a/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs
+++ b/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs
@@ -1,5 +1,7 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
+
 trait Trait: Send {}
 impl Trait for () {}
 
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed b/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed
index c1d88cbdf8374..1a4c236773d93 100644
--- a/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed
+++ b/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed
@@ -1,6 +1,7 @@
 //@ run-rustfix
 #![deny(rust_2021_incompatible_closure_captures)]
 //~^ NOTE: the lint level is defined here
+#![allow(unnecessary_refs)]
 
 use std::thread;
 
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.rs b/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.rs
index 6b452fcdaf111..1538b5d432ff2 100644
--- a/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.rs
+++ b/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.rs
@@ -1,6 +1,7 @@
 //@ run-rustfix
 #![deny(rust_2021_incompatible_closure_captures)]
 //~^ NOTE: the lint level is defined here
+#![allow(unnecessary_refs)]
 
 use std::thread;
 
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr b/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr
index fdcada468e093..bf2ac91a333b5 100644
--- a/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr
+++ b/tests/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr
@@ -1,5 +1,5 @@
 error: changes to closure capture in Rust 2021 will affect which traits the closure implements
-  --> $DIR/auto_traits.rs:22:19
+  --> $DIR/auto_traits.rs:23:19
    |
 LL |     thread::spawn(move || unsafe {
    |                   ^^^^^^^ in Rust 2018, this closure implements `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` because `fptr` is not fully captured and `fptr.0` does not implement `Send`
@@ -23,7 +23,7 @@ LL ~     } }).join().unwrap();
    |
 
 error: changes to closure capture in Rust 2021 will affect which traits the closure implements
-  --> $DIR/auto_traits.rs:42:19
+  --> $DIR/auto_traits.rs:43:19
    |
 LL |     thread::spawn(move || unsafe {
    |                   ^^^^^^^
@@ -45,7 +45,7 @@ LL ~     } }).join().unwrap();
    |
 
 error: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements
-  --> $DIR/auto_traits.rs:67:13
+  --> $DIR/auto_traits.rs:68:13
    |
 LL |     let c = || {
    |             ^^ in Rust 2018, this closure implements `Clone` as `f` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f` is not fully captured and `f.1` does not implement `Clone`
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.fixed b/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.fixed
index 8bbd7fab569c8..246cb3d5c80c6 100644
--- a/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.fixed
+++ b/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.fixed
@@ -1,6 +1,7 @@
 //@ run-rustfix
 #![deny(rust_2021_incompatible_closure_captures)]
 //~^ NOTE: the lint level is defined here
+#![allow(unnecessary_refs)]
 
 use std::thread;
 
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.rs b/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.rs
index 62fe1581bac04..4893353b48f90 100644
--- a/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.rs
+++ b/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.rs
@@ -1,6 +1,7 @@
 //@ run-rustfix
 #![deny(rust_2021_incompatible_closure_captures)]
 //~^ NOTE: the lint level is defined here
+#![allow(unnecessary_refs)]
 
 use std::thread;
 
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr b/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr
index 138778ff5d723..34a42f416a3d4 100644
--- a/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr
+++ b/tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr
@@ -1,5 +1,5 @@
 error: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements
-  --> $DIR/multi_diagnostics.rs:37:13
+  --> $DIR/multi_diagnostics.rs:38:13
    |
 LL |     let c = || {
    |             ^^ in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f1` is not fully captured and `f1.0` does not implement `Clone`
@@ -26,7 +26,7 @@ LL +         let _ = (&f1, &f2);
    |
 
 error: changes to closure capture in Rust 2021 will affect which traits the closure implements
-  --> $DIR/multi_diagnostics.rs:56:13
+  --> $DIR/multi_diagnostics.rs:57:13
    |
 LL |     let c = || {
    |             ^^ in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f1` is not fully captured and `f1.0` does not implement `Clone`
@@ -42,7 +42,7 @@ LL +         let _ = &f1;
    |
 
 error: changes to closure capture in Rust 2021 will affect which traits the closure implements
-  --> $DIR/multi_diagnostics.rs:81:13
+  --> $DIR/multi_diagnostics.rs:82:13
    |
 LL |     let c = || {
    |             ^^
@@ -64,7 +64,7 @@ LL +         let _ = &f1;
    |
 
 error: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements
-  --> $DIR/multi_diagnostics.rs:100:13
+  --> $DIR/multi_diagnostics.rs:101:13
    |
 LL |     let c = || {
    |             ^^ in Rust 2018, this closure implements `Clone` as `f1` implements `Clone`, but in Rust 2021, this closure will no longer implement `Clone` because `f1` is not fully captured and `f1.0` does not implement `Clone`
@@ -89,7 +89,7 @@ LL +         let _ = &f1;
    |
 
 error: changes to closure capture in Rust 2021 will affect which traits the closure implements
-  --> $DIR/multi_diagnostics.rs:133:19
+  --> $DIR/multi_diagnostics.rs:134:19
    |
 LL |     thread::spawn(move || unsafe {
    |                   ^^^^^^^
diff --git a/tests/ui/codegen/StackColoring-not-blowup-stack-issue-40883.rs b/tests/ui/codegen/StackColoring-not-blowup-stack-issue-40883.rs
index a4646d67c6847..6fca9321d98af 100644
--- a/tests/ui/codegen/StackColoring-not-blowup-stack-issue-40883.rs
+++ b/tests/ui/codegen/StackColoring-not-blowup-stack-issue-40883.rs
@@ -1,5 +1,5 @@
 //@ run-pass
-#![allow(dead_code)]
+#![allow(dead_code, unnecessary_refs)]
 // check that we don't have linear stack usage with multiple calls to `push`
 
 #![feature(test)]
diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/basic.stderr b/tests/ui/codegen/equal-pointers-unequal/as-cast/basic.stderr
new file mode 100644
index 0000000000000..b65aa596da9b1
--- /dev/null
+++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/basic.stderr
@@ -0,0 +1,27 @@
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/basic.rs:8:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unnecessary_refs)]` on by default
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/basic.rs:12:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/function.stderr b/tests/ui/codegen/equal-pointers-unequal/as-cast/function.stderr
new file mode 100644
index 0000000000000..9c916f33a96e3
--- /dev/null
+++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/function.stderr
@@ -0,0 +1,15 @@
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/function.rs:9:5
+   |
+LL |     &v as *const _ as usize
+   |     ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unnecessary_refs)]` on by default
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -     &v as *const _ as usize
+LL +     &raw const v as usize
+   |
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/inline1.stderr b/tests/ui/codegen/equal-pointers-unequal/as-cast/inline1.stderr
new file mode 100644
index 0000000000000..49b6a59bcc0b3
--- /dev/null
+++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/inline1.stderr
@@ -0,0 +1,27 @@
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/inline1.rs:20:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unnecessary_refs)]` on by default
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/inline1.rs:24:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/inline2.stderr b/tests/ui/codegen/equal-pointers-unequal/as-cast/inline2.stderr
new file mode 100644
index 0000000000000..033f630b9aad7
--- /dev/null
+++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/inline2.stderr
@@ -0,0 +1,27 @@
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/inline2.rs:20:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unnecessary_refs)]` on by default
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/inline2.rs:24:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/print.stderr b/tests/ui/codegen/equal-pointers-unequal/as-cast/print.stderr
new file mode 100644
index 0000000000000..21e83bcfccd1c
--- /dev/null
+++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/print.stderr
@@ -0,0 +1,27 @@
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/print.rs:10:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unnecessary_refs)]` on by default
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/print.rs:14:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/print3.stderr b/tests/ui/codegen/equal-pointers-unequal/as-cast/print3.stderr
new file mode 100644
index 0000000000000..37d0c4fe1ae3e
--- /dev/null
+++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/print3.stderr
@@ -0,0 +1,27 @@
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/print3.rs:10:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unnecessary_refs)]` on by default
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/print3.rs:14:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/segfault.stderr b/tests/ui/codegen/equal-pointers-unequal/as-cast/segfault.stderr
new file mode 100644
index 0000000000000..0218360d353d3
--- /dev/null
+++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/segfault.stderr
@@ -0,0 +1,27 @@
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/segfault.rs:12:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unnecessary_refs)]` on by default
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/segfault.rs:16:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/codegen/equal-pointers-unequal/as-cast/zero.stderr b/tests/ui/codegen/equal-pointers-unequal/as-cast/zero.stderr
new file mode 100644
index 0000000000000..bebe0726ee180
--- /dev/null
+++ b/tests/ui/codegen/equal-pointers-unequal/as-cast/zero.stderr
@@ -0,0 +1,27 @@
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/zero.rs:10:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unnecessary_refs)]` on by default
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/zero.rs:14:9
+   |
+LL |         &v as *const _ as usize
+   |         ^^^^^^^^^^^^^^
+   |
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -         &v as *const _ as usize
+LL +         &raw const v as usize
+   |
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/codegen/issue-63787.rs b/tests/ui/codegen/issue-63787.rs
index b8de6d3c5c895..1fc1480c137b1 100644
--- a/tests/ui/codegen/issue-63787.rs
+++ b/tests/ui/codegen/issue-63787.rs
@@ -7,6 +7,8 @@
 // Adapted from comex's proof of concept:
 // https://github.com/rust-lang/rust/issues/63787#issuecomment-523588164
 
+#![allow(unnecessary_refs)]
+
 use std::cell::RefCell;
 use std::ops::Deref;
 
diff --git a/tests/ui/const-generics/generic_const_exprs/infer-too-generic.rs b/tests/ui/const-generics/generic_const_exprs/infer-too-generic.rs
index 4ebb07e32f11d..16e84f06dbadc 100644
--- a/tests/ui/const-generics/generic_const_exprs/infer-too-generic.rs
+++ b/tests/ui/const-generics/generic_const_exprs/infer-too-generic.rs
@@ -1,6 +1,7 @@
 //@ run-pass
 #![feature(generic_const_exprs)]
 #![allow(incomplete_features)]
+#![allow(unnecessary_refs)]
 
 use std::{mem, ptr};
 
diff --git a/tests/ui/const-generics/type-dependent/issue-61936.rs b/tests/ui/const-generics/type-dependent/issue-61936.rs
index 24fc4d4a62daf..200a0e2d36495 100644
--- a/tests/ui/const-generics/type-dependent/issue-61936.rs
+++ b/tests/ui/const-generics/type-dependent/issue-61936.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 trait SliceExt<T: Clone> {
     fn array_windows_example<'a, const N: usize>(&'a self) -> ArrayWindowsExample<'a, T, N>;
 }
diff --git a/tests/ui/const-ptr/allowed_slices.rs b/tests/ui/const-ptr/allowed_slices.rs
index e5b9966c60930..3fed7e3e77963 100644
--- a/tests/ui/const-ptr/allowed_slices.rs
+++ b/tests/ui/const-ptr/allowed_slices.rs
@@ -1,4 +1,5 @@
 //@ run-pass
+#![allow(unnecessary_refs)]
 #![feature(
     slice_from_ptr_range,
     const_slice_from_ptr_range,
diff --git a/tests/ui/const_prop/const-prop-ice3.rs b/tests/ui/const_prop/const-prop-ice3.rs
index 34b662922ae6e..9b764507af789 100644
--- a/tests/ui/const_prop/const-prop-ice3.rs
+++ b/tests/ui/const_prop/const-prop-ice3.rs
@@ -1,5 +1,7 @@
 //@ run-pass (ensure that const-prop is run)
 
+#![allow(unnecessary_refs)]
+
 struct A<T: ?Sized>(T);
 
 fn main() {
diff --git a/tests/ui/consts/const-eval/extern_fat_pointer.rs b/tests/ui/consts/const-eval/extern_fat_pointer.rs
index d03415aa2695e..e91e2b349d057 100644
--- a/tests/ui/consts/const-eval/extern_fat_pointer.rs
+++ b/tests/ui/consts/const-eval/extern_fat_pointer.rs
@@ -1,5 +1,6 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
 #![feature(extern_types)]
 
 extern "C" {
diff --git a/tests/ui/consts/const-eval/nonnull_as_ref.rs b/tests/ui/consts/const-eval/nonnull_as_ref.rs
index 003b28febff05..2d0a26c9e881b 100644
--- a/tests/ui/consts/const-eval/nonnull_as_ref.rs
+++ b/tests/ui/consts/const-eval/nonnull_as_ref.rs
@@ -1,5 +1,7 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
+
 use std::ptr::NonNull;
 
 const NON_NULL: NonNull<u8> = unsafe { NonNull::new_unchecked((&42u8 as *const u8).cast_mut()) };
diff --git a/tests/ui/consts/extra-const-ub/detect-extra-ub.rs b/tests/ui/consts/extra-const-ub/detect-extra-ub.rs
index d2b157e03e7cb..b9f250370f0ab 100644
--- a/tests/ui/consts/extra-const-ub/detect-extra-ub.rs
+++ b/tests/ui/consts/extra-const-ub/detect-extra-ub.rs
@@ -1,6 +1,8 @@
 //@ revisions: no_flag with_flag
 //@ [no_flag] check-pass
 //@ [with_flag] compile-flags: -Zextra-const-ub-checks
+
+#![allow(unnecessary_refs)]
 #![feature(never_type)]
 
 use std::mem::transmute;
diff --git a/tests/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr b/tests/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr
index 0100aafb6b7c6..b5f956f049f50 100644
--- a/tests/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr
+++ b/tests/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr
@@ -1,11 +1,11 @@
 error[E0080]: evaluation of constant value failed
-  --> $DIR/detect-extra-ub.rs:29:20
+  --> $DIR/detect-extra-ub.rs:31:20
    |
 LL |     let _x: bool = transmute(3u8);
    |                    ^^^^^^^^^^^^^^ constructing invalid value: encountered 0x03, but expected a boolean
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/detect-extra-ub.rs:35:21
+  --> $DIR/detect-extra-ub.rs:37:21
    |
 LL |     let _x: usize = transmute(&3u8);
    |                     ^^^^^^^^^^^^^^^ constructing invalid value: encountered a pointer, but expected an integer
@@ -14,7 +14,7 @@ LL |     let _x: usize = transmute(&3u8);
    = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/detect-extra-ub.rs:41:28
+  --> $DIR/detect-extra-ub.rs:43:28
    |
 LL |     let _x: PtrSizedEnum = transmute(&3u8);
    |                            ^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered a pointer, but expected an integer
@@ -23,7 +23,7 @@ LL |     let _x: PtrSizedEnum = transmute(&3u8);
    = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/detect-extra-ub.rs:48:30
+  --> $DIR/detect-extra-ub.rs:50:30
    |
 LL |     let _x: (usize, usize) = transmute(x);
    |                              ^^^^^^^^^^^^ constructing invalid value at .0: encountered a pointer, but expected an integer
@@ -32,19 +32,19 @@ LL |     let _x: (usize, usize) = transmute(x);
    = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/detect-extra-ub.rs:54:20
+  --> $DIR/detect-extra-ub.rs:56:20
    |
 LL |     let _x: &u32 = transmute(&[0u8; 4]);
    |                    ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 4 byte alignment but found 1)
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/detect-extra-ub.rs:62:13
+  --> $DIR/detect-extra-ub.rs:64:13
    |
 LL |     let v = *addr_of!(data).cast::<UninhDiscriminant>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/detect-extra-ub.rs:82:16
+  --> $DIR/detect-extra-ub.rs:84:16
    |
 LL |     let _val = *(&mem as *const Align as *const [*const u8; 2]);
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered a partial pointer or a mix of pointers
@@ -53,7 +53,7 @@ LL |     let _val = *(&mem as *const Align as *const [*const u8; 2]);
    = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/detect-extra-ub.rs:97:16
+  --> $DIR/detect-extra-ub.rs:99:16
    |
 LL |     let _val = &*slice;
    |                ^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
diff --git a/tests/ui/consts/issue-21721.rs b/tests/ui/consts/issue-21721.rs
index 1300c4a78840c..582576fad82d0 100644
--- a/tests/ui/consts/issue-21721.rs
+++ b/tests/ui/consts/issue-21721.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 fn main() {
     static NONE: Option<((), &'static u8)> = None;
     let ptr = unsafe {
diff --git a/tests/ui/consts/load-preserves-partial-init.rs b/tests/ui/consts/load-preserves-partial-init.rs
index 2a8adbd5e1665..d07698fe548d9 100644
--- a/tests/ui/consts/load-preserves-partial-init.rs
+++ b/tests/ui/consts/load-preserves-partial-init.rs
@@ -4,6 +4,8 @@
 // Loads of partially-initialized data could produce completely-uninitialized results.
 // Test to make sure that we no longer do such a "deinitializing" load.
 
+#![allow(unnecessary_refs)]
+
 // Or, equivalently: `MaybeUninit`.
 pub union BagOfBits<T: Copy> {
     uninit: (),
diff --git a/tests/ui/consts/miri_unleashed/slice_eq.rs b/tests/ui/consts/miri_unleashed/slice_eq.rs
index 7f07823bdc640..9662be0f4c084 100644
--- a/tests/ui/consts/miri_unleashed/slice_eq.rs
+++ b/tests/ui/consts/miri_unleashed/slice_eq.rs
@@ -1,6 +1,7 @@
 //@ compile-flags: -Zunleash-the-miri-inside-of-you
 //@ run-pass
 
+#![allow(unnecessary_refs)]
 #![feature(const_raw_ptr_comparison)]
 
 const EMPTY_SLICE: &[i32] = &[];
diff --git a/tests/ui/consts/offset.rs b/tests/ui/consts/offset.rs
index 2b1db34928590..ea85f53d1f023 100644
--- a/tests/ui/consts/offset.rs
+++ b/tests/ui/consts/offset.rs
@@ -1,4 +1,7 @@
 //@ run-pass
+
+#![allow(unnecessary_refs)]
+
 use std::ptr;
 
 #[repr(C)]
diff --git a/tests/ui/consts/offset_from.rs b/tests/ui/consts/offset_from.rs
index 02e8d145f65a9..4ed1faa8baa89 100644
--- a/tests/ui/consts/offset_from.rs
+++ b/tests/ui/consts/offset_from.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 struct Struct {
     field: (),
 }
diff --git a/tests/ui/consts/raw-ptr-const.rs b/tests/ui/consts/raw-ptr-const.rs
index 2946c9b4a8e9c..661d2bf29f430 100644
--- a/tests/ui/consts/raw-ptr-const.rs
+++ b/tests/ui/consts/raw-ptr-const.rs
@@ -3,6 +3,8 @@
 // This is a regression test for a `span_delayed_bug` during interning when a constant
 // evaluates to a (non-dangling) raw pointer.
 
+#![allow(unnecessary_refs)]
+
 const CONST_RAW: *const Vec<i32> = &Vec::new() as *const _;
 
 fn main() {}
diff --git a/tests/ui/consts/static-mut-refs.rs b/tests/ui/consts/static-mut-refs.rs
index c0d0bb613325c..b0f30b21ae4c9 100644
--- a/tests/ui/consts/static-mut-refs.rs
+++ b/tests/ui/consts/static-mut-refs.rs
@@ -1,5 +1,6 @@
 //@ run-pass
 #![allow(dead_code)]
+#![allow(unnecessary_refs)]
 
 // FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
 #![allow(static_mut_refs)]
diff --git a/tests/ui/consts/static-raw-pointer-interning.rs b/tests/ui/consts/static-raw-pointer-interning.rs
index 0e915760675b5..f5d24a77e9df7 100644
--- a/tests/ui/consts/static-raw-pointer-interning.rs
+++ b/tests/ui/consts/static-raw-pointer-interning.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 static FOO: Foo = Foo {
     field: &42 as *const i32,
 };
diff --git a/tests/ui/consts/static-raw-pointer-interning2.rs b/tests/ui/consts/static-raw-pointer-interning2.rs
index b279bb2261a8e..be6eec99f1c41 100644
--- a/tests/ui/consts/static-raw-pointer-interning2.rs
+++ b/tests/ui/consts/static-raw-pointer-interning2.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 static mut FOO: Foo = Foo {
     field: &mut [42] as *mut [i32] as *mut i32,
 };
diff --git a/tests/ui/consts/zst_no_llvm_alloc.rs b/tests/ui/consts/zst_no_llvm_alloc.rs
index 1e92e3bbd4c1b..2c1437710c09c 100644
--- a/tests/ui/consts/zst_no_llvm_alloc.rs
+++ b/tests/ui/consts/zst_no_llvm_alloc.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 #[repr(align(4))]
 struct Foo;
 
diff --git a/tests/ui/coroutine/static-coroutine.rs b/tests/ui/coroutine/static-coroutine.rs
index eba6336d342fe..d91990ec67b75 100644
--- a/tests/ui/coroutine/static-coroutine.rs
+++ b/tests/ui/coroutine/static-coroutine.rs
@@ -1,6 +1,7 @@
 //@ run-pass
 
 #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
+#![allow(unnecessary_refs)]
 
 use std::ops::{Coroutine, CoroutineState};
 use std::pin::Pin;
diff --git a/tests/ui/dynamically-sized-types/dst-field-align.rs b/tests/ui/dynamically-sized-types/dst-field-align.rs
index 09c818da63ff1..f66f1ae878de7 100644
--- a/tests/ui/dynamically-sized-types/dst-field-align.rs
+++ b/tests/ui/dynamically-sized-types/dst-field-align.rs
@@ -1,5 +1,8 @@
 //@ run-pass
+
 #![allow(dead_code)]
+#![allow(unnecessary_refs)]
+
 struct Foo<T: ?Sized> {
     a: u16,
     b: T
diff --git a/tests/ui/dynamically-sized-types/dst-raw.rs b/tests/ui/dynamically-sized-types/dst-raw.rs
index 111848c5a7f05..1ca90f55b9b91 100644
--- a/tests/ui/dynamically-sized-types/dst-raw.rs
+++ b/tests/ui/dynamically-sized-types/dst-raw.rs
@@ -1,6 +1,8 @@
 //@ run-pass
 // Test DST raw pointers
 
+#![allow(unnecessary_refs)]
+
 trait Trait {
     fn foo(&self) -> isize;
 }
diff --git a/tests/ui/editions/edition-raw-pointer-method-2015.rs b/tests/ui/editions/edition-raw-pointer-method-2015.rs
index b85e70465aba6..7d9823aaa11a4 100644
--- a/tests/ui/editions/edition-raw-pointer-method-2015.rs
+++ b/tests/ui/editions/edition-raw-pointer-method-2015.rs
@@ -2,7 +2,9 @@
 
 // tests that editions work with the tyvar warning-turned-error
 
+#![allow(unnecessary_refs)]
 #[deny(warnings)]
+
 fn main() {
     let x = 0;
     let y = &x as *const _;
diff --git a/tests/ui/editions/edition-raw-pointer-method-2015.stderr b/tests/ui/editions/edition-raw-pointer-method-2015.stderr
index 3d8b3f633ce8c..9b2f33b910f1b 100644
--- a/tests/ui/editions/edition-raw-pointer-method-2015.stderr
+++ b/tests/ui/editions/edition-raw-pointer-method-2015.stderr
@@ -1,5 +1,5 @@
 error: type annotations needed
-  --> $DIR/edition-raw-pointer-method-2015.rs:9:15
+  --> $DIR/edition-raw-pointer-method-2015.rs:11:15
    |
 LL |     let _ = y.is_null();
    |               ^^^^^^^
@@ -7,7 +7,7 @@ LL |     let _ = y.is_null();
    = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
    = note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>
 note: the lint level is defined here
-  --> $DIR/edition-raw-pointer-method-2015.rs:5:8
+  --> $DIR/edition-raw-pointer-method-2015.rs:6:8
    |
 LL | #[deny(warnings)]
    |        ^^^^^^^^
diff --git a/tests/ui/extern/extern-types-field-offset.rs b/tests/ui/extern/extern-types-field-offset.rs
index 75f3eab3e275f..4760cfc88e066 100644
--- a/tests/ui/extern/extern-types-field-offset.rs
+++ b/tests/ui/extern/extern-types-field-offset.rs
@@ -2,6 +2,8 @@
 //@ check-run-results
 //@ exec-env:RUST_BACKTRACE=0
 //@ normalize-stderr: "(core/src/panicking\.rs):[0-9]+:[0-9]+" -> "$1:$$LINE:$$COL"
+
+#![allow(unnecessary_refs)]
 #![feature(extern_types)]
 
 extern "C" {
diff --git a/tests/ui/feature-gates/feature-gate-strict_provenance_lints.rs b/tests/ui/feature-gates/feature-gate-strict_provenance_lints.rs
index 738c8daa1687f..d78e80f07988a 100644
--- a/tests/ui/feature-gates/feature-gate-strict_provenance_lints.rs
+++ b/tests/ui/feature-gates/feature-gate-strict_provenance_lints.rs
@@ -1,5 +1,7 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
+
 #![deny(fuzzy_provenance_casts)]
 //~^ WARNING unknown lint: `fuzzy_provenance_casts`
 #![deny(lossy_provenance_casts)]
diff --git a/tests/ui/feature-gates/feature-gate-strict_provenance_lints.stderr b/tests/ui/feature-gates/feature-gate-strict_provenance_lints.stderr
index 3f3b49bc60671..16675aae5d7ad 100644
--- a/tests/ui/feature-gates/feature-gate-strict_provenance_lints.stderr
+++ b/tests/ui/feature-gates/feature-gate-strict_provenance_lints.stderr
@@ -1,5 +1,5 @@
 warning: unknown lint: `fuzzy_provenance_casts`
-  --> $DIR/feature-gate-strict_provenance_lints.rs:3:9
+  --> $DIR/feature-gate-strict_provenance_lints.rs:5:9
    |
 LL | #![deny(fuzzy_provenance_casts)]
    |         ^^^^^^^^^^^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | #![deny(fuzzy_provenance_casts)]
    = note: `#[warn(unknown_lints)]` on by default
 
 warning: unknown lint: `lossy_provenance_casts`
-  --> $DIR/feature-gate-strict_provenance_lints.rs:5:9
+  --> $DIR/feature-gate-strict_provenance_lints.rs:7:9
    |
 LL | #![deny(lossy_provenance_casts)]
    |         ^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/inference/inference-variable-behind-raw-pointer.rs b/tests/ui/inference/inference-variable-behind-raw-pointer.rs
index 6a67cf593a567..a401a3735679b 100644
--- a/tests/ui/inference/inference-variable-behind-raw-pointer.rs
+++ b/tests/ui/inference/inference-variable-behind-raw-pointer.rs
@@ -2,6 +2,8 @@
 
 // tests that the following code compiles, but produces a future-compatibility warning
 
+#![allow(unnecessary_refs)]
+
 fn main() {
     let data = std::ptr::null();
     let _ = &data as *const *const ();
diff --git a/tests/ui/inference/inference-variable-behind-raw-pointer.stderr b/tests/ui/inference/inference-variable-behind-raw-pointer.stderr
index 3dea09e7f5282..430996e601178 100644
--- a/tests/ui/inference/inference-variable-behind-raw-pointer.stderr
+++ b/tests/ui/inference/inference-variable-behind-raw-pointer.stderr
@@ -1,5 +1,5 @@
 warning: type annotations needed
-  --> $DIR/inference-variable-behind-raw-pointer.rs:8:13
+  --> $DIR/inference-variable-behind-raw-pointer.rs:10:13
    |
 LL |     if data.is_null() {}
    |             ^^^^^^^
diff --git a/tests/ui/inference/inference_unstable.rs b/tests/ui/inference/inference_unstable.rs
index 5a5ac66310d60..0e869f7203bfe 100644
--- a/tests/ui/inference/inference_unstable.rs
+++ b/tests/ui/inference/inference_unstable.rs
@@ -5,6 +5,8 @@
 //@ aux-build:inference_unstable_itertools.rs
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 extern crate inference_unstable_iterator;
 extern crate inference_unstable_itertools;
 
diff --git a/tests/ui/inference/inference_unstable.stderr b/tests/ui/inference/inference_unstable.stderr
index 395dcb2661f11..420971514b084 100644
--- a/tests/ui/inference/inference_unstable.stderr
+++ b/tests/ui/inference/inference_unstable.stderr
@@ -1,5 +1,5 @@
 warning: a method with this name may be added to the standard library in the future
-  --> $DIR/inference_unstable.rs:16:20
+  --> $DIR/inference_unstable.rs:18:20
    |
 LL |     assert_eq!('x'.ipu_flatten(), 1);
    |                    ^^^^^^^^^^^
@@ -14,7 +14,7 @@ LL + #![feature(ipu_flatten)]
    |
 
 warning: a method with this name may be added to the standard library in the future
-  --> $DIR/inference_unstable.rs:19:20
+  --> $DIR/inference_unstable.rs:21:20
    |
 LL |     assert_eq!('x'.ipu_by_value_vs_by_ref(), 1);
    |                    ^^^^^^^^^^^^^^^^^^^^^^
@@ -28,7 +28,7 @@ LL + #![feature(ipu_flatten)]
    |
 
 warning: a method with this name may be added to the standard library in the future
-  --> $DIR/inference_unstable.rs:22:20
+  --> $DIR/inference_unstable.rs:24:20
    |
 LL |     assert_eq!('x'.ipu_by_ref_vs_by_ref_mut(), 1);
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -42,7 +42,7 @@ LL + #![feature(ipu_flatten)]
    |
 
 warning: a method with this name may be added to the standard library in the future
-  --> $DIR/inference_unstable.rs:25:40
+  --> $DIR/inference_unstable.rs:27:40
    |
 LL |     assert_eq!((&mut 'x' as *mut char).ipu_by_mut_ptr_vs_by_const_ptr(), 1);
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -56,7 +56,7 @@ LL + #![feature(ipu_flatten)]
    |
 
 warning: an associated constant with this name may be added to the standard library in the future
-  --> $DIR/inference_unstable.rs:28:16
+  --> $DIR/inference_unstable.rs:30:16
    |
 LL |     assert_eq!(char::C, 1);
    |                ^^^^^^^
diff --git a/tests/ui/intrinsics/const-eval-select-x86_64.rs b/tests/ui/intrinsics/const-eval-select-x86_64.rs
index c17be2ddaca39..c289f0ded2203 100644
--- a/tests/ui/intrinsics/const-eval-select-x86_64.rs
+++ b/tests/ui/intrinsics/const-eval-select-x86_64.rs
@@ -1,6 +1,7 @@
 //@ run-pass
 //@ only-x86_64
 
+#![allow(unnecessary_refs)]
 #![feature(const_eval_select)]
 #![feature(core_intrinsics)]
 use std::intrinsics::const_eval_select;
diff --git a/tests/ui/issues/issue-23699.rs b/tests/ui/issues/issue-23699.rs
index 6dde2dfd93001..331f0a0694b53 100644
--- a/tests/ui/issues/issue-23699.rs
+++ b/tests/ui/issues/issue-23699.rs
@@ -1,5 +1,6 @@
 //@ run-pass
 #![allow(unused_variables)]
+#![allow(unnecessary_refs)]
 fn gimme_a_raw_pointer<T>(_: *const T) { }
 
 fn test<T>(t: T) { }
diff --git a/tests/ui/issues/issue-30615.rs b/tests/ui/issues/issue-30615.rs
index 6157e593ea327..a8dc38ac70df7 100644
--- a/tests/ui/issues/issue-30615.rs
+++ b/tests/ui/issues/issue-30615.rs
@@ -1,4 +1,7 @@
 //@ run-pass
+
+#![allow(unnecessary_refs)]
+
 fn main() {
     &0u8 as *const u8 as *const dyn PartialEq<u8>;
     &[0u8] as *const [u8; 1] as *const [u8];
diff --git a/tests/ui/issues/issue-36936.rs b/tests/ui/issues/issue-36936.rs
index 4fbac00212672..4424281a8d0e0 100644
--- a/tests/ui/issues/issue-36936.rs
+++ b/tests/ui/issues/issue-36936.rs
@@ -1,6 +1,8 @@
 //@ run-pass
 // check that casts are not being treated as lexprs.
 
+#![allow(unnecessary_refs)]
+
 fn main() {
     let mut a = 0i32;
     let b = &(a as i32);
diff --git a/tests/ui/issues/issue-58212.rs b/tests/ui/issues/issue-58212.rs
index f266db603bf1c..a18cf04db11ac 100644
--- a/tests/ui/issues/issue-58212.rs
+++ b/tests/ui/issues/issue-58212.rs
@@ -1,5 +1,7 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
+
 trait FromUnchecked {
     fn from_unchecked();
 }
diff --git a/tests/ui/lint/function-item-references.rs b/tests/ui/lint/function-item-references.rs
index 4f2fc4de8632e..9054b537eb1d6 100644
--- a/tests/ui/lint/function-item-references.rs
+++ b/tests/ui/lint/function-item-references.rs
@@ -1,6 +1,7 @@
 //@ check-pass
 #![feature(c_variadic)]
 #![warn(function_item_references)]
+#![allow(unnecessary_refs)]
 use std::fmt::Pointer;
 use std::fmt::Formatter;
 
diff --git a/tests/ui/lint/function-item-references.stderr b/tests/ui/lint/function-item-references.stderr
index a9d18bb6a4743..b00f99f95b186 100644
--- a/tests/ui/lint/function-item-references.stderr
+++ b/tests/ui/lint/function-item-references.stderr
@@ -1,5 +1,5 @@
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:44:18
+  --> $DIR/function-item-references.rs:45:18
    |
 LL |     Pointer::fmt(&zst_ref, f)
    |                  ^^^^^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
@@ -11,193 +11,193 @@ LL | #![warn(function_item_references)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:81:22
+  --> $DIR/function-item-references.rs:82:22
    |
 LL |     println!("{:p}", &foo);
    |                      ^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:83:20
+  --> $DIR/function-item-references.rs:84:20
    |
 LL |     print!("{:p}", &foo);
    |                    ^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:85:21
+  --> $DIR/function-item-references.rs:86:21
    |
 LL |     format!("{:p}", &foo);
    |                     ^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:88:22
+  --> $DIR/function-item-references.rs:89:22
    |
 LL |     println!("{:p}", &foo as *const _);
    |                      ^^^^^^^^^^^^^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:90:22
+  --> $DIR/function-item-references.rs:91:22
    |
 LL |     println!("{:p}", zst_ref);
    |                      ^^^^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:92:22
+  --> $DIR/function-item-references.rs:93:22
    |
 LL |     println!("{:p}", cast_zst_ptr);
    |                      ^^^^^^^^^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:94:22
+  --> $DIR/function-item-references.rs:95:22
    |
 LL |     println!("{:p}", coerced_zst_ptr);
    |                      ^^^^^^^^^^^^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:97:22
+  --> $DIR/function-item-references.rs:98:22
    |
 LL |     println!("{:p}", &fn_item);
    |                      ^^^^^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:99:22
+  --> $DIR/function-item-references.rs:100:22
    |
 LL |     println!("{:p}", indirect_ref);
    |                      ^^^^^^^^^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:102:22
+  --> $DIR/function-item-references.rs:103:22
    |
 LL |     println!("{:p}", &nop);
    |                      ^^^^ help: cast `nop` to obtain a function pointer: `nop as fn()`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:104:22
+  --> $DIR/function-item-references.rs:105:22
    |
 LL |     println!("{:p}", &bar);
    |                      ^^^^ help: cast `bar` to obtain a function pointer: `bar as fn(_) -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:106:22
+  --> $DIR/function-item-references.rs:107:22
    |
 LL |     println!("{:p}", &baz);
    |                      ^^^^ help: cast `baz` to obtain a function pointer: `baz as fn(_, _) -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:108:22
+  --> $DIR/function-item-references.rs:109:22
    |
 LL |     println!("{:p}", &unsafe_fn);
    |                      ^^^^^^^^^^ help: cast `unsafe_fn` to obtain a function pointer: `unsafe_fn as unsafe fn()`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:110:22
+  --> $DIR/function-item-references.rs:111:22
    |
 LL |     println!("{:p}", &c_fn);
    |                      ^^^^^ help: cast `c_fn` to obtain a function pointer: `c_fn as extern "C" fn()`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:112:22
+  --> $DIR/function-item-references.rs:113:22
    |
 LL |     println!("{:p}", &unsafe_c_fn);
    |                      ^^^^^^^^^^^^ help: cast `unsafe_c_fn` to obtain a function pointer: `unsafe_c_fn as unsafe extern "C" fn()`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:114:22
+  --> $DIR/function-item-references.rs:115:22
    |
 LL |     println!("{:p}", &variadic);
    |                      ^^^^^^^^^ help: cast `variadic` to obtain a function pointer: `variadic as unsafe extern "C" fn(_, ...)`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:116:22
+  --> $DIR/function-item-references.rs:117:22
    |
 LL |     println!("{:p}", &take_generic_ref::<u32>);
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^ help: cast `take_generic_ref` to obtain a function pointer: `take_generic_ref::<u32> as fn(_)`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:118:22
+  --> $DIR/function-item-references.rs:119:22
    |
 LL |     println!("{:p}", &take_generic_array::<u32, 4>);
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: cast `take_generic_array` to obtain a function pointer: `take_generic_array::<u32, 4> as fn(_)`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:120:22
+  --> $DIR/function-item-references.rs:121:22
    |
 LL |     println!("{:p}", &multiple_generic::<u32, f32>);
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: cast `multiple_generic` to obtain a function pointer: `multiple_generic::<u32, f32> as fn(_, _)`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:122:22
+  --> $DIR/function-item-references.rs:123:22
    |
 LL |     println!("{:p}", &multiple_generic_arrays::<u32, f32, 4, 8>);
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: cast `multiple_generic_arrays` to obtain a function pointer: `multiple_generic_arrays::<u32, f32, 4, 8> as fn(_, _)`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:124:22
+  --> $DIR/function-item-references.rs:125:22
    |
 LL |     println!("{:p}", &std::env::var::<String>);
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^ help: cast `var` to obtain a function pointer: `var::<String> as fn(_) -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:127:32
+  --> $DIR/function-item-references.rs:128:32
    |
 LL |     println!("{:p} {:p} {:p}", &nop, &foo, &bar);
    |                                ^^^^ help: cast `nop` to obtain a function pointer: `nop as fn()`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:127:38
+  --> $DIR/function-item-references.rs:128:38
    |
 LL |     println!("{:p} {:p} {:p}", &nop, &foo, &bar);
    |                                      ^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:127:44
+  --> $DIR/function-item-references.rs:128:44
    |
 LL |     println!("{:p} {:p} {:p}", &nop, &foo, &bar);
    |                                            ^^^^ help: cast `bar` to obtain a function pointer: `bar as fn(_) -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:142:41
+  --> $DIR/function-item-references.rs:143:41
    |
 LL |         std::mem::transmute::<_, usize>(&foo);
    |                                         ^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:144:50
+  --> $DIR/function-item-references.rs:145:50
    |
 LL |         std::mem::transmute::<_, (usize, usize)>((&foo, &bar));
    |                                                  ^^^^^^^^^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:144:50
+  --> $DIR/function-item-references.rs:145:50
    |
 LL |         std::mem::transmute::<_, (usize, usize)>((&foo, &bar));
    |                                                  ^^^^^^^^^^^^ help: cast `bar` to obtain a function pointer: `bar as fn(_) -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:147:41
+  --> $DIR/function-item-references.rs:148:41
    |
 LL |         std::mem::transmute::<_, usize>(&take_generic_ref::<u32>);
    |                                         ^^^^^^^^^^^^^^^^^^^^^^^^ help: cast `take_generic_ref` to obtain a function pointer: `take_generic_ref::<u32> as fn(_)`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:156:15
+  --> $DIR/function-item-references.rs:157:15
    |
 LL |     print_ptr(&bar);
    |               ^^^^ help: cast `bar` to obtain a function pointer: `bar as fn(_) -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:158:24
+  --> $DIR/function-item-references.rs:159:24
    |
 LL |     bound_by_ptr_trait(&bar);
    |                        ^^^^ help: cast `bar` to obtain a function pointer: `bar as fn(_) -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:160:30
+  --> $DIR/function-item-references.rs:161:30
    |
 LL |     bound_by_ptr_trait_tuple((&foo, &bar));
    |                              ^^^^^^^^^^^^ help: cast `bar` to obtain a function pointer: `bar as fn(_) -> _`
 
 warning: taking a reference to a function item does not give a function pointer
-  --> $DIR/function-item-references.rs:160:30
+  --> $DIR/function-item-references.rs:161:30
    |
 LL |     bound_by_ptr_trait_tuple((&foo, &bar));
    |                              ^^^^^^^^^^^^ help: cast `foo` to obtain a function pointer: `foo as fn() -> _`
diff --git a/tests/ui/lint/lint-strict-provenance-lossy-casts.rs b/tests/ui/lint/lint-strict-provenance-lossy-casts.rs
index 395dc75f82555..08b0a45a05d06 100644
--- a/tests/ui/lint/lint-strict-provenance-lossy-casts.rs
+++ b/tests/ui/lint/lint-strict-provenance-lossy-casts.rs
@@ -1,5 +1,6 @@
 #![feature(strict_provenance_lints)]
 #![deny(lossy_provenance_casts)]
+#![allow(unnecessary_refs)]
 
 fn main() {
     let x: u8 = 37;
diff --git a/tests/ui/lint/lint-strict-provenance-lossy-casts.stderr b/tests/ui/lint/lint-strict-provenance-lossy-casts.stderr
index bcef0ae424e68..89989f6fa0422 100644
--- a/tests/ui/lint/lint-strict-provenance-lossy-casts.stderr
+++ b/tests/ui/lint/lint-strict-provenance-lossy-casts.stderr
@@ -1,5 +1,5 @@
 error: under strict provenance it is considered bad style to cast pointer `*const u8` to integer `usize`
-  --> $DIR/lint-strict-provenance-lossy-casts.rs:6:23
+  --> $DIR/lint-strict-provenance-lossy-casts.rs:7:23
    |
 LL |     let addr: usize = &x as *const u8 as usize;
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -17,7 +17,7 @@ LL +     let addr: usize = (&x as *const u8).addr();
    |
 
 error: under strict provenance it is considered bad style to cast pointer `*const u8` to integer `u32`
-  --> $DIR/lint-strict-provenance-lossy-casts.rs:9:22
+  --> $DIR/lint-strict-provenance-lossy-casts.rs:10:22
    |
 LL |     let addr_32bit = &x as *const u8 as u32;
    |                      ^^^^^^^^^^^^^^^^^^^^^^
@@ -29,7 +29,7 @@ LL |     let addr_32bit = (&x as *const u8).addr() as u32;
    |                      +               ++++++++
 
 error: under strict provenance it is considered bad style to cast pointer `*const u8` to integer `usize`
-  --> $DIR/lint-strict-provenance-lossy-casts.rs:14:20
+  --> $DIR/lint-strict-provenance-lossy-casts.rs:15:20
    |
 LL |     let ptr_addr = ptr as usize;
    |                    ^^^---------
@@ -39,7 +39,7 @@ LL |     let ptr_addr = ptr as usize;
    = help: if you can't comply with strict provenance and need to expose the pointer provenance you can use `.expose_provenance()` instead
 
 error: under strict provenance it is considered bad style to cast pointer `*const u8` to integer `u32`
-  --> $DIR/lint-strict-provenance-lossy-casts.rs:16:26
+  --> $DIR/lint-strict-provenance-lossy-casts.rs:17:26
    |
 LL |     let ptr_addr_32bit = ptr as u32;
    |                          ^^^-------
diff --git a/tests/ui/lint/lint-unnecessary-refs.fixed b/tests/ui/lint/lint-unnecessary-refs.fixed
new file mode 100644
index 0000000000000..ff25f8a27de5f
--- /dev/null
+++ b/tests/ui/lint/lint-unnecessary-refs.fixed
@@ -0,0 +1,39 @@
+//@ check-pass
+//@ run-rustfix
+
+#![allow(dead_code, unused_variables)]
+
+struct A {
+    a: i32,
+    b: u8,
+}
+
+fn via_ref(x: *const (i32, i32)) -> *const i32 {
+    unsafe { &raw const (*x).0 }
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
+
+fn via_ref_struct(x: *const A) -> *const u8 {
+    unsafe { &raw const (*x).b }
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
+
+fn via_ref_mut(x: *mut (i32, i32)) -> *mut i32 {
+    unsafe { &raw mut (*x).0 }
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
+
+fn via_ref_struct_mut(x: *mut A) -> *mut i32 {
+    unsafe { &raw mut (*x).a }
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
+
+fn main() {
+    let a = 0;
+    let a = &raw const a;
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+
+    let mut b = 0;
+    let b = &raw mut b;
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
diff --git a/tests/ui/lint/lint-unnecessary-refs.rs b/tests/ui/lint/lint-unnecessary-refs.rs
new file mode 100644
index 0000000000000..a130d316f8ec9
--- /dev/null
+++ b/tests/ui/lint/lint-unnecessary-refs.rs
@@ -0,0 +1,39 @@
+//@ check-pass
+//@ run-rustfix
+
+#![allow(dead_code, unused_variables)]
+
+struct A {
+    a: i32,
+    b: u8,
+}
+
+fn via_ref(x: *const (i32, i32)) -> *const i32 {
+    unsafe { &(*x).0 as *const i32 }
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
+
+fn via_ref_struct(x: *const A) -> *const u8 {
+    unsafe { &(*x).b as *const u8 }
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
+
+fn via_ref_mut(x: *mut (i32, i32)) -> *mut i32 {
+    unsafe { &mut (*x).0 as *mut i32 }
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
+
+fn via_ref_struct_mut(x: *mut A) -> *mut i32 {
+    unsafe { &mut (*x).a as *mut i32 }
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
+
+fn main() {
+    let a = 0;
+    let a = &a as *const i32;
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+
+    let mut b = 0;
+    let b = &mut b as *mut i32;
+    //~^ WARN creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers [unnecessary_refs]
+}
diff --git a/tests/ui/lint/lint-unnecessary-refs.stderr b/tests/ui/lint/lint-unnecessary-refs.stderr
new file mode 100644
index 0000000000000..ad5bac1b55a04
--- /dev/null
+++ b/tests/ui/lint/lint-unnecessary-refs.stderr
@@ -0,0 +1,75 @@
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/lint-unnecessary-refs.rs:12:14
+   |
+LL |     unsafe { &(*x).0 as *const i32 }
+   |              ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(unnecessary_refs)]` on by default
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -     unsafe { &(*x).0 as *const i32 }
+LL +     unsafe { &raw const (*x).0 }
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/lint-unnecessary-refs.rs:17:14
+   |
+LL |     unsafe { &(*x).b as *const u8 }
+   |              ^^^^^^^^^^^^^^^^^^^^
+   |
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -     unsafe { &(*x).b as *const u8 }
+LL +     unsafe { &raw const (*x).b }
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/lint-unnecessary-refs.rs:22:14
+   |
+LL |     unsafe { &mut (*x).0 as *mut i32 }
+   |              ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: consider using `&raw mut` for a safer and more explicit raw pointer
+   |
+LL -     unsafe { &mut (*x).0 as *mut i32 }
+LL +     unsafe { &raw mut (*x).0 }
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/lint-unnecessary-refs.rs:27:14
+   |
+LL |     unsafe { &mut (*x).a as *mut i32 }
+   |              ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: consider using `&raw mut` for a safer and more explicit raw pointer
+   |
+LL -     unsafe { &mut (*x).a as *mut i32 }
+LL +     unsafe { &raw mut (*x).a }
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/lint-unnecessary-refs.rs:33:13
+   |
+LL |     let a = &a as *const i32;
+   |             ^^^^^^^^^^^^^^^^
+   |
+help: consider using `&raw const` for a safer and more explicit raw pointer
+   |
+LL -     let a = &a as *const i32;
+LL +     let a = &raw const a;
+   |
+
+warning: creating a intermediate reference implies aliasing requirements even when immediately casting to raw pointers
+  --> $DIR/lint-unnecessary-refs.rs:37:13
+   |
+LL |     let b = &mut b as *mut i32;
+   |             ^^^^^^^^^^^^^^^^^^
+   |
+help: consider using `&raw mut` for a safer and more explicit raw pointer
+   |
+LL -     let b = &mut b as *mut i32;
+LL +     let b = &raw mut b;
+   |
+
+warning: 6 warnings emitted
+
diff --git a/tests/ui/lint/ptr_null_checks.rs b/tests/ui/lint/ptr_null_checks.rs
index 19d328856fd16..8a3c625a44b0b 100644
--- a/tests/ui/lint/ptr_null_checks.rs
+++ b/tests/ui/lint/ptr_null_checks.rs
@@ -1,5 +1,7 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
+
 use std::ptr;
 
 extern "C" fn c_fn() {}
diff --git a/tests/ui/lint/ptr_null_checks.stderr b/tests/ui/lint/ptr_null_checks.stderr
index 70a27790c5b3e..0edc1b865361e 100644
--- a/tests/ui/lint/ptr_null_checks.stderr
+++ b/tests/ui/lint/ptr_null_checks.stderr
@@ -1,5 +1,5 @@
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:12:8
+  --> $DIR/ptr_null_checks.rs:14:8
    |
 LL |     if (fn_ptr as *mut ()).is_null() {}
    |        ^------^^^^^^^^^^^^^^^^^^^^^^
@@ -10,7 +10,7 @@ LL |     if (fn_ptr as *mut ()).is_null() {}
    = note: `#[warn(useless_ptr_null_checks)]` on by default
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:14:8
+  --> $DIR/ptr_null_checks.rs:16:8
    |
 LL |     if (fn_ptr as *const u8).is_null() {}
    |        ^------^^^^^^^^^^^^^^^^^^^^^^^^
@@ -20,7 +20,7 @@ LL |     if (fn_ptr as *const u8).is_null() {}
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:16:8
+  --> $DIR/ptr_null_checks.rs:18:8
    |
 LL |     if (fn_ptr as *const ()) == std::ptr::null() {}
    |        ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -30,7 +30,7 @@ LL |     if (fn_ptr as *const ()) == std::ptr::null() {}
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:18:8
+  --> $DIR/ptr_null_checks.rs:20:8
    |
 LL |     if (fn_ptr as *mut ()) == std::ptr::null_mut() {}
    |        ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +40,7 @@ LL |     if (fn_ptr as *mut ()) == std::ptr::null_mut() {}
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:20:8
+  --> $DIR/ptr_null_checks.rs:22:8
    |
 LL |     if (fn_ptr as *const ()) == (0 as *const ()) {}
    |        ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -50,7 +50,7 @@ LL |     if (fn_ptr as *const ()) == (0 as *const ()) {}
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:22:8
+  --> $DIR/ptr_null_checks.rs:24:8
    |
 LL |     if <*const _>::is_null(fn_ptr as *const ()) {}
    |        ^^^^^^^^^^^^^^^^^^^^------^^^^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL |     if <*const _>::is_null(fn_ptr as *const ()) {}
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:24:8
+  --> $DIR/ptr_null_checks.rs:26:8
    |
 LL |     if (fn_ptr as *mut fn() as *const fn() as *const ()).is_null() {}
    |        ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -70,7 +70,7 @@ LL |     if (fn_ptr as *mut fn() as *const fn() as *const ()).is_null() {}
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:26:8
+  --> $DIR/ptr_null_checks.rs:28:8
    |
 LL |     if (fn_ptr as *mut fn() as *const fn()).cast_mut().is_null() {}
    |        ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -80,7 +80,7 @@ LL |     if (fn_ptr as *mut fn() as *const fn()).cast_mut().is_null() {}
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:28:8
+  --> $DIR/ptr_null_checks.rs:30:8
    |
 LL |     if ((fn_ptr as *mut fn()).cast() as *const fn()).cast_mut().is_null() {}
    |        ^^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -90,7 +90,7 @@ LL |     if ((fn_ptr as *mut fn()).cast() as *const fn()).cast_mut().is_null() {
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:30:8
+  --> $DIR/ptr_null_checks.rs:32:8
    |
 LL |     if (fn_ptr as fn() as *const ()).is_null() {}
    |        ^--------------^^^^^^^^^^^^^^^^^^^^^^^^
@@ -100,7 +100,7 @@ LL |     if (fn_ptr as fn() as *const ()).is_null() {}
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: function pointers are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:32:8
+  --> $DIR/ptr_null_checks.rs:34:8
    |
 LL |     if (c_fn as *const fn()).is_null() {}
    |        ^----^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -110,7 +110,7 @@ LL |     if (c_fn as *const fn()).is_null() {}
    = help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:36:8
+  --> $DIR/ptr_null_checks.rs:38:8
    |
 LL |     if (&mut 8 as *mut i32).is_null() {}
    |        ^------^^^^^^^^^^^^^^^^^^^^^^^
@@ -118,13 +118,13 @@ LL |     if (&mut 8 as *mut i32).is_null() {}
    |         expression has type `&mut i32`
 
 warning: returned pointer of `from_mut` call is never null, so checking it for null will always return false
-  --> $DIR/ptr_null_checks.rs:38:8
+  --> $DIR/ptr_null_checks.rs:40:8
    |
 LL |     if ptr::from_mut(&mut 8).is_null() {}
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:40:8
+  --> $DIR/ptr_null_checks.rs:42:8
    |
 LL |     if (&8 as *const i32).is_null() {}
    |        ^--^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -132,25 +132,25 @@ LL |     if (&8 as *const i32).is_null() {}
    |         expression has type `&i32`
 
 warning: returned pointer of `from_ref` call is never null, so checking it for null will always return false
-  --> $DIR/ptr_null_checks.rs:42:8
+  --> $DIR/ptr_null_checks.rs:44:8
    |
 LL |     if ptr::from_ref(&8).is_null() {}
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: returned pointer of `from_ref` call is never null, so checking it for null will always return false
-  --> $DIR/ptr_null_checks.rs:44:8
+  --> $DIR/ptr_null_checks.rs:46:8
    |
 LL |     if ptr::from_ref(&8).cast_mut().is_null() {}
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: returned pointer of `from_ref` call is never null, so checking it for null will always return false
-  --> $DIR/ptr_null_checks.rs:46:8
+  --> $DIR/ptr_null_checks.rs:48:8
    |
 LL |     if (ptr::from_ref(&8).cast_mut() as *mut i32).is_null() {}
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:48:8
+  --> $DIR/ptr_null_checks.rs:50:8
    |
 LL |     if (&8 as *const i32) == std::ptr::null() {}
    |        ^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -158,7 +158,7 @@ LL |     if (&8 as *const i32) == std::ptr::null() {}
    |         expression has type `&i32`
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:51:8
+  --> $DIR/ptr_null_checks.rs:53:8
    |
 LL |     if (ref_num as *const i32) == std::ptr::null() {}
    |        ^-------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -166,7 +166,7 @@ LL |     if (ref_num as *const i32) == std::ptr::null() {}
    |         expression has type `&i32`
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:53:8
+  --> $DIR/ptr_null_checks.rs:55:8
    |
 LL |     if (b"\0" as *const u8).is_null() {}
    |        ^-----^^^^^^^^^^^^^^^^^^^^^^^^
@@ -174,7 +174,7 @@ LL |     if (b"\0" as *const u8).is_null() {}
    |         expression has type `&[u8; 1]`
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:55:8
+  --> $DIR/ptr_null_checks.rs:57:8
    |
 LL |     if ("aa" as *const str).is_null() {}
    |        ^----^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -182,7 +182,7 @@ LL |     if ("aa" as *const str).is_null() {}
    |         expression has type `&str`
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:57:8
+  --> $DIR/ptr_null_checks.rs:59:8
    |
 LL |     if (&[1, 2] as *const i32).is_null() {}
    |        ^-------^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -190,7 +190,7 @@ LL |     if (&[1, 2] as *const i32).is_null() {}
    |         expression has type `&[i32; 2]`
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:59:8
+  --> $DIR/ptr_null_checks.rs:61:8
    |
 LL |     if (&mut [1, 2] as *mut i32) == std::ptr::null_mut() {}
    |        ^-----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -198,7 +198,7 @@ LL |     if (&mut [1, 2] as *mut i32) == std::ptr::null_mut() {}
    |         expression has type `&mut [i32; 2]`
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:61:8
+  --> $DIR/ptr_null_checks.rs:63:8
    |
 LL |     if (static_i32() as *const i32).is_null() {}
    |        ^------------^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -206,7 +206,7 @@ LL |     if (static_i32() as *const i32).is_null() {}
    |         expression has type `&i32`
 
 warning: references are not nullable, so checking them for null will always return false
-  --> $DIR/ptr_null_checks.rs:63:8
+  --> $DIR/ptr_null_checks.rs:65:8
    |
 LL |     if (&*{ static_i32() } as *const i32).is_null() {}
    |        ^------------------^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -214,13 +214,13 @@ LL |     if (&*{ static_i32() } as *const i32).is_null() {}
    |         expression has type `&i32`
 
 warning: returned pointer of `as_ptr` call is never null, so checking it for null will always return false
-  --> $DIR/ptr_null_checks.rs:67:8
+  --> $DIR/ptr_null_checks.rs:69:8
    |
 LL |     if ptr::NonNull::new(&mut 8).unwrap().as_ptr().is_null() {}
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: returned pointer of `as_ptr` call is never null, so checking it for null will always return false
-  --> $DIR/ptr_null_checks.rs:69:8
+  --> $DIR/ptr_null_checks.rs:71:8
    |
 LL |     if ptr::NonNull::<u8>::dangling().as_ptr().is_null() {}
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/lint/reference_casting.rs b/tests/ui/lint/reference_casting.rs
index 87fa42f94775e..c617cee08c3ec 100644
--- a/tests/ui/lint/reference_casting.rs
+++ b/tests/ui/lint/reference_casting.rs
@@ -1,5 +1,7 @@
 //@ check-fail
 
+#![allow(unnecessary_refs)]
+
 extern "C" {
     // N.B., mutability can be easily incorrect in FFI calls -- as
     // in C, the default is mutable pointers.
diff --git a/tests/ui/lint/reference_casting.stderr b/tests/ui/lint/reference_casting.stderr
index 4205d406b5158..27ae6ca6d317b 100644
--- a/tests/ui/lint/reference_casting.stderr
+++ b/tests/ui/lint/reference_casting.stderr
@@ -1,5 +1,5 @@
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:17:16
+  --> $DIR/reference_casting.rs:19:16
    |
 LL |     let _num = &mut *(num as *const i32 as *mut i32);
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL |     let _num = &mut *(num as *const i32 as *mut i32);
    = note: `#[deny(invalid_reference_casting)]` on by default
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:19:16
+  --> $DIR/reference_casting.rs:21:16
    |
 LL |     let _num = &mut *(num as *const i32).cast_mut();
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL |     let _num = &mut *(num as *const i32).cast_mut();
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:21:16
+  --> $DIR/reference_casting.rs:23:16
    |
 LL |     let _num = &mut *std::ptr::from_ref(num).cast_mut();
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL |     let _num = &mut *std::ptr::from_ref(num).cast_mut();
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:23:16
+  --> $DIR/reference_casting.rs:25:16
    |
 LL |     let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -32,7 +32,7 @@ LL |     let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:25:16
+  --> $DIR/reference_casting.rs:27:16
    |
 LL |     let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +40,7 @@ LL |     let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:27:16
+  --> $DIR/reference_casting.rs:29:16
    |
 LL |     let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -48,7 +48,7 @@ LL |     let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:29:16
+  --> $DIR/reference_casting.rs:31:16
    |
 LL |     let _num = &mut *(num as *const i32).cast::<i32>().cast_mut();
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -56,7 +56,7 @@ LL |     let _num = &mut *(num as *const i32).cast::<i32>().cast_mut();
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:31:16
+  --> $DIR/reference_casting.rs:33:16
    |
 LL |     let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_const().cast_mut();
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -64,7 +64,7 @@ LL |     let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_cons
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:33:16
+  --> $DIR/reference_casting.rs:35:16
    |
 LL |     let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i8);
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +72,7 @@ LL |     let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i8);
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:35:16
+  --> $DIR/reference_casting.rs:37:16
    |
 LL |     let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -80,7 +80,7 @@ LL |     let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:37:16
+  --> $DIR/reference_casting.rs:39:16
    |
 LL |     let _num = &mut *(std::mem::transmute::<_, *mut i32>(num) as *mut i32);
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -88,7 +88,7 @@ LL |     let _num = &mut *(std::mem::transmute::<_, *mut i32>(num) as *mut i32);
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:39:16
+  --> $DIR/reference_casting.rs:41:16
    |
 LL |       let _num = &mut *std::cell::UnsafeCell::raw_get(
    |  ________________^
@@ -100,7 +100,7 @@ LL | |     );
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:45:16
+  --> $DIR/reference_casting.rs:47:16
    |
 LL |     let deferred = num as *const i32 as *mut i32;
    |                    ----------------------------- casting happened here
@@ -110,7 +110,7 @@ LL |     let _num = &mut *deferred;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:48:16
+  --> $DIR/reference_casting.rs:50:16
    |
 LL |     let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
    |                    ---------------------------------------------------------------------------- casting happened here
@@ -120,7 +120,7 @@ LL |     let _num = &mut *deferred;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:51:16
+  --> $DIR/reference_casting.rs:53:16
    |
 LL |     let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
    |                    ---------------------------------------------------------------------------- casting happened here
@@ -131,7 +131,7 @@ LL |     let _num = &mut *deferred_rebind;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:53:16
+  --> $DIR/reference_casting.rs:55:16
    |
 LL |     let _num = &mut *(num as *const _ as usize as *mut i32);
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -139,7 +139,7 @@ LL |     let _num = &mut *(num as *const _ as usize as *mut i32);
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:55:16
+  --> $DIR/reference_casting.rs:57:16
    |
 LL |     let _num = &mut *(std::mem::transmute::<_, *mut _>(num as *const i32) as *mut i32);
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -147,7 +147,7 @@ LL |     let _num = &mut *(std::mem::transmute::<_, *mut _>(num as *const i32) a
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:62:16
+  --> $DIR/reference_casting.rs:64:16
    |
 LL |     let num = NUM as *const i32 as *mut i32;
    |               ----------------------------- casting happened here
@@ -158,7 +158,7 @@ LL |     let _num = &mut *num;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:66:16
+  --> $DIR/reference_casting.rs:68:16
    |
 LL |     let _num = &mut *(cell as *const _ as *mut i32);
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -167,7 +167,7 @@ LL |     let _num = &mut *(cell as *const _ as *mut i32);
    = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:70:9
+  --> $DIR/reference_casting.rs:72:9
    |
 LL |         &mut *((this as *const _) as *mut _)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -175,7 +175,7 @@ LL |         &mut *((this as *const _) as *mut _)
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:75:18
+  --> $DIR/reference_casting.rs:77:18
    |
 LL |         unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -183,7 +183,7 @@ LL |         unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *con
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:80:18
+  --> $DIR/reference_casting.rs:82:18
    |
 LL |         unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -191,7 +191,7 @@ LL |         unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *con
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:90:5
+  --> $DIR/reference_casting.rs:92:5
    |
 LL |     *(a as *const _ as *mut _) = String::from("Replaced");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -199,7 +199,7 @@ LL |     *(a as *const _ as *mut _) = String::from("Replaced");
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:92:5
+  --> $DIR/reference_casting.rs:94:5
    |
 LL |     *(a as *const _ as *mut String) += " world";
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -207,7 +207,7 @@ LL |     *(a as *const _ as *mut String) += " world";
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:94:5
+  --> $DIR/reference_casting.rs:96:5
    |
 LL |     *std::ptr::from_ref(num).cast_mut() += 1;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -215,7 +215,7 @@ LL |     *std::ptr::from_ref(num).cast_mut() += 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:96:5
+  --> $DIR/reference_casting.rs:98:5
    |
 LL |     *std::ptr::from_ref({ num }).cast_mut() += 1;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -223,7 +223,7 @@ LL |     *std::ptr::from_ref({ num }).cast_mut() += 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:98:5
+  --> $DIR/reference_casting.rs:100:5
    |
 LL |     *{ std::ptr::from_ref(num) }.cast_mut() += 1;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -231,7 +231,7 @@ LL |     *{ std::ptr::from_ref(num) }.cast_mut() += 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:100:5
+  --> $DIR/reference_casting.rs:102:5
    |
 LL |     *(std::ptr::from_ref({ num }) as *mut i32) += 1;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -239,7 +239,7 @@ LL |     *(std::ptr::from_ref({ num }) as *mut i32) += 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:102:5
+  --> $DIR/reference_casting.rs:104:5
    |
 LL |     *std::mem::transmute::<_, *mut i32>(num) += 1;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -247,7 +247,7 @@ LL |     *std::mem::transmute::<_, *mut i32>(num) += 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:104:5
+  --> $DIR/reference_casting.rs:106:5
    |
 LL |     *(std::mem::transmute::<_, *mut i32>(num) as *mut i32) += 1;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -255,7 +255,7 @@ LL |     *(std::mem::transmute::<_, *mut i32>(num) as *mut i32) += 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:106:5
+  --> $DIR/reference_casting.rs:108:5
    |
 LL | /     std::ptr::write(
 LL | |
@@ -267,7 +267,7 @@ LL | |     );
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:111:5
+  --> $DIR/reference_casting.rs:113:5
    |
 LL |     *((&std::cell::UnsafeCell::new(0)) as *const _ as *mut i32) = 5;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -276,7 +276,7 @@ LL |     *((&std::cell::UnsafeCell::new(0)) as *const _ as *mut i32) = 5;
    = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:115:5
+  --> $DIR/reference_casting.rs:117:5
    |
 LL |     let value = num as *const i32 as *mut i32;
    |                 ----------------------------- casting happened here
@@ -286,7 +286,7 @@ LL |     *value = 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:119:5
+  --> $DIR/reference_casting.rs:121:5
    |
 LL |     let value = value as *mut i32;
    |                 ----------------- casting happened here
@@ -296,7 +296,7 @@ LL |     *value = 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:122:5
+  --> $DIR/reference_casting.rs:124:5
    |
 LL |     let value = num as *const i32 as *mut i32;
    |                 ----------------------------- casting happened here
@@ -306,7 +306,7 @@ LL |     *value = 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:125:5
+  --> $DIR/reference_casting.rs:127:5
    |
 LL |     let value = num as *const i32 as *mut i32;
    |                 ----------------------------- casting happened here
@@ -317,7 +317,7 @@ LL |     *value_rebind = 1;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:127:5
+  --> $DIR/reference_casting.rs:129:5
    |
 LL |     *(num as *const i32).cast::<i32>().cast_mut() = 2;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -325,7 +325,7 @@ LL |     *(num as *const i32).cast::<i32>().cast_mut() = 2;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:129:5
+  --> $DIR/reference_casting.rs:131:5
    |
 LL |     *(num as *const _ as usize as *mut i32) = 2;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -333,7 +333,7 @@ LL |     *(num as *const _ as usize as *mut i32) = 2;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:131:5
+  --> $DIR/reference_casting.rs:133:5
    |
 LL |     let value = num as *const i32 as *mut i32;
    |                 ----------------------------- casting happened here
@@ -344,7 +344,7 @@ LL |     std::ptr::write(value, 2);
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:133:5
+  --> $DIR/reference_casting.rs:135:5
    |
 LL |     let value = num as *const i32 as *mut i32;
    |                 ----------------------------- casting happened here
@@ -355,7 +355,7 @@ LL |     std::ptr::write_unaligned(value, 2);
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:135:5
+  --> $DIR/reference_casting.rs:137:5
    |
 LL |     let value = num as *const i32 as *mut i32;
    |                 ----------------------------- casting happened here
@@ -366,7 +366,7 @@ LL |     std::ptr::write_volatile(value, 2);
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:139:9
+  --> $DIR/reference_casting.rs:141:9
    |
 LL |         *(this as *const _ as *mut _) = a;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -374,7 +374,7 @@ LL |         *(this as *const _ as *mut _) = a;
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:161:20
+  --> $DIR/reference_casting.rs:163:20
    |
 LL |         let num = &mut 3i32;
    |                        ---- backing allocation comes from here
@@ -385,7 +385,7 @@ LL |         let _num = &*(num as *const i32 as *const i64);
    = note: casting from `i32` (4 bytes) to `i64` (8 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:163:20
+  --> $DIR/reference_casting.rs:165:20
    |
 LL |         let num = &mut 3i32;
    |                        ---- backing allocation comes from here
@@ -396,7 +396,7 @@ LL |         let _num = &mut *(num as *mut i32 as *mut i64);
    = note: casting from `i32` (4 bytes) to `i64` (8 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:165:20
+  --> $DIR/reference_casting.rs:167:20
    |
 LL |         let num = &mut 3i32;
    |                        ---- backing allocation comes from here
@@ -407,7 +407,7 @@ LL |         let _num = &mut *(num as *mut i32 as *mut I64);
    = note: casting from `i32` (4 bytes) to `I64` (16 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:167:9
+  --> $DIR/reference_casting.rs:169:9
    |
 LL |         let num = &mut 3i32;
    |                        ---- backing allocation comes from here
@@ -418,7 +418,7 @@ LL |         std::ptr::write(num as *mut i32 as *mut i64, 2);
    = note: casting from `i32` (4 bytes) to `i64` (8 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:176:20
+  --> $DIR/reference_casting.rs:178:20
    |
 LL |         let num = &mut [0i32; 3];
    |                        --------- backing allocation comes from here
@@ -429,7 +429,7 @@ LL |         let _num = &mut *(num as *mut _ as *mut [i64; 2]);
    = note: casting from `[i32; 3]` (12 bytes) to `[i64; 2]` (16 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:178:9
+  --> $DIR/reference_casting.rs:180:9
    |
 LL |         let num = &mut [0i32; 3];
    |                        --------- backing allocation comes from here
@@ -440,7 +440,7 @@ LL |         std::ptr::write_unaligned(num as *mut _ as *mut [i32; 4], [0, 0, 1,
    = note: casting from `[i32; 3]` (12 bytes) to `[i32; 4]` (16 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:188:20
+  --> $DIR/reference_casting.rs:190:20
    |
 LL |         let num = &mut [0i32; 3] as &mut [i32];
    |                        --------- backing allocation comes from here
@@ -451,7 +451,7 @@ LL |         let _num = &mut *(num as *mut _ as *mut i128);
    = note: casting from `[i32; 3]` (12 bytes) to `i128` (16 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:190:20
+  --> $DIR/reference_casting.rs:192:20
    |
 LL |         let num = &mut [0i32; 3] as &mut [i32];
    |                        --------- backing allocation comes from here
@@ -462,7 +462,7 @@ LL |         let _num = &mut *(num as *mut _ as *mut [i64; 4]);
    = note: casting from `[i32; 3]` (12 bytes) to `[i64; 4]` (32 bytes)
 
 error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
-  --> $DIR/reference_casting.rs:200:20
+  --> $DIR/reference_casting.rs:202:20
    |
 LL |         let _num = &mut *(&mat3 as *const _ as *mut [[i64; 3]; 3]);
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -470,7 +470,7 @@ LL |         let _num = &mut *(&mat3 as *const _ as *mut [[i64; 3]; 3]);
    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:200:20
+  --> $DIR/reference_casting.rs:202:20
    |
 LL |         let _num = &mut *(&mat3 as *const _ as *mut [[i64; 3]; 3]);
    |                    ^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -480,7 +480,7 @@ LL |         let _num = &mut *(&mat3 as *const _ as *mut [[i64; 3]; 3]);
    = note: casting from `Mat3<i32>` (36 bytes) to `[[i64; 3]; 3]` (72 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:203:20
+  --> $DIR/reference_casting.rs:205:20
    |
 LL |         let _num = &*(&mat3 as *const _ as *mut [[i64; 3]; 3]);
    |                    ^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -490,7 +490,7 @@ LL |         let _num = &*(&mat3 as *const _ as *mut [[i64; 3]; 3]);
    = note: casting from `Mat3<i32>` (36 bytes) to `[[i64; 3]; 3]` (72 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:212:37
+  --> $DIR/reference_casting.rs:214:37
    |
 LL |         let w: *mut [u16; 2] = &mut l as *mut [u8; 2] as *mut _;
    |                                --------------------------------
@@ -503,7 +503,7 @@ LL |         let w: *mut [u16] = unsafe {&mut *w};
    = note: casting from `[u8; 2]` (2 bytes) to `[u16; 2]` (4 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:220:20
+  --> $DIR/reference_casting.rs:222:20
    |
 LL |         let _num = &*(&num as *const i32 as *const i64);
    |                    ^^^^---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -513,7 +513,7 @@ LL |         let _num = &*(&num as *const i32 as *const i64);
    = note: casting from `[i32; 1]` (4 bytes) to `i64` (8 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:222:20
+  --> $DIR/reference_casting.rs:224:20
    |
 LL |         let _num = &*(&foo() as *const i32 as *const i64);
    |                    ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -523,7 +523,7 @@ LL |         let _num = &*(&foo() as *const i32 as *const i64);
    = note: casting from `[i32; 1]` (4 bytes) to `i64` (8 bytes)
 
 error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
-  --> $DIR/reference_casting.rs:238:20
+  --> $DIR/reference_casting.rs:240:20
    |
 LL |         let _num = &*(&num as *const i32 as *const i64);
    |                    ^^^^---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/lint/wide_pointer_comparisons.rs b/tests/ui/lint/wide_pointer_comparisons.rs
index 05097cbf1e3de..4754cc14f9e04 100644
--- a/tests/ui/lint/wide_pointer_comparisons.rs
+++ b/tests/ui/lint/wide_pointer_comparisons.rs
@@ -1,5 +1,7 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
+
 use std::rc::Rc;
 use std::sync::Arc;
 use std::cmp::PartialEq;
diff --git a/tests/ui/lint/wide_pointer_comparisons.stderr b/tests/ui/lint/wide_pointer_comparisons.stderr
index 5a0b914d8320e..25481faca4951 100644
--- a/tests/ui/lint/wide_pointer_comparisons.stderr
+++ b/tests/ui/lint/wide_pointer_comparisons.stderr
@@ -1,5 +1,5 @@
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:20:13
+  --> $DIR/wide_pointer_comparisons.rs:22:13
    |
 LL |     let _ = a == b;
    |             ^^^^^^
@@ -12,7 +12,7 @@ LL +     let _ = std::ptr::addr_eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:22:13
+  --> $DIR/wide_pointer_comparisons.rs:24:13
    |
 LL |     let _ = a != b;
    |             ^^^^^^
@@ -24,7 +24,7 @@ LL +     let _ = !std::ptr::addr_eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:24:13
+  --> $DIR/wide_pointer_comparisons.rs:26:13
    |
 LL |     let _ = a < b;
    |             ^^^^^
@@ -35,7 +35,7 @@ LL |     let _ = a.cast::<()>() < b.cast::<()>();
    |              +++++++++++++    +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:26:13
+  --> $DIR/wide_pointer_comparisons.rs:28:13
    |
 LL |     let _ = a <= b;
    |             ^^^^^^
@@ -46,7 +46,7 @@ LL |     let _ = a.cast::<()>() <= b.cast::<()>();
    |              +++++++++++++     +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:28:13
+  --> $DIR/wide_pointer_comparisons.rs:30:13
    |
 LL |     let _ = a > b;
    |             ^^^^^
@@ -57,7 +57,7 @@ LL |     let _ = a.cast::<()>() > b.cast::<()>();
    |              +++++++++++++    +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:30:13
+  --> $DIR/wide_pointer_comparisons.rs:32:13
    |
 LL |     let _ = a >= b;
    |             ^^^^^^
@@ -68,7 +68,7 @@ LL |     let _ = a.cast::<()>() >= b.cast::<()>();
    |              +++++++++++++     +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:33:13
+  --> $DIR/wide_pointer_comparisons.rs:35:13
    |
 LL |     let _ = PartialEq::eq(&a, &b);
    |             ^^^^^^^^^^^^^^^^^^^^^
@@ -80,7 +80,7 @@ LL +     let _ = std::ptr::addr_eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:35:13
+  --> $DIR/wide_pointer_comparisons.rs:37:13
    |
 LL |     let _ = PartialEq::ne(&a, &b);
    |             ^^^^^^^^^^^^^^^^^^^^^
@@ -92,7 +92,7 @@ LL +     let _ = !std::ptr::addr_eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:37:13
+  --> $DIR/wide_pointer_comparisons.rs:39:13
    |
 LL |     let _ = a.eq(&b);
    |             ^^^^^^^^
@@ -104,7 +104,7 @@ LL +     let _ = std::ptr::addr_eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:39:13
+  --> $DIR/wide_pointer_comparisons.rs:41:13
    |
 LL |     let _ = a.ne(&b);
    |             ^^^^^^^^
@@ -116,7 +116,7 @@ LL +     let _ = !std::ptr::addr_eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:41:13
+  --> $DIR/wide_pointer_comparisons.rs:43:13
    |
 LL |     let _ = a.cmp(&b);
    |             ^^^^^^^^^
@@ -127,7 +127,7 @@ LL |     let _ = a.cast::<()>().cmp(&b.cast::<()>());
    |              +++++++++++++       +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:43:13
+  --> $DIR/wide_pointer_comparisons.rs:45:13
    |
 LL |     let _ = a.partial_cmp(&b);
    |             ^^^^^^^^^^^^^^^^^
@@ -138,7 +138,7 @@ LL |     let _ = a.cast::<()>().partial_cmp(&b.cast::<()>());
    |              +++++++++++++               +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:45:13
+  --> $DIR/wide_pointer_comparisons.rs:47:13
    |
 LL |     let _ = a.le(&b);
    |             ^^^^^^^^
@@ -149,7 +149,7 @@ LL |     let _ = a.cast::<()>().le(&b.cast::<()>());
    |              +++++++++++++      +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:47:13
+  --> $DIR/wide_pointer_comparisons.rs:49:13
    |
 LL |     let _ = a.lt(&b);
    |             ^^^^^^^^
@@ -160,7 +160,7 @@ LL |     let _ = a.cast::<()>().lt(&b.cast::<()>());
    |              +++++++++++++      +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:49:13
+  --> $DIR/wide_pointer_comparisons.rs:51:13
    |
 LL |     let _ = a.ge(&b);
    |             ^^^^^^^^
@@ -171,7 +171,7 @@ LL |     let _ = a.cast::<()>().ge(&b.cast::<()>());
    |              +++++++++++++      +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:51:13
+  --> $DIR/wide_pointer_comparisons.rs:53:13
    |
 LL |     let _ = a.gt(&b);
    |             ^^^^^^^^
@@ -182,7 +182,7 @@ LL |     let _ = a.cast::<()>().gt(&b.cast::<()>());
    |              +++++++++++++      +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:57:17
+  --> $DIR/wide_pointer_comparisons.rs:59:17
    |
 LL |         let _ = a == b;
    |                 ^^^^^^
@@ -194,7 +194,7 @@ LL +         let _ = std::ptr::addr_eq(a.as_ptr(), b.as_ptr());
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:59:17
+  --> $DIR/wide_pointer_comparisons.rs:61:17
    |
 LL |         let _ = a >= b;
    |                 ^^^^^^
@@ -205,7 +205,7 @@ LL |         let _ = a.as_ptr().cast::<()>() >= b.as_ptr().cast::<()>();
    |                  ++++++++++++++++++++++     ++++++++++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:61:17
+  --> $DIR/wide_pointer_comparisons.rs:63:17
    |
 LL |         let _ = &a == &b;
    |                 ^^^^^^^^
@@ -217,7 +217,7 @@ LL +         let _ = std::ptr::addr_eq(a.as_ptr(), b.as_ptr());
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:70:17
+  --> $DIR/wide_pointer_comparisons.rs:72:17
    |
 LL |         let _ = a == b;
    |                 ^^^^^^
@@ -229,7 +229,7 @@ LL +         let _ = std::ptr::addr_eq(*a, *b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:72:17
+  --> $DIR/wide_pointer_comparisons.rs:74:17
    |
 LL |         let _ = a != b;
    |                 ^^^^^^
@@ -241,7 +241,7 @@ LL +         let _ = !std::ptr::addr_eq(*a, *b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:74:17
+  --> $DIR/wide_pointer_comparisons.rs:76:17
    |
 LL |         let _ = a < b;
    |                 ^^^^^
@@ -252,7 +252,7 @@ LL |         let _ = (*a).cast::<()>() < (*b).cast::<()>();
    |                 ++ ++++++++++++++   ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:76:17
+  --> $DIR/wide_pointer_comparisons.rs:78:17
    |
 LL |         let _ = a <= b;
    |                 ^^^^^^
@@ -263,7 +263,7 @@ LL |         let _ = (*a).cast::<()>() <= (*b).cast::<()>();
    |                 ++ ++++++++++++++    ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:78:17
+  --> $DIR/wide_pointer_comparisons.rs:80:17
    |
 LL |         let _ = a > b;
    |                 ^^^^^
@@ -274,7 +274,7 @@ LL |         let _ = (*a).cast::<()>() > (*b).cast::<()>();
    |                 ++ ++++++++++++++   ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:80:17
+  --> $DIR/wide_pointer_comparisons.rs:82:17
    |
 LL |         let _ = a >= b;
    |                 ^^^^^^
@@ -285,7 +285,7 @@ LL |         let _ = (*a).cast::<()>() >= (*b).cast::<()>();
    |                 ++ ++++++++++++++    ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:83:17
+  --> $DIR/wide_pointer_comparisons.rs:85:17
    |
 LL |         let _ = PartialEq::eq(a, b);
    |                 ^^^^^^^^^^^^^^^^^^^
@@ -297,7 +297,7 @@ LL +         let _ = std::ptr::addr_eq(*a, *b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:85:17
+  --> $DIR/wide_pointer_comparisons.rs:87:17
    |
 LL |         let _ = PartialEq::ne(a, b);
    |                 ^^^^^^^^^^^^^^^^^^^
@@ -309,7 +309,7 @@ LL +         let _ = !std::ptr::addr_eq(*a, *b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:87:17
+  --> $DIR/wide_pointer_comparisons.rs:89:17
    |
 LL |         let _ = PartialEq::eq(&a, &b);
    |                 ^^^^^^^^^^^^^^^^^^^^^
@@ -321,7 +321,7 @@ LL +         let _ = std::ptr::addr_eq(*a, *b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:89:17
+  --> $DIR/wide_pointer_comparisons.rs:91:17
    |
 LL |         let _ = PartialEq::ne(&a, &b);
    |                 ^^^^^^^^^^^^^^^^^^^^^
@@ -333,7 +333,7 @@ LL +         let _ = !std::ptr::addr_eq(*a, *b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:91:17
+  --> $DIR/wide_pointer_comparisons.rs:93:17
    |
 LL |         let _ = a.eq(b);
    |                 ^^^^^^^
@@ -345,7 +345,7 @@ LL +         let _ = std::ptr::addr_eq(*a, *b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:93:17
+  --> $DIR/wide_pointer_comparisons.rs:95:17
    |
 LL |         let _ = a.ne(b);
    |                 ^^^^^^^
@@ -357,7 +357,7 @@ LL +         let _ = !std::ptr::addr_eq(*a, *b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:95:17
+  --> $DIR/wide_pointer_comparisons.rs:97:17
    |
 LL |         let _ = a.cmp(&b);
    |                 ^^^^^^^^^
@@ -368,7 +368,7 @@ LL |         let _ = (*a).cast::<()>().cmp(&(*b).cast::<()>());
    |                 ++ ++++++++++++++      ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:97:17
+  --> $DIR/wide_pointer_comparisons.rs:99:17
    |
 LL |         let _ = a.partial_cmp(&b);
    |                 ^^^^^^^^^^^^^^^^^
@@ -379,7 +379,7 @@ LL |         let _ = (*a).cast::<()>().partial_cmp(&(*b).cast::<()>());
    |                 ++ ++++++++++++++              ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:99:17
+  --> $DIR/wide_pointer_comparisons.rs:101:17
    |
 LL |         let _ = a.le(&b);
    |                 ^^^^^^^^
@@ -390,7 +390,7 @@ LL |         let _ = (*a).cast::<()>().le(&(*b).cast::<()>());
    |                 ++ ++++++++++++++     ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:101:17
+  --> $DIR/wide_pointer_comparisons.rs:103:17
    |
 LL |         let _ = a.lt(&b);
    |                 ^^^^^^^^
@@ -401,7 +401,7 @@ LL |         let _ = (*a).cast::<()>().lt(&(*b).cast::<()>());
    |                 ++ ++++++++++++++     ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:103:17
+  --> $DIR/wide_pointer_comparisons.rs:105:17
    |
 LL |         let _ = a.ge(&b);
    |                 ^^^^^^^^
@@ -412,7 +412,7 @@ LL |         let _ = (*a).cast::<()>().ge(&(*b).cast::<()>());
    |                 ++ ++++++++++++++     ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:105:17
+  --> $DIR/wide_pointer_comparisons.rs:107:17
    |
 LL |         let _ = a.gt(&b);
    |                 ^^^^^^^^
@@ -423,7 +423,7 @@ LL |         let _ = (*a).cast::<()>().gt(&(*b).cast::<()>());
    |                 ++ ++++++++++++++     ++ ++++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:110:13
+  --> $DIR/wide_pointer_comparisons.rs:112:13
    |
 LL |     let _ = s == s;
    |             ^^^^^^
@@ -440,7 +440,7 @@ LL +     let _ = std::ptr::eq(s, s);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:114:13
+  --> $DIR/wide_pointer_comparisons.rs:116:13
    |
 LL |     let _ = s == s;
    |             ^^^^^^
@@ -457,7 +457,7 @@ LL +     let _ = std::ptr::eq(s, s);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:118:17
+  --> $DIR/wide_pointer_comparisons.rs:120:17
    |
 LL |         let _ = a == b;
    |                 ^^^^^^
@@ -474,7 +474,7 @@ LL +         let _ = std::ptr::eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:120:17
+  --> $DIR/wide_pointer_comparisons.rs:122:17
    |
 LL |         let _ = a != b;
    |                 ^^^^^^
@@ -491,7 +491,7 @@ LL +         let _ = !std::ptr::eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:122:17
+  --> $DIR/wide_pointer_comparisons.rs:124:17
    |
 LL |         let _ = a < b;
    |                 ^^^^^
@@ -502,7 +502,7 @@ LL |         let _ = a.cast::<()>() < b.cast::<()>();
    |                  +++++++++++++    +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:124:17
+  --> $DIR/wide_pointer_comparisons.rs:126:17
    |
 LL |         let _ = a <= b;
    |                 ^^^^^^
@@ -513,7 +513,7 @@ LL |         let _ = a.cast::<()>() <= b.cast::<()>();
    |                  +++++++++++++     +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:126:17
+  --> $DIR/wide_pointer_comparisons.rs:128:17
    |
 LL |         let _ = a > b;
    |                 ^^^^^
@@ -524,7 +524,7 @@ LL |         let _ = a.cast::<()>() > b.cast::<()>();
    |                  +++++++++++++    +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:128:17
+  --> $DIR/wide_pointer_comparisons.rs:130:17
    |
 LL |         let _ = a >= b;
    |                 ^^^^^^
@@ -535,7 +535,7 @@ LL |         let _ = a.cast::<()>() >= b.cast::<()>();
    |                  +++++++++++++     +++++++++++++
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:131:17
+  --> $DIR/wide_pointer_comparisons.rs:133:17
    |
 LL |         let _ = PartialEq::eq(&a, &b);
    |                 ^^^^^^^^^^^^^^^^^^^^^
@@ -552,7 +552,7 @@ LL +         let _ = std::ptr::eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:133:17
+  --> $DIR/wide_pointer_comparisons.rs:135:17
    |
 LL |         let _ = PartialEq::ne(&a, &b);
    |                 ^^^^^^^^^^^^^^^^^^^^^
@@ -569,7 +569,7 @@ LL +         let _ = !std::ptr::eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:135:17
+  --> $DIR/wide_pointer_comparisons.rs:137:17
    |
 LL |         let _ = a.eq(&b);
    |                 ^^^^^^^^
@@ -586,7 +586,7 @@ LL +         let _ = std::ptr::eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:137:17
+  --> $DIR/wide_pointer_comparisons.rs:139:17
    |
 LL |         let _ = a.ne(&b);
    |                 ^^^^^^^^
@@ -603,7 +603,7 @@ LL +         let _ = !std::ptr::eq(a, b);
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:142:9
+  --> $DIR/wide_pointer_comparisons.rs:144:9
    |
 LL |         &*a == &*b
    |         ^^^^^^^^^^
@@ -620,7 +620,7 @@ LL +         std::ptr::eq(*a, *b)
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:153:14
+  --> $DIR/wide_pointer_comparisons.rs:155:14
    |
 LL |         cmp!(a, b);
    |              ^^^^
@@ -631,7 +631,7 @@ LL |         cmp!(std::ptr::addr_eq(a, b));
    |              ++++++++++++++++++    +
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:159:39
+  --> $DIR/wide_pointer_comparisons.rs:161:39
    |
 LL |             ($a:ident, $b:ident) => { $a == $b }
    |                                       ^^^^^^^^
@@ -647,7 +647,7 @@ LL +             ($a:ident, $b:ident) => { std::ptr::addr_eq($a, $b) }
    |
 
 warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
-  --> $DIR/wide_pointer_comparisons.rs:169:37
+  --> $DIR/wide_pointer_comparisons.rs:171:37
    |
 LL |             ($a:expr, $b:expr) => { $a == $b }
    |                                     ^^^^^^^^
diff --git a/tests/ui/match/match-ref-mut-stability.rs b/tests/ui/match/match-ref-mut-stability.rs
index 90784a4f4b652..4c68ef754bc6a 100644
--- a/tests/ui/match/match-ref-mut-stability.rs
+++ b/tests/ui/match/match-ref-mut-stability.rs
@@ -3,6 +3,8 @@
 
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 // Test that z always point to the same temporary.
 fn referent_stability() {
     let p;
diff --git a/tests/ui/methods/method-two-traits-distinguished-via-where-clause.rs b/tests/ui/methods/method-two-traits-distinguished-via-where-clause.rs
index 2ef2848c21641..e4cac56aa19b4 100644
--- a/tests/ui/methods/method-two-traits-distinguished-via-where-clause.rs
+++ b/tests/ui/methods/method-two-traits-distinguished-via-where-clause.rs
@@ -2,6 +2,7 @@
 // Test that we select between traits A and B. To do that, we must
 // consider the `Sized` bound.
 
+#![allow(unnecessary_refs)]
 
 trait A { //~ WARN trait `A` is never used
     fn foo(self);
diff --git a/tests/ui/methods/method-two-traits-distinguished-via-where-clause.stderr b/tests/ui/methods/method-two-traits-distinguished-via-where-clause.stderr
index fa87ce5cc49ff..0a60c6242bb2d 100644
--- a/tests/ui/methods/method-two-traits-distinguished-via-where-clause.stderr
+++ b/tests/ui/methods/method-two-traits-distinguished-via-where-clause.stderr
@@ -1,5 +1,5 @@
 warning: trait `A` is never used
-  --> $DIR/method-two-traits-distinguished-via-where-clause.rs:6:7
+  --> $DIR/method-two-traits-distinguished-via-where-clause.rs:7:7
    |
 LL | trait A {
    |       ^
diff --git a/tests/ui/mir/alignment/place_computation.rs b/tests/ui/mir/alignment/place_computation.rs
index d3717db77c78d..026c54179dfb8 100644
--- a/tests/ui/mir/alignment/place_computation.rs
+++ b/tests/ui/mir/alignment/place_computation.rs
@@ -1,6 +1,8 @@
 //@ run-pass
 //@ compile-flags: -C debug-assertions
 
+#![allow(unnecessary_refs)]
+
 #[repr(align(8))]
 struct Misalignment {
     a: u8,
diff --git a/tests/ui/mir/alignment/two_pointers.rs b/tests/ui/mir/alignment/two_pointers.rs
index 198a1c9853d97..c04e201f8a97f 100644
--- a/tests/ui/mir/alignment/two_pointers.rs
+++ b/tests/ui/mir/alignment/two_pointers.rs
@@ -3,6 +3,8 @@
 //@ compile-flags: -C debug-assertions
 //@ error-pattern: misaligned pointer dereference: address must be a multiple of 0x4 but is
 
+#![allow(unnecessary_refs)]
+
 fn main() {
     let x = [0u32; 2];
     let ptr = x.as_ptr();
diff --git a/tests/ui/mir/mir_autoderef.rs b/tests/ui/mir/mir_autoderef.rs
index 95800c68ec243..fede471e9872c 100644
--- a/tests/ui/mir/mir_autoderef.rs
+++ b/tests/ui/mir/mir_autoderef.rs
@@ -1,4 +1,7 @@
 //@ run-pass
+
+#![allow(unnecessary_refs)]
+
 use std::ops::{Deref, DerefMut};
 
 pub struct MyRef(u32);
diff --git a/tests/ui/mir/mir_raw_fat_ptr.rs b/tests/ui/mir/mir_raw_fat_ptr.rs
index 96c030b70e50f..492cf04e201e9 100644
--- a/tests/ui/mir/mir_raw_fat_ptr.rs
+++ b/tests/ui/mir/mir_raw_fat_ptr.rs
@@ -3,6 +3,7 @@
 // FIXME: please improve this when we get monomorphization support
 
 #![allow(ambiguous_wide_pointer_comparisons)]
+#![allow(unnecessary_refs)]
 
 use std::mem;
 
diff --git a/tests/ui/mir/mir_raw_fat_ptr.stderr b/tests/ui/mir/mir_raw_fat_ptr.stderr
index cd99d566654f9..a9e9dd66ebdfa 100644
--- a/tests/ui/mir/mir_raw_fat_ptr.stderr
+++ b/tests/ui/mir/mir_raw_fat_ptr.stderr
@@ -1,5 +1,5 @@
 warning: method `foo` is never used
-  --> $DIR/mir_raw_fat_ptr.rs:100:16
+  --> $DIR/mir_raw_fat_ptr.rs:101:16
    |
 LL | trait Foo { fn foo(&self) -> usize; }
    |       ---      ^^^
diff --git a/tests/ui/mir/null/two_pointers.rs b/tests/ui/mir/null/two_pointers.rs
index 52b9510be12eb..e2df5e30bb1a6 100644
--- a/tests/ui/mir/null/two_pointers.rs
+++ b/tests/ui/mir/null/two_pointers.rs
@@ -2,6 +2,8 @@
 //@ compile-flags: -C debug-assertions
 //@ error-pattern: null pointer dereference occurred
 
+#![allow(unnecessary_refs)]
+
 fn main() {
     let ptr = std::ptr::null();
     let mut dest = 0u32;
diff --git a/tests/ui/numbers-arithmetic/integer-literal-suffix-inference-2.rs b/tests/ui/numbers-arithmetic/integer-literal-suffix-inference-2.rs
index 2cbbdfc6479f1..eef47b1ce0d2f 100644
--- a/tests/ui/numbers-arithmetic/integer-literal-suffix-inference-2.rs
+++ b/tests/ui/numbers-arithmetic/integer-literal-suffix-inference-2.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 fn foo(_: *const ()) {}
 
 fn main() {
diff --git a/tests/ui/packed/packed-struct-optimized-enum.rs b/tests/ui/packed/packed-struct-optimized-enum.rs
index e76620c630d74..ed1ddc4281db4 100644
--- a/tests/ui/packed/packed-struct-optimized-enum.rs
+++ b/tests/ui/packed/packed-struct-optimized-enum.rs
@@ -1,4 +1,7 @@
 //@ run-pass
+
+#![allow(unnecessary_refs)]
+
 #[repr(packed)]
 struct Packed<T: Copy>(#[allow(dead_code)] T);
 
diff --git a/tests/ui/parallel-rustc/export-symbols-deadlock-issue-118205.rs b/tests/ui/parallel-rustc/export-symbols-deadlock-issue-118205.rs
index 3ccc1ea5f1063..c2f923cf1eb61 100644
--- a/tests/ui/parallel-rustc/export-symbols-deadlock-issue-118205.rs
+++ b/tests/ui/parallel-rustc/export-symbols-deadlock-issue-118205.rs
@@ -1,6 +1,8 @@
 //@ compile-flags: -Z threads=16
 //@ build-pass
 
+#![allow(unnecessary_refs)]
+
 pub static GLOBAL: isize = 3;
 
 static GLOBAL0: isize = 4;
diff --git a/tests/ui/self/arbitrary_self_types_niche_deshadowing.rs b/tests/ui/self/arbitrary_self_types_niche_deshadowing.rs
index 9326eca1f5353..324d8e00e0e64 100644
--- a/tests/ui/self/arbitrary_self_types_niche_deshadowing.rs
+++ b/tests/ui/self/arbitrary_self_types_niche_deshadowing.rs
@@ -2,6 +2,7 @@
 
 #![allow(dead_code)]
 #![allow(incomplete_features)]
+#![allow(unnecessary_refs)]
 
 #![feature(arbitrary_self_types)]
 #![feature(arbitrary_self_types_pointers)]
diff --git a/tests/ui/self/arbitrary_self_types_raw_pointer_struct.rs b/tests/ui/self/arbitrary_self_types_raw_pointer_struct.rs
index 7f76ed7fd2a59..bab4e8d13af4a 100644
--- a/tests/ui/self/arbitrary_self_types_raw_pointer_struct.rs
+++ b/tests/ui/self/arbitrary_self_types_raw_pointer_struct.rs
@@ -1,4 +1,6 @@
 //@ run-pass
+
+#![allow(unnecessary_refs)]
 #![feature(arbitrary_self_types_pointers)]
 
 use std::rc::Rc;
diff --git a/tests/ui/self/arbitrary_self_types_raw_pointer_trait.rs b/tests/ui/self/arbitrary_self_types_raw_pointer_trait.rs
index 6f34c9281b074..785b2fd9944cd 100644
--- a/tests/ui/self/arbitrary_self_types_raw_pointer_trait.rs
+++ b/tests/ui/self/arbitrary_self_types_raw_pointer_trait.rs
@@ -1,4 +1,6 @@
 //@ run-pass
+
+#![allow(unnecessary_refs)]
 #![feature(arbitrary_self_types_pointers)]
 
 use std::ptr;
diff --git a/tests/ui/simd/intrinsic/generic-gather-pass.rs b/tests/ui/simd/intrinsic/generic-gather-pass.rs
index b98d4d6575bb7..3f7d9a9581778 100644
--- a/tests/ui/simd/intrinsic/generic-gather-pass.rs
+++ b/tests/ui/simd/intrinsic/generic-gather-pass.rs
@@ -5,6 +5,7 @@
 
 #![feature(repr_simd, core_intrinsics)]
 #![allow(non_camel_case_types)]
+#![allow(unnecessary_refs)]
 
 use std::intrinsics::simd::{simd_gather, simd_scatter};
 
diff --git a/tests/ui/simd/intrinsic/ptr-cast.rs b/tests/ui/simd/intrinsic/ptr-cast.rs
index 3a73c0273e1a7..353bf47a85c6c 100644
--- a/tests/ui/simd/intrinsic/ptr-cast.rs
+++ b/tests/ui/simd/intrinsic/ptr-cast.rs
@@ -1,5 +1,6 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
 #![feature(repr_simd, core_intrinsics)]
 
 use std::intrinsics::simd::{simd_cast_ptr, simd_expose_provenance, simd_with_exposed_provenance};
diff --git a/tests/ui/simd/issue-32947.rs b/tests/ui/simd/issue-32947.rs
index b34484b2d3b54..55113e2322fd0 100644
--- a/tests/ui/simd/issue-32947.rs
+++ b/tests/ui/simd/issue-32947.rs
@@ -1,5 +1,6 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
 #![feature(repr_simd, test)]
 
 extern crate test;
diff --git a/tests/ui/simd/issue-85915-simd-ptrs.rs b/tests/ui/simd/issue-85915-simd-ptrs.rs
index 4e2379d052510..ac4d270865385 100644
--- a/tests/ui/simd/issue-85915-simd-ptrs.rs
+++ b/tests/ui/simd/issue-85915-simd-ptrs.rs
@@ -5,6 +5,7 @@
 // verifying simd([*const T; N]) and simd([*mut T; N]) pass typeck and work.
 #![feature(repr_simd, core_intrinsics)]
 #![allow(non_camel_case_types)]
+#![allow(unnecessary_refs)]
 
 use std::intrinsics::simd::{simd_gather, simd_scatter};
 
diff --git a/tests/ui/stable-addr-of.rs b/tests/ui/stable-addr-of.rs
index e330a4853ce03..34c74ca5a2f2c 100644
--- a/tests/ui/stable-addr-of.rs
+++ b/tests/ui/stable-addr-of.rs
@@ -1,6 +1,7 @@
 //@ run-pass
 // Issue #2040
 
+#![allow(unnecessary_refs)]
 
 pub fn main() {
     let foo: isize = 1;
diff --git a/tests/ui/statics/recursive_interior_mut.rs b/tests/ui/statics/recursive_interior_mut.rs
index 43e9d0c50913c..9c1e450f3e533 100644
--- a/tests/ui/statics/recursive_interior_mut.rs
+++ b/tests/ui/statics/recursive_interior_mut.rs
@@ -1,5 +1,7 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
+
 use std::cell::Cell;
 use std::ptr::NonNull;
 
diff --git a/tests/ui/statics/static-mut-shared-parens.rs b/tests/ui/statics/static-mut-shared-parens.rs
index 8e58152e27acd..67d72c1c0edf4 100644
--- a/tests/ui/statics/static-mut-shared-parens.rs
+++ b/tests/ui/statics/static-mut-shared-parens.rs
@@ -1,6 +1,7 @@
 //Missing paren in diagnostic msg: https://github.com/rust-lang/rust/issues/131977
 //@check-pass
 
+#![allow(unnecessary_refs)]
 
 static mut TEST: usize = 0;
 
diff --git a/tests/ui/statics/static-mut-shared-parens.stderr b/tests/ui/statics/static-mut-shared-parens.stderr
index 30a586c286ae7..b2710c2bce43e 100644
--- a/tests/ui/statics/static-mut-shared-parens.stderr
+++ b/tests/ui/statics/static-mut-shared-parens.stderr
@@ -1,5 +1,5 @@
 warning: creating a shared reference to mutable static is discouraged
-  --> $DIR/static-mut-shared-parens.rs:8:22
+  --> $DIR/static-mut-shared-parens.rs:9:22
    |
 LL |     let _ = unsafe { (&TEST) as *const usize };
    |                      ^^^^^^^ shared reference to mutable static
@@ -13,7 +13,7 @@ LL |     let _ = unsafe { (&raw const TEST) as *const usize };
    |                        +++++++++
 
 warning: creating a mutable reference to mutable static is discouraged
-  --> $DIR/static-mut-shared-parens.rs:11:22
+  --> $DIR/static-mut-shared-parens.rs:12:22
    |
 LL |     let _ = unsafe { ((&mut TEST)) as *const usize };
    |                      ^^^^^^^^^^^^^ mutable reference to mutable static
diff --git a/tests/ui/statics/static-recursive.rs b/tests/ui/statics/static-recursive.rs
index da23b54d1fca0..bb8151301343a 100644
--- a/tests/ui/statics/static-recursive.rs
+++ b/tests/ui/statics/static-recursive.rs
@@ -1,5 +1,7 @@
 //@ run-pass
 
+#![allow(unnecessary_refs)]
+
 static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
 //~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
 
diff --git a/tests/ui/statics/static-recursive.stderr b/tests/ui/statics/static-recursive.stderr
index 039934dfc692d..6c91d76086f2b 100644
--- a/tests/ui/statics/static-recursive.stderr
+++ b/tests/ui/statics/static-recursive.stderr
@@ -1,5 +1,5 @@
 warning: creating a shared reference to mutable static is discouraged
-  --> $DIR/static-recursive.rs:3:36
+  --> $DIR/static-recursive.rs:5:36
    |
 LL | static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
    |                                    ^^ shared reference to mutable static
@@ -13,7 +13,7 @@ LL | static mut S: *const u8 = unsafe { &raw const S as *const *const u8 as *con
    |                                     +++++++++
 
 warning: creating a shared reference to mutable static is discouraged
-  --> $DIR/static-recursive.rs:19:20
+  --> $DIR/static-recursive.rs:21:20
    |
 LL |         assert_eq!(S, *(S as *const *const u8));
    |                    ^ shared reference to mutable static
diff --git a/tests/ui/stdlib-unit-tests/raw-fat-ptr.rs b/tests/ui/stdlib-unit-tests/raw-fat-ptr.rs
index 51876d0bf1547..7b853ad77f850 100644
--- a/tests/ui/stdlib-unit-tests/raw-fat-ptr.rs
+++ b/tests/ui/stdlib-unit-tests/raw-fat-ptr.rs
@@ -1,6 +1,8 @@
 //@ run-pass
 // check raw fat pointer ops
 
+#![allow(unnecessary_refs)]
+
 use std::mem;
 
 fn assert_inorder<T: PartialEq + PartialOrd>(a: &[T]) {
diff --git a/tests/ui/stdlib-unit-tests/raw-fat-ptr.stderr b/tests/ui/stdlib-unit-tests/raw-fat-ptr.stderr
index 670fa5bb9224b..ac0de67292814 100644
--- a/tests/ui/stdlib-unit-tests/raw-fat-ptr.stderr
+++ b/tests/ui/stdlib-unit-tests/raw-fat-ptr.stderr
@@ -1,5 +1,5 @@
 warning: method `foo` is never used
-  --> $DIR/raw-fat-ptr.rs:35:16
+  --> $DIR/raw-fat-ptr.rs:37:16
    |
 LL | trait Foo { fn foo(&self) -> usize; }
    |       ---      ^^^
diff --git a/tests/ui/thread-local/tls-dylib-access.rs b/tests/ui/thread-local/tls-dylib-access.rs
index 53b01674d77ad..8a2e9aefa2e01 100644
--- a/tests/ui/thread-local/tls-dylib-access.rs
+++ b/tests/ui/thread-local/tls-dylib-access.rs
@@ -2,6 +2,7 @@
 //@ aux-build: tls-export.rs
 //@ run-pass
 
+#![allow(unnecessary_refs)]
 #![feature(cfg_target_thread_local)]
 
 #[cfg(target_thread_local)]
diff --git a/tests/ui/thread-local/tls.rs b/tests/ui/thread-local/tls.rs
index fa6a722b291d7..e2802f4b1f7de 100644
--- a/tests/ui/thread-local/tls.rs
+++ b/tests/ui/thread-local/tls.rs
@@ -3,6 +3,7 @@
 //@ compile-flags: -O
 //@ ignore-nto Doesn't work without emulated TLS enabled (in LLVM)
 
+#![allow(unnecessary_refs)]
 #![feature(thread_local)]
 
 #[thread_local]
diff --git a/tests/ui/threads-sendsync/task-spawn-move-and-copy.rs b/tests/ui/threads-sendsync/task-spawn-move-and-copy.rs
index 07d1a3d5c36ef..5f164e9d4ceb5 100644
--- a/tests/ui/threads-sendsync/task-spawn-move-and-copy.rs
+++ b/tests/ui/threads-sendsync/task-spawn-move-and-copy.rs
@@ -1,7 +1,9 @@
 //@ run-pass
-#![allow(unused_must_use)]
 //@ needs-threads
 
+#![allow(unused_must_use)]
+#![allow(unnecessary_refs)]
+
 use std::sync::mpsc::channel;
 use std::thread;
 
diff --git a/tests/ui/traits/const-traits/const-drop.rs b/tests/ui/traits/const-traits/const-drop.rs
index e2d87aeff47fb..12f57a091e64e 100644
--- a/tests/ui/traits/const-traits/const-drop.rs
+++ b/tests/ui/traits/const-traits/const-drop.rs
@@ -2,6 +2,8 @@
 //@ compile-flags: -Znext-solver
 //@ revisions: stock precise
 
+#![allow(unnecessary_refs)]
+
 #![feature(const_trait_impl, const_destruct)]
 #![feature(never_type)]
 #![cfg_attr(precise, feature(const_precise_live_drops))]
diff --git a/tests/ui/unsafe/place-expr-safe.rs b/tests/ui/unsafe/place-expr-safe.rs
index 2590ea7404655..9fcf819013b8e 100644
--- a/tests/ui/unsafe/place-expr-safe.rs
+++ b/tests/ui/unsafe/place-expr-safe.rs
@@ -1,5 +1,7 @@
 //@ check-pass
 
+#![allow(unnecessary_refs)]
+
 fn main() {
     let ptr = std::ptr::null_mut::<i32>();
     let addr = &raw const *ptr;