Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully qualify Result in generated doctest code #137807

Merged
merged 1 commit into from
Mar 2, 2025

Conversation

GuillaumeGomez
Copy link
Member

As discussed in https://lore.kernel.org/rust-for-linux/[email protected]/T/#u, it would require less code for RfL to be able to reach the same result (pun unintended).

cc @ojeda

r? @notriddle

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 28, 2025
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this pull request Feb 28, 2025
…e doctest handling.

Thanks for the detailed answer!

I added the missing "Signed-of-by" in the commit message.

I added some more context in the commit message, hopefully I didn't
miss anything.

> We currently support versions 1.78+, so we will need to do these
> things conditionally. I can help with that, so don't worry too much
> about it for the moment (e.g. we have `rustc-option` and other helpers
> to pick the right flags given a version etc.).

I'll definitely need some help here. I'm not sure current stable already
has this change so until then, we'll need a beta/nightly version to run
these tests.

> Hmm... I was hoping we could do something on the `rustdoc` side to
> remove these hacks altogether since we are going to have a "proper
> flag" for it, i.e. to avoid relying on the particular "format" of the
> tests somehow.

I opened rust-lang/rust#137807 to resolve
this problem.

> > +    let doctest_code = doctest_code.replace(
> > +        "} _inner().unwrap() }",
> > +        "} let test_return_value = _inner(); assert!(test_return_value.is_ok()); }",
> >      );
> > +    std::fs::write(path, doctest_code.as_bytes()).unwrap();
> > +}
>
> Same for this.

For this one I'll need to check first if it can be done "safely" (ie,
so unexpected side
effect).

> > +    } else {
> > +        panic!("missing `format_version` field");
> > +    }
>
> `expect` maybe?

I don't think `expect` would work in any of the cases in this file.
What I suggest
is to add methods on `JsonValue` in a future patch which would allow to reduce
code in this file (and call `expect` too).

> These two bits could go in a first patch, I think, though it isn't a big deal.

You're absolutely right, removing them and sending a separate patch.

Here is the updated patch:

The goal of this patch is to remove the use of 2 unstable rustdoc features
(`--no-run` and `--test-builder`) and replace it with a stable feature:
`--output-format=doctest`, which was added in
rust-lang/rust#134531.

Before this patch, the code was using very hacky methods in order to retrieve
doctests, modify them as needed and then concatenate all of them in one file.

Now, with this new flag, it instead asks rustdoc to provide the doctests
code with their associated information such as file path and line number.

Signed-off-by: Guillaume Gomez <[email protected]>
@notriddle
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 28, 2025

📌 Commit c86a7ef has been approved by notriddle

It is now in the queue for this repository.

@bors bors 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 Feb 28, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 1, 2025
…ult, r=notriddle

Fully qualify `Result` in generated doctest code

As discussed in https://lore.kernel.org/rust-for-linux/[email protected]/T/#u, it would require less code for RfL to be able to reach the same result (pun unintended).

cc `@ojeda`

r? `@notriddle`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 1, 2025
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#137804 (rename BackendRepr::Vector → SimdVector)
 - rust-lang#137807 (Fully qualify `Result` in generated doctest code)
 - rust-lang#137809 (Use correct error message casing for `io::const_error`s)
 - rust-lang#137818 (tests: adapt for LLVM 21 changes)
 - rust-lang#137822 (Update query normalizer docs to not position it as the greatest pioneer in the space of normalization)
 - rust-lang#137824 (Tweak invalid RTN errors)
 - rust-lang#137828 (Fix inaccurate `std::intrinsics::simd` documentation)
 - rust-lang#137830 (Fix link failure on AVR (incompatible ISA error))
 - rust-lang#137837 (Update `const_conditions` and `explicit_implied_const_bounds` docs)
 - rust-lang#137840 (triagebot: only ping me for constck)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 2, 2025
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#137804 (rename BackendRepr::Vector → SimdVector)
 - rust-lang#137807 (Fully qualify `Result` in generated doctest code)
 - rust-lang#137809 (Use correct error message casing for `io::const_error`s)
 - rust-lang#137818 (tests: adapt for LLVM 21 changes)
 - rust-lang#137822 (Update query normalizer docs to not position it as the greatest pioneer in the space of normalization)
 - rust-lang#137824 (Tweak invalid RTN errors)
 - rust-lang#137828 (Fix inaccurate `std::intrinsics::simd` documentation)
 - rust-lang#137830 (Fix link failure on AVR (incompatible ISA error))
 - rust-lang#137837 (Update `const_conditions` and `explicit_implied_const_bounds` docs)
 - rust-lang#137840 (triagebot: only ping me for constck)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 643c19c into rust-lang:master Mar 2, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 2, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 2, 2025
Rollup merge of rust-lang#137807 - GuillaumeGomez:doctest-qualify-result, r=notriddle

Fully qualify `Result` in generated doctest code

As discussed in https://lore.kernel.org/rust-for-linux/[email protected]/T/#u, it would require less code for RfL to be able to reach the same result (pun unintended).

cc ``@ojeda``

r? ``@notriddle``
@GuillaumeGomez GuillaumeGomez deleted the doctest-qualify-result branch March 2, 2025 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant 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.

4 participants