about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-07 17:00:18 +0200
committerGitHub <noreply@github.com>2019-07-07 17:00:18 +0200
commitfe807fcf3e8c76fc54c19a1bb0570579a4ecfe95 (patch)
tree2d5ad6ab6c856ef8f112b5e957cd0f323829f807 /src/test/ui
parent3250b8ee596afc9881aee092279efaa57486d2ea (diff)
parentcff6ce667fd8c5002f789a55f75ba70b67be42f7 (diff)
Rollup merge of #62213 - QuietMisdreavus:cfg-doctest, r=GuillaumeGomez
rustdoc: set cfg(doctest) when collecting doctests

Note: This PR builds on top of https://github.com/rust-lang/rust/pull/61199; only the last commit is specific to this PR.

As discussed in https://github.com/rust-lang/rust/pull/61199, we want the ability to isolate items to only when rustdoc is collecting doctests, but we can't use `cfg(test)` because of libcore's `#![cfg(not(test))]`. This PR proposes a new cfg flag, `cfg(doctest)`, specific to this situation, rather than reusing an existing flag. I've isolated it behind a feature gate so that we can contain the effects to nightly only. (A stable workaround that can be used in lieu of `#[cfg(doctest)]` is `#[cfg(rustdoc)] #[doc(hidden)]`, at least once https://github.com/rust-lang/rust/pull/61351 lands.)

Tracking issue: https://github.com/rust-lang/rust/issues/62210
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/feature-gate/feature-gate-cfg_doctest.rs4
-rw-r--r--src/test/ui/feature-gate/feature-gate-cfg_doctest.stderr12
2 files changed, 16 insertions, 0 deletions
diff --git a/src/test/ui/feature-gate/feature-gate-cfg_doctest.rs b/src/test/ui/feature-gate/feature-gate-cfg_doctest.rs
new file mode 100644
index 00000000000..308f68bd52a
--- /dev/null
+++ b/src/test/ui/feature-gate/feature-gate-cfg_doctest.rs
@@ -0,0 +1,4 @@
+#[cfg(doctest)] //~ ERROR
+pub struct SomeStruct;
+
+fn main() {}
diff --git a/src/test/ui/feature-gate/feature-gate-cfg_doctest.stderr b/src/test/ui/feature-gate/feature-gate-cfg_doctest.stderr
new file mode 100644
index 00000000000..aa1d18a6f75
--- /dev/null
+++ b/src/test/ui/feature-gate/feature-gate-cfg_doctest.stderr
@@ -0,0 +1,12 @@
+error[E0658]: `cfg(doctest)` is experimental and subject to change
+  --> $DIR/feature-gate-cfg_doctest.rs:1:7
+   |
+LL | #[cfg(doctest)]
+   |       ^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/62210
+   = help: add #![feature(cfg_doctest)] to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.