Skip to content

Commit

Permalink
Rollup merge of rust-lang#64741 - GuillaumeGomez:prevent-rustdoc-feat…
Browse files Browse the repository at this point in the history
…ure-doctests, r=QuietMisdreavus

Prevent rustdoc feature doctests

Part of rust-lang#61351

cc @ollie27
  • Loading branch information
Centril authored Oct 3, 2019
2 parents ac937bc + 366fdeb commit d7a4f9d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions src/test/rustdoc-ui/doc-test-rustdoc-feature.rs
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 6 additions & 0 deletions src/test/rustdoc-ui/doc-test-rustdoc-feature.stdout
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d7a4f9d

Please sign in to comment.