Skip to content

Commit 1a3bb27

Browse files
feature(doc_cfg): set cfg(rustdoc) when rustdoc is running
1 parent ec4a752 commit 1a3bb27

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

Diff for: src/librustdoc/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ fn main_args(args: &[String]) -> isize {
466466

467467
let output = matches.opt_str("o").map(|s| PathBuf::from(&s));
468468
let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
469-
let cfgs = matches.opt_strs("cfg");
469+
let mut cfgs = matches.opt_strs("cfg");
470+
cfgs.push("rustdoc".to_string());
470471

471472
if let Some(ref p) = css_file_extension {
472473
if !p.is_file() {
@@ -643,7 +644,8 @@ where R: 'static + Send,
643644
for s in &matches.opt_strs("L") {
644645
paths.add_path(s, ErrorOutputType::default());
645646
}
646-
let cfgs = matches.opt_strs("cfg");
647+
let mut cfgs = matches.opt_strs("cfg");
648+
cfgs.push("rustdoc".to_string());
647649
let triple = matches.opt_str("target").map(|target| {
648650
if target.ends_with(".json") {
649651
TargetTriple::TargetPath(PathBuf::from(target))

Diff for: src/libsyntax/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ const GATED_CFGS: &[(&str, &str, fn(&Features) -> bool)] = &[
11481148
("target_vendor", "cfg_target_vendor", cfg_fn!(cfg_target_vendor)),
11491149
("target_thread_local", "cfg_target_thread_local", cfg_fn!(cfg_target_thread_local)),
11501150
("target_has_atomic", "cfg_target_has_atomic", cfg_fn!(cfg_target_has_atomic)),
1151+
("rustdoc", "doc_cfg", cfg_fn!(doc_cfg)),
11511152
];
11521153

11531154
#[derive(Debug)]

Diff for: src/test/ui/feature-gate-doc_cfg-cfg-rustdoc.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[cfg(rustdoc)] //~ ERROR: `cfg(rustdoc)` is experimental and subject to change
12+
pub struct SomeStruct;
13+
14+
fn main() {}

Diff for: src/test/ui/feature-gate-doc_cfg-cfg-rustdoc.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0658]: `cfg(rustdoc)` is experimental and subject to change (see issue #43781)
2+
--> $DIR/feature-gate-doc_cfg-cfg-rustdoc.rs:11:7
3+
|
4+
LL | #[cfg(rustdoc)] //~ ERROR: `cfg(rustdoc)` is experimental and subject to change
5+
| ^^^^^^^
6+
|
7+
= help: add #![feature(doc_cfg)] to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)