Skip to content

Commit

Permalink
feature(doc_cfg): set cfg(rustdoc) when rustdoc is running
Browse files Browse the repository at this point in the history
  • Loading branch information
QuietMisdreavus committed Aug 31, 2018
1 parent ec4a752 commit 1a3bb27
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/librustdoc/lib.rs
Expand Up @@ -466,7 +466,8 @@ fn main_args(args: &[String]) -> isize {

let output = matches.opt_str("o").map(|s| PathBuf::from(&s));
let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
let cfgs = matches.opt_strs("cfg");
let mut cfgs = matches.opt_strs("cfg");
cfgs.push("rustdoc".to_string());

if let Some(ref p) = css_file_extension {
if !p.is_file() {
Expand Down Expand Up @@ -643,7 +644,8 @@ where R: 'static + Send,
for s in &matches.opt_strs("L") {
paths.add_path(s, ErrorOutputType::default());
}
let cfgs = matches.opt_strs("cfg");
let mut cfgs = matches.opt_strs("cfg");
cfgs.push("rustdoc".to_string());
let triple = matches.opt_str("target").map(|target| {
if target.ends_with(".json") {
TargetTriple::TargetPath(PathBuf::from(target))
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -1148,6 +1148,7 @@ const GATED_CFGS: &[(&str, &str, fn(&Features) -> bool)] = &[
("target_vendor", "cfg_target_vendor", cfg_fn!(cfg_target_vendor)),
("target_thread_local", "cfg_target_thread_local", cfg_fn!(cfg_target_thread_local)),
("target_has_atomic", "cfg_target_has_atomic", cfg_fn!(cfg_target_has_atomic)),
("rustdoc", "doc_cfg", cfg_fn!(doc_cfg)),
];

#[derive(Debug)]
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/feature-gate-doc_cfg-cfg-rustdoc.rs
@@ -0,0 +1,14 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[cfg(rustdoc)] //~ ERROR: `cfg(rustdoc)` is experimental and subject to change
pub struct SomeStruct;

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/feature-gate-doc_cfg-cfg-rustdoc.stderr
@@ -0,0 +1,11 @@
error[E0658]: `cfg(rustdoc)` is experimental and subject to change (see issue #43781)
--> $DIR/feature-gate-doc_cfg-cfg-rustdoc.rs:11:7
|
LL | #[cfg(rustdoc)] //~ ERROR: `cfg(rustdoc)` is experimental and subject to change
| ^^^^^^^
|
= help: add #![feature(doc_cfg)] to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.

0 comments on commit 1a3bb27

Please sign in to comment.