Fully qualify Result in generated doctest code by GuillaumeGomez · Pull Request #137807 · rust-lang/rust (original) (raw)

…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 guillaume1.gomez@gmail.com