diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index c039b181178a4..9ab873d711f3c 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -16,9 +16,6 @@ use rustc_span::Span; use crate::html::escape::Escape; -#[cfg(test)] -mod tests; - #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum Cfg { /// Accepts all configurations. diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 7b7c152d8abbf..a856c250bf462 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -1034,6 +1034,3 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx> ); } } - -#[cfg(test)] -mod tests; diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 4769edc50ff07..909f0c4804426 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -45,7 +45,7 @@ fn write_header(out: &mut String, class: Option<&str>) { .unwrap() } -fn write_code(out: &mut String, src: &str) { +crate fn write_code(out: &mut String, src: &str) { Classifier::new(src).highlight(&mut |highlight| { match highlight { Highlight::Token { text, class } => string(out, Escape(text), class), @@ -343,6 +343,3 @@ fn string(out: &mut String, text: T, klass: Class) { klass => write!(out, "{}", klass.as_html(), text).unwrap(), } } - -#[cfg(test)] -mod tests; diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index d54b8ea747899..b20f4c70fcd18 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -40,9 +40,6 @@ use crate::html::toc::TocBuilder; use pulldown_cmark::{html, CodeBlockKind, CowStr, Event, Options, Parser, Tag}; -#[cfg(test)] -mod tests; - fn opts() -> Options { Options::ENABLE_TABLES | Options::ENABLE_FOOTNOTES | Options::ENABLE_STRIKETHROUGH } @@ -678,6 +675,10 @@ impl<'a, 'b> ExtraInfo<'a, 'b> { #[derive(Eq, PartialEq, Clone, Debug)] pub struct LangString { + #[cfg(test)] + // Only making it public when running tests. + pub original: String, + #[cfg(not(test))] original: String, pub should_panic: bool, pub no_run: bool, @@ -698,7 +699,7 @@ pub enum Ignore { } impl LangString { - fn all_false() -> LangString { + pub fn all_false() -> LangString { LangString { original: String::new(), should_panic: false, @@ -713,7 +714,7 @@ impl LangString { } } - fn parse_without_check( + pub fn parse_without_check( string: &str, allow_error_code_check: ErrorCodes, enable_per_target_ignores: bool, @@ -721,7 +722,7 @@ impl LangString { Self::parse(string, allow_error_code_check, enable_per_target_ignores, None) } - fn parse( + pub fn parse( string: &str, allow_error_code_check: ErrorCodes, enable_per_target_ignores: bool, diff --git a/src/librustdoc/html/mod.rs b/src/librustdoc/html/mod.rs index 367538d440ea1..8f7552d0936b9 100644 --- a/src/librustdoc/html/mod.rs +++ b/src/librustdoc/html/mod.rs @@ -4,6 +4,6 @@ crate mod highlight; crate mod layout; pub mod markdown; pub mod render; -crate mod sources; +pub mod sources; crate mod static_files; -crate mod toc; +pub mod toc; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 470e9d5ae768d..779488c285aa8 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -27,9 +27,6 @@ pub mod cache; -#[cfg(test)] -mod tests; - use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::cmp::Ordering; diff --git a/src/librustdoc/html/toc.rs b/src/librustdoc/html/toc.rs index 721988e29a678..eb45926a67719 100644 --- a/src/librustdoc/html/toc.rs +++ b/src/librustdoc/html/toc.rs @@ -16,7 +16,7 @@ pub struct Toc { /// ### A /// ## B /// ``` - entries: Vec, + pub(crate) entries: Vec, } impl Toc { @@ -27,11 +27,11 @@ impl Toc { #[derive(Debug, PartialEq)] pub struct TocEntry { - level: u32, - sec_number: String, - name: String, - id: String, - children: Toc, + pub(crate) level: u32, + pub(crate) sec_number: String, + pub(crate) name: String, + pub(crate) id: String, + pub(crate) children: Toc, } /// Progressive construction of a table of contents. @@ -183,6 +183,3 @@ impl Toc { v } } - -#[cfg(test)] -mod tests; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 73a783d54060c..8632a7a9a243f 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -37,7 +37,7 @@ extern crate rustc_mir; extern crate rustc_parse; extern crate rustc_resolve; extern crate rustc_session; -extern crate rustc_span as rustc_span; +extern crate rustc_span; extern crate rustc_target; extern crate rustc_trait_selection; extern crate rustc_typeck; @@ -57,21 +57,24 @@ use rustc_session::{early_error, early_warn}; #[macro_use] mod externalfiles; -mod clean; +#[cfg(test)] +mod rustdoc_tests; + +crate mod clean; mod config; mod core; mod docfs; mod doctree; #[macro_use] mod error; -mod doctest; +crate mod doctest; mod fold; crate mod formats; pub mod html; mod json; mod markdown; -mod passes; -mod theme; +crate mod passes; +crate mod theme; mod visit_ast; mod visit_lib; diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 75a659666673f..9c143c0cc8ba2 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -24,7 +24,7 @@ pub use self::strip_private::STRIP_PRIVATE; mod strip_priv_imports; pub use self::strip_priv_imports::STRIP_PRIV_IMPORTS; -mod unindent_comments; +crate mod unindent_comments; pub use self::unindent_comments::UNINDENT_COMMENTS; mod propagate_doc_cfg; diff --git a/src/librustdoc/passes/unindent_comments.rs b/src/librustdoc/passes/unindent_comments.rs index 5604a9c2dc163..2064f29c36abf 100644 --- a/src/librustdoc/passes/unindent_comments.rs +++ b/src/librustdoc/passes/unindent_comments.rs @@ -6,16 +6,13 @@ use crate::core::DocContext; use crate::fold::{self, DocFolder}; use crate::passes::Pass; -#[cfg(test)] -mod tests; - pub const UNINDENT_COMMENTS: Pass = Pass { name: "unindent-comments", run: unindent_comments, description: "removes excess indentation on comments in order for markdown to like it", }; -pub fn unindent_comments(krate: clean::Crate, _: &DocContext<'_>) -> clean::Crate { +crate fn unindent_comments(krate: clean::Crate, _: &DocContext<'_>) -> clean::Crate { CommentCleaner.fold_crate(krate) } @@ -46,7 +43,7 @@ fn unindent_fragments(docs: &mut Vec) { } } -fn unindent(s: &str) -> String { +crate fn unindent(s: &str) -> String { let lines = s.lines().collect::>(); let mut saw_first_line = false; let mut saw_second_line = false; diff --git a/src/librustdoc/clean/cfg/tests.rs b/src/librustdoc/rustdoc_tests/clean_cfg.rs similarity index 99% rename from src/librustdoc/clean/cfg/tests.rs rename to src/librustdoc/rustdoc_tests/clean_cfg.rs index 794a7bcaf1cb7..de48d03e94b5a 100644 --- a/src/librustdoc/clean/cfg/tests.rs +++ b/src/librustdoc/rustdoc_tests/clean_cfg.rs @@ -1,7 +1,7 @@ -use super::*; +use crate::clean::cfg::Cfg; use rustc_ast::attr; -use rustc_ast::Path; +use rustc_ast::{LitKind, MetaItem, MetaItemKind, NestedMetaItem, Path}; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::with_default_session_globals; use rustc_span::DUMMY_SP; diff --git a/src/librustdoc/doctest/tests.rs b/src/librustdoc/rustdoc_tests/doctest.rs similarity index 99% rename from src/librustdoc/doctest/tests.rs rename to src/librustdoc/rustdoc_tests/doctest.rs index a96186a95e16b..b27ce2d3501ba 100644 --- a/src/librustdoc/doctest/tests.rs +++ b/src/librustdoc/rustdoc_tests/doctest.rs @@ -1,5 +1,5 @@ -use super::{make_test, TestOptions}; use rustc_span::edition::DEFAULT_EDITION; +use crate::doctest::{make_test, TestOptions}; #[test] fn make_test_basic() { diff --git a/src/librustdoc/html/highlight/fixtures/sample.html b/src/librustdoc/rustdoc_tests/fixtures/sample.html similarity index 100% rename from src/librustdoc/html/highlight/fixtures/sample.html rename to src/librustdoc/rustdoc_tests/fixtures/sample.html diff --git a/src/librustdoc/html/highlight/fixtures/sample.rs b/src/librustdoc/rustdoc_tests/fixtures/sample.rs similarity index 100% rename from src/librustdoc/html/highlight/fixtures/sample.rs rename to src/librustdoc/rustdoc_tests/fixtures/sample.rs diff --git a/src/librustdoc/html/highlight/tests.rs b/src/librustdoc/rustdoc_tests/html_highlight.rs similarity index 94% rename from src/librustdoc/html/highlight/tests.rs rename to src/librustdoc/rustdoc_tests/html_highlight.rs index c79471b1fae6b..1de4c5805fbc2 100644 --- a/src/librustdoc/html/highlight/tests.rs +++ b/src/librustdoc/rustdoc_tests/html_highlight.rs @@ -1,5 +1,5 @@ -use super::write_code; use expect_test::expect_file; +use crate::html::highlight::write_code; #[test] fn test_html_highlighting() { diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/rustdoc_tests/html_markdown.rs similarity index 98% rename from src/librustdoc/html/markdown/tests.rs rename to src/librustdoc/rustdoc_tests/html_markdown.rs index 01a897c93db8d..c8ef420318dfe 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/rustdoc_tests/html_markdown.rs @@ -1,5 +1,5 @@ -use super::plain_summary_line; -use super::{ErrorCodes, IdMap, Ignore, LangString, Markdown, MarkdownHtml}; +use crate::html::markdown::plain_summary_line; +use crate::html::markdown::{ErrorCodes, IdMap, Ignore, LangString, Markdown, MarkdownHtml}; use rustc_span::edition::{Edition, DEFAULT_EDITION}; use std::cell::RefCell; diff --git a/src/librustdoc/html/render/tests.rs b/src/librustdoc/rustdoc_tests/html_render.rs similarity index 95% rename from src/librustdoc/html/render/tests.rs rename to src/librustdoc/rustdoc_tests/html_render.rs index abf5f05fe58ab..12a80a3e6017e 100644 --- a/src/librustdoc/html/render/tests.rs +++ b/src/librustdoc/rustdoc_tests/html_render.rs @@ -1,4 +1,5 @@ -use super::*; +use crate::html::render::compare_names; +use std::cmp::Ordering; #[test] fn test_compare_names() { diff --git a/src/librustdoc/html/toc/tests.rs b/src/librustdoc/rustdoc_tests/html_toc.rs similarity index 97% rename from src/librustdoc/html/toc/tests.rs rename to src/librustdoc/rustdoc_tests/html_toc.rs index 014f346862b3f..64f0f14f22d2d 100644 --- a/src/librustdoc/html/toc/tests.rs +++ b/src/librustdoc/rustdoc_tests/html_toc.rs @@ -1,4 +1,4 @@ -use super::{Toc, TocBuilder, TocEntry}; +use crate::html::toc::{Toc, TocBuilder, TocEntry}; #[test] fn builder_smoke() { diff --git a/src/librustdoc/rustdoc_tests/mod.rs b/src/librustdoc/rustdoc_tests/mod.rs new file mode 100644 index 0000000000000..4bf855ba896f8 --- /dev/null +++ b/src/librustdoc/rustdoc_tests/mod.rs @@ -0,0 +1,16 @@ +#[cfg(test)] +mod clean_cfg; +#[cfg(test)] +mod doctest; +#[cfg(test)] +mod html_highlight; +#[cfg(test)] +mod html_markdown; +#[cfg(test)] +mod html_render; +#[cfg(test)] +mod html_toc; +#[cfg(test)] +mod passes_unindent_comments; +#[cfg(test)] +mod theme; diff --git a/src/librustdoc/passes/unindent_comments/tests.rs b/src/librustdoc/rustdoc_tests/passes_unindent_comments.rs similarity index 97% rename from src/librustdoc/passes/unindent_comments/tests.rs rename to src/librustdoc/rustdoc_tests/passes_unindent_comments.rs index c39c03e1249c6..b7d976823ea27 100644 --- a/src/librustdoc/passes/unindent_comments/tests.rs +++ b/src/librustdoc/rustdoc_tests/passes_unindent_comments.rs @@ -1,4 +1,4 @@ -use super::*; +use crate::passes::unindent_comments::*; #[test] fn should_unindent() { diff --git a/src/librustdoc/theme/tests.rs b/src/librustdoc/rustdoc_tests/theme.rs similarity index 98% rename from src/librustdoc/theme/tests.rs rename to src/librustdoc/rustdoc_tests/theme.rs index b924215733d55..22c68811001c4 100644 --- a/src/librustdoc/theme/tests.rs +++ b/src/librustdoc/rustdoc_tests/theme.rs @@ -1,4 +1,4 @@ -use super::*; +use crate::theme::*; #[test] fn test_comments_in_rules() { diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index c8eb271c807d6..1d42d06965df3 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -5,9 +5,6 @@ use std::path::Path; use rustc_errors::Handler; -#[cfg(test)] -mod tests; - #[derive(Debug, Clone, Eq)] pub struct CssPath { pub name: String, @@ -43,14 +40,14 @@ impl Hash for CssPath { } impl CssPath { - fn new(name: String) -> CssPath { + pub fn new(name: String) -> CssPath { CssPath { name, children: FxHashSet::default() } } } /// All variants contain the position they occur. #[derive(Debug, Clone, Copy)] -enum Events { +pub enum Events { StartLineComment(usize), StartComment(usize), EndComment(usize), @@ -59,7 +56,7 @@ enum Events { } impl Events { - fn get_pos(&self) -> usize { + pub fn get_pos(&self) -> usize { match *self { Events::StartLineComment(p) | Events::StartComment(p) @@ -69,7 +66,7 @@ impl Events { } } - fn is_comment(&self) -> bool { + pub fn is_comment(&self) -> bool { match *self { Events::StartLineComment(_) | Events::StartComment(_) | Events::EndComment(_) => true, _ => false, @@ -88,7 +85,7 @@ fn is_line_comment(pos: usize, v: &[u8], events: &[Events]) -> bool { v[pos + 1] == b'/' } -fn load_css_events(v: &[u8]) -> Vec { +pub fn load_css_events(v: &[u8]) -> Vec { let mut pos = 0; let mut events = Vec::with_capacity(100);