Skip to content

Commit d8aa257

Browse files
authored
Rollup merge of rust-lang#83197 - jyn514:cfg-test-dead-code, r=joshtriplett
Move some test-only code to test files Split out from rust-lang#83185.
2 parents c512aa0 + 620ecc0 commit d8aa257

File tree

8 files changed

+85
-78
lines changed

8 files changed

+85
-78
lines changed

compiler/rustc_arena/src/lib.rs

-16
Original file line numberDiff line numberDiff line change
@@ -298,22 +298,6 @@ impl<T> TypedArena<T> {
298298
}
299299
}
300300

301-
/// Clears the arena. Deallocates all but the longest chunk which may be reused.
302-
pub fn clear(&mut self) {
303-
unsafe {
304-
// Clear the last chunk, which is partially filled.
305-
let mut chunks_borrow = self.chunks.borrow_mut();
306-
if let Some(mut last_chunk) = chunks_borrow.last_mut() {
307-
self.clear_last_chunk(&mut last_chunk);
308-
let len = chunks_borrow.len();
309-
// If `T` is ZST, code below has no effect.
310-
for mut chunk in chunks_borrow.drain(..len - 1) {
311-
chunk.destroy(chunk.entries);
312-
}
313-
}
314-
}
315-
}
316-
317301
// Drops the contents of the last chunk. The last chunk is partially empty, unlike all other
318302
// chunks.
319303
fn clear_last_chunk(&self, last_chunk: &mut TypedArenaChunk<T>) {

compiler/rustc_arena/src/tests.rs

+18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ struct Point {
1111
z: i32,
1212
}
1313

14+
impl<T> TypedArena<T> {
15+
/// Clears the arena. Deallocates all but the longest chunk which may be reused.
16+
fn clear(&mut self) {
17+
unsafe {
18+
// Clear the last chunk, which is partially filled.
19+
let mut chunks_borrow = self.chunks.borrow_mut();
20+
if let Some(mut last_chunk) = chunks_borrow.last_mut() {
21+
self.clear_last_chunk(&mut last_chunk);
22+
let len = chunks_borrow.len();
23+
// If `T` is ZST, code below has no effect.
24+
for mut chunk in chunks_borrow.drain(..len - 1) {
25+
chunk.destroy(chunk.entries);
26+
}
27+
}
28+
}
29+
}
30+
}
31+
1432
#[test]
1533
pub fn test_unused() {
1634
let arena: TypedArena<Point> = TypedArena::default();

compiler/rustc_data_structures/src/tiny_list.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
mod tests;
1616

1717
#[derive(Clone)]
18-
pub struct TinyList<T: PartialEq> {
18+
pub struct TinyList<T> {
1919
head: Option<Element<T>>,
2020
}
2121

@@ -56,20 +56,10 @@ impl<T: PartialEq> TinyList<T> {
5656
}
5757
false
5858
}
59-
60-
#[inline]
61-
pub fn len(&self) -> usize {
62-
let (mut elem, mut count) = (self.head.as_ref(), 0);
63-
while let Some(ref e) = elem {
64-
count += 1;
65-
elem = e.next.as_deref();
66-
}
67-
count
68-
}
6959
}
7060

7161
#[derive(Clone)]
72-
struct Element<T: PartialEq> {
62+
struct Element<T> {
7363
data: T,
7464
next: Option<Box<Element<T>>>,
7565
}

compiler/rustc_data_structures/src/tiny_list/tests.rs

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ use super::*;
33
extern crate test;
44
use test::{black_box, Bencher};
55

6+
impl<T> TinyList<T> {
7+
fn len(&self) -> usize {
8+
let (mut elem, mut count) = (self.head.as_ref(), 0);
9+
while let Some(ref e) = elem {
10+
count += 1;
11+
elem = e.next.as_deref();
12+
}
13+
count
14+
}
15+
}
16+
617
#[test]
718
fn test_contains_and_insert() {
819
fn do_insert(i: u32) -> bool {

compiler/rustc_data_structures/src/transitive_relation.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::mem;
99
mod tests;
1010

1111
#[derive(Clone, Debug)]
12-
pub struct TransitiveRelation<T: Eq + Hash> {
12+
pub struct TransitiveRelation<T> {
1313
// List of elements. This is used to map from a T to a usize.
1414
elements: FxIndexSet<T>,
1515

@@ -49,7 +49,7 @@ struct Edge {
4949
target: Index,
5050
}
5151

52-
impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
52+
impl<T: Eq + Hash> TransitiveRelation<T> {
5353
pub fn is_empty(&self) -> bool {
5454
self.edges.is_empty()
5555
}
@@ -322,12 +322,6 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
322322
.collect()
323323
}
324324

325-
/// A "best" parent in some sense. See `parents` and
326-
/// `postdom_upper_bound` for more details.
327-
pub fn postdom_parent(&self, a: &T) -> Option<&T> {
328-
self.mutual_immediate_postdominator(self.parents(a))
329-
}
330-
331325
fn with_closure<OP, R>(&self, op: OP) -> R
332326
where
333327
OP: FnOnce(&BitMatrix<usize, usize>) -> R,

compiler/rustc_data_structures/src/transitive_relation/tests.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
use super::*;
22

3+
impl<T: Eq + Hash> TransitiveRelation<T> {
4+
/// A "best" parent in some sense. See `parents` and
5+
/// `postdom_upper_bound` for more details.
6+
fn postdom_parent(&self, a: &T) -> Option<&T> {
7+
self.mutual_immediate_postdominator(self.parents(a))
8+
}
9+
}
10+
311
#[test]
412
fn test_one_step() {
513
let mut relation = TransitiveRelation::default();

compiler/rustc_span/src/source_map.rs

-42
Original file line numberDiff line numberDiff line change
@@ -453,41 +453,6 @@ impl SourceMap {
453453
}
454454
}
455455

456-
/// Returns `Some(span)`, a union of the LHS and RHS span. The LHS must precede the RHS. If
457-
/// there are gaps between LHS and RHS, the resulting union will cross these gaps.
458-
/// For this to work,
459-
///
460-
/// * the syntax contexts of both spans much match,
461-
/// * the LHS span needs to end on the same line the RHS span begins,
462-
/// * the LHS span must start at or before the RHS span.
463-
pub fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span> {
464-
// Ensure we're at the same expansion ID.
465-
if sp_lhs.ctxt() != sp_rhs.ctxt() {
466-
return None;
467-
}
468-
469-
let lhs_end = match self.lookup_line(sp_lhs.hi()) {
470-
Ok(x) => x,
471-
Err(_) => return None,
472-
};
473-
let rhs_begin = match self.lookup_line(sp_rhs.lo()) {
474-
Ok(x) => x,
475-
Err(_) => return None,
476-
};
477-
478-
// If we must cross lines to merge, don't merge.
479-
if lhs_end.line != rhs_begin.line {
480-
return None;
481-
}
482-
483-
// Ensure these follow the expected order and that we don't overlap.
484-
if (sp_lhs.lo() <= sp_rhs.lo()) && (sp_lhs.hi() <= sp_rhs.lo()) {
485-
Some(sp_lhs.to(sp_rhs))
486-
} else {
487-
None
488-
}
489-
}
490-
491456
pub fn span_to_string(&self, sp: Span) -> String {
492457
if self.files.borrow().source_files.is_empty() && sp.is_dummy() {
493458
return "no-location".to_string();
@@ -931,13 +896,6 @@ impl SourceMap {
931896
SourceFileAndBytePos { sf, pos: offset }
932897
}
933898

934-
/// Converts an absolute `BytePos` to a `CharPos` relative to the `SourceFile`.
935-
pub fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos {
936-
let idx = self.lookup_source_file_idx(bpos);
937-
let sf = &(*self.files.borrow().source_files)[idx];
938-
sf.bytepos_to_file_charpos(bpos)
939-
}
940-
941899
// Returns the index of the `SourceFile` (in `self.files`) that contains `pos`.
942900
// This index is guaranteed to be valid for the lifetime of this `SourceMap`,
943901
// since `source_files` is a `MonotonicVec`

compiler/rustc_span/src/source_map/tests.rs

+44
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,50 @@ fn init_source_map() -> SourceMap {
1010
sm
1111
}
1212

13+
impl SourceMap {
14+
/// Returns `Some(span)`, a union of the LHS and RHS span. The LHS must precede the RHS. If
15+
/// there are gaps between LHS and RHS, the resulting union will cross these gaps.
16+
/// For this to work,
17+
///
18+
/// * the syntax contexts of both spans much match,
19+
/// * the LHS span needs to end on the same line the RHS span begins,
20+
/// * the LHS span must start at or before the RHS span.
21+
fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span> {
22+
// Ensure we're at the same expansion ID.
23+
if sp_lhs.ctxt() != sp_rhs.ctxt() {
24+
return None;
25+
}
26+
27+
let lhs_end = match self.lookup_line(sp_lhs.hi()) {
28+
Ok(x) => x,
29+
Err(_) => return None,
30+
};
31+
let rhs_begin = match self.lookup_line(sp_rhs.lo()) {
32+
Ok(x) => x,
33+
Err(_) => return None,
34+
};
35+
36+
// If we must cross lines to merge, don't merge.
37+
if lhs_end.line != rhs_begin.line {
38+
return None;
39+
}
40+
41+
// Ensure these follow the expected order and that we don't overlap.
42+
if (sp_lhs.lo() <= sp_rhs.lo()) && (sp_lhs.hi() <= sp_rhs.lo()) {
43+
Some(sp_lhs.to(sp_rhs))
44+
} else {
45+
None
46+
}
47+
}
48+
49+
/// Converts an absolute `BytePos` to a `CharPos` relative to the `SourceFile`.
50+
fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos {
51+
let idx = self.lookup_source_file_idx(bpos);
52+
let sf = &(*self.files.borrow().source_files)[idx];
53+
sf.bytepos_to_file_charpos(bpos)
54+
}
55+
}
56+
1357
/// Tests `lookup_byte_offset`.
1458
#[test]
1559
fn t3() {

0 commit comments

Comments
 (0)