From 445e7350f2a0a776b541ddca7b028a804639b40f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 25 Sep 2019 17:08:40 +0200 Subject: [PATCH 1/2] Prevent rustdoc feature to be passed down to doctests --- src/librustdoc/config.rs | 1 - src/librustdoc/core.rs | 5 ++++- src/librustdoc/test.rs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 19ea7814300..fe4e2bd0915 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -344,7 +344,6 @@ impl Options { .map(|s| PathBuf::from(&s)) .unwrap_or_else(|| PathBuf::from("doc")); let mut cfgs = matches.opt_strs("cfg"); - cfgs.push("rustdoc".to_string()); if should_test { cfgs.push("doctest".to_string()); } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 010e4cf6cd0..00265caa965 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -234,7 +234,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt error_format, libs, externs, - cfgs, + mut cfgs, codegen_options, debugging_options, target, @@ -250,6 +250,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt .. } = options; + // Add the rustdoc cfg into the doc build. + cfgs.push("rustdoc".to_string()); + let cpath = Some(input.clone()); let input = Input::File(input); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 6576165b6ce..3e77ca47e8a 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -62,9 +62,11 @@ pub fn run(options: Options) -> i32 { ..config::Options::default() }; + let mut cfgs = options.cfgs.clone(); + cfgs.push("rustdoc".to_owned()); let config = interface::Config { opts: sessopts, - crate_cfg: config::parse_cfgspecs(options.cfgs.clone()), + crate_cfg: config::parse_cfgspecs(cfgs), input, input_path: None, output_file: None, From 366fdebff8dc6259c67206f78d53f1b1d64854ab Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 30 Sep 2019 16:19:08 +0200 Subject: [PATCH 2/2] Add new rustdoc-ui test to ensuire that rustdoc feature isn't passed down to doctests --- src/test/rustdoc-ui/doc-test-rustdoc-feature.rs | 14 ++++++++++++++ .../rustdoc-ui/doc-test-rustdoc-feature.stdout | 6 ++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/rustdoc-ui/doc-test-rustdoc-feature.rs create mode 100644 src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout diff --git a/src/test/rustdoc-ui/doc-test-rustdoc-feature.rs b/src/test/rustdoc-ui/doc-test-rustdoc-feature.rs new file mode 100644 index 00000000000..d0ead413657 --- /dev/null +++ b/src/test/rustdoc-ui/doc-test-rustdoc-feature.rs @@ -0,0 +1,14 @@ +// build-pass +// compile-flags:--test +// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" + +#![feature(doc_cfg)] + +// Make sure `cfg(rustdoc)` is set when finding doctests but not inside the doctests. + +/// ``` +/// #![feature(doc_cfg)] +/// assert!(!cfg!(rustdoc)); +/// ``` +#[cfg(rustdoc)] +pub struct Foo; diff --git a/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout b/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout new file mode 100644 index 00000000000..f2525c2dbec --- /dev/null +++ b/src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/doc-test-rustdoc-feature.rs - Foo (line 9) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out +