diff --git a/compiler/rustc_data_structures/src/tagged_ptr.rs b/compiler/rustc_data_structures/src/tagged_ptr.rs index 750affa468b..14f282dcbeb 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr.rs @@ -232,3 +232,32 @@ pub const fn bits_for() -> usize { bits as usize } + +/// A tag type used in [`CopyTaggedPtr`] and [`TaggedPtr`] tests. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[cfg(test)] +enum Tag2 { + B00 = 0b00, + B01 = 0b01, + B10 = 0b10, + B11 = 0b11, +} + +#[cfg(test)] +unsafe impl Tag for Tag2 { + const BITS: usize = 2; + + fn into_usize(self) -> usize { + self as _ + } + + unsafe fn from_usize(tag: usize) -> Self { + match tag { + 0b00 => Tag2::B00, + 0b01 => Tag2::B01, + 0b10 => Tag2::B10, + 0b11 => Tag2::B11, + _ => unreachable!(), + } + } +} diff --git a/compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs b/compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs index 77544f9c032..09e7b59fd64 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs @@ -1,36 +1,6 @@ use std::ptr; -use crate::tagged_ptr::{CopyTaggedPtr, Pointer, Tag}; - -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -enum Tag2 { - B00 = 0b00, - B01 = 0b01, - B10 = 0b10, - B11 = 0b11, -} - -unsafe impl Tag for Tag2 { - const BITS: usize = 2; - - fn into_usize(self) -> usize { - self as _ - } - - unsafe fn from_usize(tag: usize) -> Self { - const B00: usize = Tag2::B00 as _; - const B01: usize = Tag2::B01 as _; - const B10: usize = Tag2::B10 as _; - const B11: usize = Tag2::B11 as _; - match tag { - B00 => Tag2::B00, - B01 => Tag2::B01, - B10 => Tag2::B10, - B11 => Tag2::B11, - _ => unreachable!(), - } - } -} +use crate::tagged_ptr::{CopyTaggedPtr, Pointer, Tag, Tag2}; #[test] fn smoke() { diff --git a/compiler/rustc_data_structures/src/tagged_ptr/drop/tests.rs b/compiler/rustc_data_structures/src/tagged_ptr/drop/tests.rs index 0c61cebaf7e..2c17d678d3a 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/drop/tests.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/drop/tests.rs @@ -1,36 +1,6 @@ use std::{ptr, sync::Arc}; -use crate::tagged_ptr::{Pointer, Tag, TaggedPtr}; - -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -enum Tag2 { - B00 = 0b00, - B01 = 0b01, - B10 = 0b10, - B11 = 0b11, -} - -unsafe impl Tag for Tag2 { - const BITS: usize = 2; - - fn into_usize(self) -> usize { - self as _ - } - - unsafe fn from_usize(tag: usize) -> Self { - const B00: usize = Tag2::B00 as _; - const B01: usize = Tag2::B01 as _; - const B10: usize = Tag2::B10 as _; - const B11: usize = Tag2::B11 as _; - match tag { - B00 => Tag2::B00, - B01 => Tag2::B01, - B10 => Tag2::B10, - B11 => Tag2::B11, - _ => unreachable!(), - } - } -} +use crate::tagged_ptr::{Pointer, Tag, Tag2, TaggedPtr}; #[test] fn smoke() {