]> git.lizzy.rs Git - rust.git/commit
Auto merge of #12918 - lowr:fix/doctest-names, r=Veykril
authorbors <bors@rust-lang.org>
Mon, 1 Aug 2022 10:12:59 +0000 (10:12 +0000)
committerbors <bors@rust-lang.org>
Mon, 1 Aug 2022 10:12:59 +0000 (10:12 +0000)
commit5edbdd127a59ed79bf9381a4005efb4e7bcb262b
tree7f3791792d821678780cd0bfa3c6a8abd1bb64ed
parent2b472f6684bb1958274995d12b2c50310d88cc52
parentd40ab66186fa477177a10d01eb16960a5f20c7ac
Auto merge of #12918 - lowr:fix/doctest-names, r=Veykril

fix: remove whitespaces from doctest names

When rustdoc runs doctests, it removes whitespaces from the tests' path ([code](https://github.com/rust-lang/rust/blob/25bb1c13bd472b75ceebee3b8dcf4dcbc431a8be/src/librustdoc/doctest.rs#L951)). See https://github.com/rust-lang/rust/pull/89422 for details.

Interestingly enough, "Run doctest" has been working without much problem even though rust-analyzer hasn't followed the change. This is because cargo passes the test name to rustdoc via `--test-args` option, and then rustdoc [splits it by whitespace](https://github.com/rust-lang/rust/blob/25bb1c13bd472b75ceebee3b8dcf4dcbc431a8be/src/librustdoc/config.rs#L513-L514); the last element of the split test name **always** matches the test name that rustdoc generates.

However, it may run other tests unexpectedly (to be precise, this has long since been a thing because of the split). Consider the following example:

```rust
struct A<T, U>(T, U);
struct B<T, U>(T, U);
/// ```
/// doctest here
/// ```
impl<T, U> A<T, U> {}
/// ```
/// doctest here
/// ```
impl<T, U> B<T, U> {}
```

When you "Run doctest" either of the two, rustdoc considers "U>" one of the test specs and both doctests are run. This patch fixes it by following rustdoc and removing the whitespace from the doctests' name.