Skip to content

Commit 6edf3ce

Browse files
committed
split out tests
1 parent 59dfe31 commit 6edf3ce

File tree

4 files changed

+87
-89
lines changed

4 files changed

+87
-89
lines changed

compiler/rustc_data_structures/src/tagged_ptr/covariant.rs

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -321,56 +321,4 @@ where
321321
const _: () = ();
322322

323323
#[cfg(test)]
324-
mod tests {
325-
use std::ptr;
326-
327-
use super::*;
328-
use crate::hashes::Hash128;
329-
use crate::stable_hasher::{HashStable, StableHasher};
330-
use crate::tagged_ptr::tests::Tag2;
331-
332-
#[test]
333-
fn smoke() {
334-
let value = 12u32;
335-
let reference = &value;
336-
let tag = Tag2::B01;
337-
338-
let ptr = tag_ptr(reference, tag);
339-
340-
assert_eq!(ptr.tag(), tag);
341-
assert_eq!(*ptr, 12);
342-
assert!(ptr::eq(ptr.pointer(), reference));
343-
344-
let copy = ptr;
345-
346-
let mut ptr = ptr;
347-
ptr.set_tag(Tag2::B00);
348-
assert_eq!(ptr.tag(), Tag2::B00);
349-
350-
assert_eq!(copy.tag(), tag);
351-
assert_eq!(*copy, 12);
352-
assert!(ptr::eq(copy.pointer(), reference));
353-
}
354-
355-
#[test]
356-
fn stable_hash_hashes_as_tuple() {
357-
let hash_packed = {
358-
let mut hasher = StableHasher::new();
359-
tag_ptr(&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
360-
hasher.finish::<Hash128>()
361-
};
362-
363-
let hash_tupled = {
364-
let mut hasher = StableHasher::new();
365-
(&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
366-
hasher.finish::<Hash128>()
367-
};
368-
369-
assert_eq!(hash_packed, hash_tupled);
370-
}
371-
372-
/// Helper to create tagged pointers without specifying `COMPARE_PACKED` if it does not matter.
373-
fn tag_ptr<P: Pointer, T: Tag>(ptr: P, tag: T) -> TaggedPtr<P, P::Target, T, true> {
374-
TaggedPtr::new(ptr, tag)
375-
}
376-
}
324+
mod tests;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use std::ptr;
2+
3+
use super::*;
4+
use crate::hashes::Hash128;
5+
use crate::stable_hasher::{HashStable, StableHasher};
6+
use crate::tagged_ptr::tests::Tag2;
7+
8+
#[test]
9+
fn smoke() {
10+
let value = 12u32;
11+
let reference = &value;
12+
let tag = Tag2::B01;
13+
14+
let ptr = tag_ptr(reference, tag);
15+
16+
assert_eq!(ptr.tag(), tag);
17+
assert_eq!(*ptr, 12);
18+
assert!(ptr::eq(ptr.pointer(), reference));
19+
20+
let copy = ptr;
21+
22+
let mut ptr = ptr;
23+
ptr.set_tag(Tag2::B00);
24+
assert_eq!(ptr.tag(), Tag2::B00);
25+
26+
assert_eq!(copy.tag(), tag);
27+
assert_eq!(*copy, 12);
28+
assert!(ptr::eq(copy.pointer(), reference));
29+
}
30+
31+
#[test]
32+
fn stable_hash_hashes_as_tuple() {
33+
let hash_packed = {
34+
let mut hasher = StableHasher::new();
35+
tag_ptr(&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
36+
hasher.finish::<Hash128>()
37+
};
38+
39+
let hash_tupled = {
40+
let mut hasher = StableHasher::new();
41+
(&12, Tag2::B11).hash_stable(&mut (), &mut hasher);
42+
hasher.finish::<Hash128>()
43+
};
44+
45+
assert_eq!(hash_packed, hash_tupled);
46+
}
47+
48+
/// Helper to create tagged pointers without specifying `COMPARE_PACKED` if it does not matter.
49+
fn tag_ptr<P: Pointer, T: Tag>(ptr: P, tag: T) -> TaggedPtr<P, P::Target, T, true> {
50+
TaggedPtr::new(ptr, tag)
51+
}

compiler/rustc_data_structures/src/tagged_ptr/impl_tag.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -141,39 +141,4 @@ macro_rules! impl_tag {
141141
}
142142

143143
#[cfg(test)]
144-
mod tests {
145-
#[test]
146-
fn bits_constant() {
147-
use crate::tagged_ptr::Tag;
148-
149-
#[derive(Copy, Clone)]
150-
struct Unit;
151-
impl_tag! { impl Tag for Unit; Unit, }
152-
assert_eq!(Unit::BITS, 0);
153-
154-
#[derive(Copy, Clone)]
155-
enum Enum3 {
156-
A,
157-
B,
158-
C,
159-
}
160-
impl_tag! { impl Tag for Enum3; Enum3::A, Enum3::B, Enum3::C, }
161-
assert_eq!(Enum3::BITS, 2);
162-
163-
#[derive(Copy, Clone)]
164-
struct Eight(bool, bool, bool);
165-
impl_tag! {
166-
impl Tag for Eight;
167-
Eight { 0: true, 1: true, 2: true },
168-
Eight { 0: true, 1: true, 2: false },
169-
Eight { 0: true, 1: false, 2: true },
170-
Eight { 0: true, 1: false, 2: false },
171-
Eight { 0: false, 1: true, 2: true },
172-
Eight { 0: false, 1: true, 2: false },
173-
Eight { 0: false, 1: false, 2: true },
174-
Eight { 0: false, 1: false, 2: false },
175-
}
176-
177-
assert_eq!(Eight::BITS, 3);
178-
}
179-
}
144+
mod tests;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#[test]
2+
fn bits_constant() {
3+
use crate::tagged_ptr::Tag;
4+
5+
#[derive(Copy, Clone)]
6+
struct Unit;
7+
impl_tag! { impl Tag for Unit; Unit, }
8+
assert_eq!(Unit::BITS, 0);
9+
10+
#[derive(Copy, Clone)]
11+
enum Enum3 {
12+
A,
13+
B,
14+
C,
15+
}
16+
impl_tag! { impl Tag for Enum3; Enum3::A, Enum3::B, Enum3::C, }
17+
assert_eq!(Enum3::BITS, 2);
18+
19+
#[derive(Copy, Clone)]
20+
struct Eight(bool, bool, bool);
21+
impl_tag! {
22+
impl Tag for Eight;
23+
Eight { 0: true, 1: true, 2: true },
24+
Eight { 0: true, 1: true, 2: false },
25+
Eight { 0: true, 1: false, 2: true },
26+
Eight { 0: true, 1: false, 2: false },
27+
Eight { 0: false, 1: true, 2: true },
28+
Eight { 0: false, 1: true, 2: false },
29+
Eight { 0: false, 1: false, 2: true },
30+
Eight { 0: false, 1: false, 2: false },
31+
}
32+
33+
assert_eq!(Eight::BITS, 3);
34+
}

0 commit comments

Comments
 (0)