From 62ec2cb7acb1b16d0abd8a2cf40da545a13d29f3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 2 Aug 2019 01:58:40 +0300 Subject: [PATCH] Remove some more `cfg(test)`s --- src/bootstrap/cache.rs | 5 +++-- src/liballoc/collections/linked_list/tests.rs | 1 - src/liballoc/tests/linked_list.rs | 2 -- src/liballoc/tests/vec_deque.rs | 1 - .../graph/dominators/mod.rs | 5 ----- .../graph/dominators/tests.rs | 8 +++---- .../obligation_forest/tests.rs | 4 +--- src/libsyntax/print/pprust.rs | 20 ----------------- src/libsyntax/print/pprust/tests.rs | 16 ++++++++++++++ src/libtest/lib.rs | 22 ------------------- src/libtest/tests.rs | 21 ++++++++++++++++++ 11 files changed, 45 insertions(+), 60 deletions(-) diff --git a/src/bootstrap/cache.rs b/src/bootstrap/cache.rs index f137a7b8cc2..53071df8552 100644 --- a/src/bootstrap/cache.rs +++ b/src/bootstrap/cache.rs @@ -266,8 +266,10 @@ impl Cache { .expect("invalid type mapped"); stepcache.get(step).cloned() } +} - #[cfg(test)] +#[cfg(test)] +impl Cache { pub fn all(&mut self) -> Vec<(S, S::Output)> { let cache = self.0.get_mut(); let type_id = TypeId::of::(); @@ -279,7 +281,6 @@ impl Cache { v } - #[cfg(test)] pub fn contains(&self) -> bool { self.0.borrow().contains_key(&TypeId::of::()) } diff --git a/src/liballoc/collections/linked_list/tests.rs b/src/liballoc/collections/linked_list/tests.rs index 953b0d4eb28..9a6c57d2869 100644 --- a/src/liballoc/collections/linked_list/tests.rs +++ b/src/liballoc/collections/linked_list/tests.rs @@ -201,7 +201,6 @@ fn test_split_off() { } } -#[cfg(test)] fn fuzz_test(sz: i32) { let mut m: LinkedList<_> = LinkedList::new(); let mut v = vec![]; diff --git a/src/liballoc/tests/linked_list.rs b/src/liballoc/tests/linked_list.rs index 0fbfbdccd45..8a26454c389 100644 --- a/src/liballoc/tests/linked_list.rs +++ b/src/liballoc/tests/linked_list.rs @@ -40,12 +40,10 @@ fn test_basic() { assert_eq!(n.pop_front(), Some(1)); } -#[cfg(test)] fn generate_test() -> LinkedList { list_from(&[0, 1, 2, 3, 4, 5, 6]) } -#[cfg(test)] fn list_from(v: &[T]) -> LinkedList { v.iter().cloned().collect() } diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index e0fe10a55f5..1bbcca97b3c 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -44,7 +44,6 @@ fn test_simple() { assert_eq!(d[3], 4); } -#[cfg(test)] fn test_parameterized(a: T, b: T, c: T, d: T) { let mut deq = VecDeque::new(); assert_eq!(deq.len(), 0); diff --git a/src/librustc_data_structures/graph/dominators/mod.rs b/src/librustc_data_structures/graph/dominators/mod.rs index 04ddca7896a..41e6b72953e 100644 --- a/src/librustc_data_structures/graph/dominators/mod.rs +++ b/src/librustc_data_structures/graph/dominators/mod.rs @@ -127,11 +127,6 @@ impl Dominators { // FIXME -- could be optimized by using post-order-rank self.dominators(node).any(|n| n == dom) } - - #[cfg(test)] - fn all_immediate_dominators(&self) -> &IndexVec> { - &self.immediate_dominators - } } pub struct Iter<'dom, Node: Idx> { diff --git a/src/librustc_data_structures/graph/dominators/tests.rs b/src/librustc_data_structures/graph/dominators/tests.rs index 70408fb6df1..92301ff6526 100644 --- a/src/librustc_data_structures/graph/dominators/tests.rs +++ b/src/librustc_data_structures/graph/dominators/tests.rs @@ -1,13 +1,13 @@ -use super::super::tests::TestGraph; - use super::*; +use super::super::tests::TestGraph; + #[test] fn diamond() { let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]); let dominators = dominators(&graph); - let immediate_dominators = dominators.all_immediate_dominators(); + let immediate_dominators = &dominators.immediate_dominators; assert_eq!(immediate_dominators[0], Some(0)); assert_eq!(immediate_dominators[1], Some(0)); assert_eq!(immediate_dominators[2], Some(0)); @@ -22,7 +22,7 @@ fn paper() { (2, 1)]); let dominators = dominators(&graph); - let immediate_dominators = dominators.all_immediate_dominators(); + let immediate_dominators = &dominators.immediate_dominators; assert_eq!(immediate_dominators[0], None); // <-- note that 0 is not in graph assert_eq!(immediate_dominators[1], Some(6)); assert_eq!(immediate_dominators[2], Some(6)); diff --git a/src/librustc_data_structures/obligation_forest/tests.rs b/src/librustc_data_structures/obligation_forest/tests.rs index 27d4bf4959e..e20466572a2 100644 --- a/src/librustc_data_structures/obligation_forest/tests.rs +++ b/src/librustc_data_structures/obligation_forest/tests.rs @@ -1,6 +1,4 @@ -#![cfg(test)] - -use super::{Error, DoCompleted, ObligationForest, ObligationProcessor, Outcome, ProcessResult}; +use super::*; use std::fmt; use std::marker::PhantomData; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f6dd95a7f4f..3645ab88d55 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -384,21 +384,6 @@ pub fn vis_to_string(v: &ast::Visibility) -> String { to_string(|s| s.print_visibility(v)) } -#[cfg(test)] -fn fun_to_string(decl: &ast::FnDecl, - header: ast::FnHeader, - name: ast::Ident, - generics: &ast::Generics) - -> String { - to_string(|s| { - s.head(""); - s.print_fn(decl, header, Some(name), - generics, &source_map::dummy_spanned(ast::VisibilityKind::Inherited)); - s.end(); // Close the head box - s.end(); // Close the outer box - }) -} - fn block_to_string(blk: &ast::Block) -> String { to_string(|s| { // containing cbox, will be closed by print-block at } @@ -421,11 +406,6 @@ pub fn attribute_to_string(attr: &ast::Attribute) -> String { to_string(|s| s.print_attribute(attr)) } -#[cfg(test)] -fn variant_to_string(var: &ast::Variant) -> String { - to_string(|s| s.print_variant(var)) -} - pub fn arg_to_string(arg: &ast::Arg) -> String { to_string(|s| s.print_arg(arg, false)) } diff --git a/src/libsyntax/print/pprust/tests.rs b/src/libsyntax/print/pprust/tests.rs index 97df7e6dcbd..082a430e0ed 100644 --- a/src/libsyntax/print/pprust/tests.rs +++ b/src/libsyntax/print/pprust/tests.rs @@ -5,6 +5,22 @@ use crate::source_map; use crate::with_default_globals; use syntax_pos; +fn fun_to_string( + decl: &ast::FnDecl, header: ast::FnHeader, name: ast::Ident, generics: &ast::Generics +) -> String { + to_string(|s| { + s.head(""); + s.print_fn(decl, header, Some(name), + generics, &source_map::dummy_spanned(ast::VisibilityKind::Inherited)); + s.end(); // Close the head box + s.end(); // Close the outer box + }) +} + +fn variant_to_string(var: &ast::Variant) -> String { + to_string(|s| s.print_variant(var)) +} + #[test] fn test_fun_to_string() { with_default_globals(|| { diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index b36c5be4c07..ef66c4df99d 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -380,28 +380,6 @@ pub struct TestOpts { pub options: Options, } -impl TestOpts { - #[cfg(test)] - fn new() -> TestOpts { - TestOpts { - list: false, - filter: None, - filter_exact: false, - exclude_should_panic: false, - run_ignored: RunIgnored::No, - run_tests: false, - bench_benchmarks: false, - logfile: None, - nocapture: false, - color: AutoColor, - format: OutputFormat::Pretty, - test_threads: None, - skip: vec![], - options: Options::new(), - } - } -} - /// Result of parsing the options. pub type OptRes = Result; diff --git a/src/libtest/tests.rs b/src/libtest/tests.rs index 05b38f17e2b..f574743e4b6 100644 --- a/src/libtest/tests.rs +++ b/src/libtest/tests.rs @@ -7,6 +7,27 @@ use crate::test::{ }; use std::sync::mpsc::channel; +impl TestOpts { + fn new() -> TestOpts { + TestOpts { + list: false, + filter: None, + filter_exact: false, + exclude_should_panic: false, + run_ignored: RunIgnored::No, + run_tests: false, + bench_benchmarks: false, + logfile: None, + nocapture: false, + color: AutoColor, + format: OutputFormat::Pretty, + test_threads: None, + skip: vec![], + options: Options::new(), + } + } +} + fn one_ignored_one_unignored_test() -> Vec { vec![ TestDescAndFn {