Skip to content

Commit 69837b1

Browse files
authored
Rollup merge of rust-lang#64741 - GuillaumeGomez:prevent-rustdoc-feature-doctests, r=QuietMisdreavus
Prevent rustdoc feature doctests Part of rust-lang#61351 cc @ollie27
2 parents c6999a5 + 366fdeb commit 69837b1

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

src/librustdoc/config.rs

-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ impl Options {
344344
.map(|s| PathBuf::from(&s))
345345
.unwrap_or_else(|| PathBuf::from("doc"));
346346
let mut cfgs = matches.opt_strs("cfg");
347-
cfgs.push("rustdoc".to_string());
348347
if should_test {
349348
cfgs.push("doctest".to_string());
350349
}

src/librustdoc/core.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
234234
error_format,
235235
libs,
236236
externs,
237-
cfgs,
237+
mut cfgs,
238238
codegen_options,
239239
debugging_options,
240240
target,
@@ -250,6 +250,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
250250
..
251251
} = options;
252252

253+
// Add the rustdoc cfg into the doc build.
254+
cfgs.push("rustdoc".to_string());
255+
253256
let cpath = Some(input.clone());
254257
let input = Input::File(input);
255258

src/librustdoc/test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ pub fn run(options: Options) -> i32 {
6262
..config::Options::default()
6363
};
6464

65+
let mut cfgs = options.cfgs.clone();
66+
cfgs.push("rustdoc".to_owned());
6567
let config = interface::Config {
6668
opts: sessopts,
67-
crate_cfg: config::parse_cfgspecs(options.cfgs.clone()),
69+
crate_cfg: config::parse_cfgspecs(cfgs),
6870
input,
6971
input_path: None,
7072
output_file: None,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// build-pass
2+
// compile-flags:--test
3+
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
4+
5+
#![feature(doc_cfg)]
6+
7+
// Make sure `cfg(rustdoc)` is set when finding doctests but not inside the doctests.
8+
9+
/// ```
10+
/// #![feature(doc_cfg)]
11+
/// assert!(!cfg!(rustdoc));
12+
/// ```
13+
#[cfg(rustdoc)]
14+
pub struct Foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
running 1 test
3+
test $DIR/doc-test-rustdoc-feature.rs - Foo (line 9) ... ok
4+
5+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
6+

0 commit comments

Comments
 (0)