Skip to content

Commit 251f662

Browse files
committed
Share Tag2 impl between CopyTaggedPtr and TaggedPtr tests
1 parent 8d49e94 commit 251f662

File tree

3 files changed

+31
-62
lines changed

3 files changed

+31
-62
lines changed

compiler/rustc_data_structures/src/tagged_ptr.rs

+29
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,32 @@ pub const fn bits_for<T: ?Sized + Aligned>() -> usize {
232232

233233
bits as usize
234234
}
235+
236+
/// A tag type used in [`CopyTaggedPtr`] and [`TaggedPtr`] tests.
237+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
238+
#[cfg(test)]
239+
enum Tag2 {
240+
B00 = 0b00,
241+
B01 = 0b01,
242+
B10 = 0b10,
243+
B11 = 0b11,
244+
}
245+
246+
#[cfg(test)]
247+
unsafe impl Tag for Tag2 {
248+
const BITS: usize = 2;
249+
250+
fn into_usize(self) -> usize {
251+
self as _
252+
}
253+
254+
unsafe fn from_usize(tag: usize) -> Self {
255+
match tag {
256+
0b00 => Tag2::B00,
257+
0b01 => Tag2::B01,
258+
0b10 => Tag2::B10,
259+
0b11 => Tag2::B11,
260+
_ => unreachable!(),
261+
}
262+
}
263+
}

compiler/rustc_data_structures/src/tagged_ptr/copy/tests.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
use std::ptr;
22

3-
use crate::tagged_ptr::{CopyTaggedPtr, Pointer, Tag};
4-
5-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6-
enum Tag2 {
7-
B00 = 0b00,
8-
B01 = 0b01,
9-
B10 = 0b10,
10-
B11 = 0b11,
11-
}
12-
13-
unsafe impl Tag for Tag2 {
14-
const BITS: usize = 2;
15-
16-
fn into_usize(self) -> usize {
17-
self as _
18-
}
19-
20-
unsafe fn from_usize(tag: usize) -> Self {
21-
const B00: usize = Tag2::B00 as _;
22-
const B01: usize = Tag2::B01 as _;
23-
const B10: usize = Tag2::B10 as _;
24-
const B11: usize = Tag2::B11 as _;
25-
match tag {
26-
B00 => Tag2::B00,
27-
B01 => Tag2::B01,
28-
B10 => Tag2::B10,
29-
B11 => Tag2::B11,
30-
_ => unreachable!(),
31-
}
32-
}
33-
}
3+
use crate::tagged_ptr::{CopyTaggedPtr, Pointer, Tag, Tag2};
344

355
#[test]
366
fn smoke() {

compiler/rustc_data_structures/src/tagged_ptr/drop/tests.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
use std::{ptr, sync::Arc};
22

3-
use crate::tagged_ptr::{Pointer, Tag, TaggedPtr};
4-
5-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6-
enum Tag2 {
7-
B00 = 0b00,
8-
B01 = 0b01,
9-
B10 = 0b10,
10-
B11 = 0b11,
11-
}
12-
13-
unsafe impl Tag for Tag2 {
14-
const BITS: usize = 2;
15-
16-
fn into_usize(self) -> usize {
17-
self as _
18-
}
19-
20-
unsafe fn from_usize(tag: usize) -> Self {
21-
const B00: usize = Tag2::B00 as _;
22-
const B01: usize = Tag2::B01 as _;
23-
const B10: usize = Tag2::B10 as _;
24-
const B11: usize = Tag2::B11 as _;
25-
match tag {
26-
B00 => Tag2::B00,
27-
B01 => Tag2::B01,
28-
B10 => Tag2::B10,
29-
B11 => Tag2::B11,
30-
_ => unreachable!(),
31-
}
32-
}
33-
}
3+
use crate::tagged_ptr::{Pointer, Tag, Tag2, TaggedPtr};
344

355
#[test]
366
fn smoke() {

0 commit comments

Comments
 (0)