mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Share Tag2
impl between CopyTaggedPtr
and TaggedPtr
tests
This commit is contained in:
parent
8d49e948a8
commit
251f662e4d
@ -232,3 +232,32 @@ pub const fn bits_for<T: ?Sized + Aligned>() -> 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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user