about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-09-28 05:50:00 +0000
committerbors <bors@rust-lang.org>2021-09-28 05:50:00 +0000
commit7b10746ef08041885989eccd2dd6cd3c2f6f0f49 (patch)
tree1c14455b39e32a2cbcc97422919f847c8f2352e1 /src/test
parent8a12be741290b16c29293f87bdb3e8e5129bd4a9 (diff)
parent6f087aedb60ccbed0e1ee05256100e2f80e45f2f (diff)
Auto merge of #89277 - jyn514:codeblock-edition, r=GuillaumeGomez
Use the correct edition for syntax highlighting doctests

Previously it would unconditionally use edition 2015, which was incorrect.

Helps with https://github.com/rust-lang/rust/issues/89135 in that you can now override the doctest to be 2018 edition instead of being forced to fix the error. This doesn't resolve any of the deeper problems that rustdoc disagrees with most rust users on what a code block is.

cc `@Mark-Simulacrum`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/rustdoc-ui/doctest-edition.rs16
-rw-r--r--src/test/rustdoc-ui/doctest-edition.stderr22
2 files changed, 38 insertions, 0 deletions
diff --git a/src/test/rustdoc-ui/doctest-edition.rs b/src/test/rustdoc-ui/doctest-edition.rs
new file mode 100644
index 00000000000..b0787be972f
--- /dev/null
+++ b/src/test/rustdoc-ui/doctest-edition.rs
@@ -0,0 +1,16 @@
+// edition:2021
+
+#![deny(rustdoc::invalid_rust_codeblocks)]
+//~^ NOTE lint level is defined here
+
+// By default, rustdoc should use the edition of the crate.
+//! ```
+//! foo'b'
+//! ```
+//~^^^ ERROR could not parse
+//~| NOTE prefix `foo` is unknown
+
+// Rustdoc should respect `edition2018` when highlighting syntax.
+//! ```edition2018
+//! foo'b'
+//! ```
diff --git a/src/test/rustdoc-ui/doctest-edition.stderr b/src/test/rustdoc-ui/doctest-edition.stderr
new file mode 100644
index 00000000000..1643d605375
--- /dev/null
+++ b/src/test/rustdoc-ui/doctest-edition.stderr
@@ -0,0 +1,22 @@
+error: could not parse code block as Rust code
+  --> $DIR/doctest-edition.rs:7:5
+   |
+LL |   //! ```
+   |  _____^
+LL | | //! foo'b'
+LL | | //! ```
+   | |_______^
+   |
+note: the lint level is defined here
+  --> $DIR/doctest-edition.rs:3:9
+   |
+LL | #![deny(rustdoc::invalid_rust_codeblocks)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = note: error from rustc: prefix `foo` is unknown
+help: mark blocks that do not contain Rust code as text
+   |
+LL | //! ```text
+   |        ++++
+
+error: aborting due to previous error
+