Skip to content

Remove whitespaces in doctests' name - #89422

Merged
bors merged 1 commit into
rust-lang:masterfrom
GuillaumeGomez:doctest-whitespace-name
Oct 2, 2021
Merged

Remove whitespaces in doctests' name#89422
bors merged 1 commit into
rust-lang:masterfrom
GuillaumeGomez:doctest-whitespace-name

Conversation

@GuillaumeGomez

@GuillaumeGomezGuillaumeGomez commented Oct 1, 2021

Copy link
Copy Markdown
Member

Fixes#88263.

Instead of handling white spaces when we filter tests (which would be quite complicated since we split on them!), I propose to instead replace them with dashes.

So for example, this:

test foo.rs - Iter2<T, P>::len (line 13) ... oktest foo.rs - Iter<T, P>::len (line 4) ... ok

becomes:

test foo.rs - Iter<T,-P>::len (line 4) ... oktest foo.rs - Iter2<T,-P>::len (line 13) ... ok

r? @jyn514

@GuillaumeGomezGuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-doctests Area: Documentation tests, run by rustdoc labels Oct 1, 2021
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @CraftSpider

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 1, 2021
@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

Failed the assignment...

r? @jyn514

@Urgau

Urgau commented Oct 1, 2021

Copy link
Copy Markdown
Member

Is it not possible to use a no-break space « » (ie U+00A0) instead of « - » ?
This would have the benefits of keeping the « same » visual appearance.

@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

If we do that, it's very likely that people will simply enter the name (with normal white space) and end up in the original issue.

@jyn514

Copy link
Copy Markdown
Member

r? @CraftSpider

I don't have time to review this.

@CraftSpider

Copy link
Copy Markdown
Contributor

I'm not sure the look with dashes is great, but I also agree that using no-break spaces is likely to lead people to the same issue.

Possible Alternative: How often do spaces show up, and where? If we're pretty sure spaces won't show up between identifiers, would it make sense to just strip them entirely? So we instead end up with Iter<T,P>::len, which while imperfect I think still looks a little better, and solves the issue.

@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

Great idea! I prefer this alternative much more! I'll update it then.

@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

Done!

@CraftSpider

Copy link
Copy Markdown
Contributor

Awesome, looks good to me
@bors r+

@bors

bors commented Oct 1, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 3792be6 has been approved by CraftSpider

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 1, 2021
@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

@bors rollup

@ManishearthManishearth mentioned this pull request Oct 1, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 1, 2021
…arth
Rollup of 7 pull requests
Successful merges:
- rust-lang#85223 (rustdoc: Clarified the attribute which prompts the warning)
- rust-lang#88847 (platform-support.md: correct ARMv7+MUSL platform triple notes)
- rust-lang#88963 (Coerce const FnDefs to implement const Fn traits )
- rust-lang#89376 (Fix use after drop in self-profile with llvm events)
- rust-lang#89422 (Replace whitespaces in doctests' name with dashes)
- rust-lang#89440 (Clarify a sentence in the documentation of Vec (rust-lang#84488))
- rust-lang#89441 (Normalize after substituting via `field.ty()`)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 04ba153 into rust-lang:masterOct 2, 2021
@rustbotrustbot added this to the 1.57.0 milestone Oct 2, 2021
@GuillaumeGomez
GuillaumeGomez deleted the doctest-whitespace-name branch October 2, 2021 09:35
@GuillaumeGomezGuillaumeGomez changed the title Replace whitespaces in doctests' name with dashesRemove whitespaces in doctests' nameOct 2, 2021
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 7, 2021
…arth
Rollup of 7 pull requests
Successful merges:
- rust-lang#85223 (rustdoc: Clarified the attribute which prompts the warning)
- rust-lang#88847 (platform-support.md: correct ARMv7+MUSL platform triple notes)
- rust-lang#88963 (Coerce const FnDefs to implement const Fn traits )
- rust-lang#89376 (Fix use after drop in self-profile with llvm events)
- rust-lang#89422 (Replace whitespaces in doctests' name with dashes)
- rust-lang#89440 (Clarify a sentence in the documentation of Vec (rust-lang#84488))
- rust-lang#89441 (Normalize after substituting via `field.ty()`)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang/rust-analyzer that referenced this pull request Aug 1, 2022
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 rust-lang/rust#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.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-doctestsArea: Documentation tests, run by rustdocS-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustdoc does not filter correctly doctests when their name contain spaces.

7 participants

@GuillaumeGomez@rust-highfive@Urgau@jyn514@CraftSpider@bors@rustbot