Skip to content

Change in resolution of relative paths in doctest included with #[doc = include_str(...)] in 1.83.0 #133824

@andrewhickman

Description

@andrewhickman
Contributor

When using attribute an attribute like #[doc = include_str("../doc/docs.md")] to include documentation from a file, if the file contains doctests, the resolution of relative paths in the test at compile time has changed. For example, if doc/docs.md uses include_bytes!, previously the path would need to be relative to the file containing #[doc], but in 1.82.0, it is relative to docs/docs.md.

This is easily worked around by using absolute paths like concat!(env!("CARGO_MANIFEST_DIR"), "/src/foo"), and I don't know if this behaviour is actually defined anywhere, but I thought I'd report it anyway.

Code

A minimal reproduction of this issue is here: https://github.com/andrewhickman/doctestissue. The doctest in this repo passes in 1.82.0 but fails to compile in 1.83.0 with

> cargo test --doc
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.01s
   Doc-tests doctestissue

running 1 test
test src\../doc/docs.md - (line 3) ... FAILED

failures:

---- src\../doc/docs.md - (line 3) stdout ----
error: couldn't read `src\../doc\foo`: The system cannot find the file specified. (os error 2)
 --> src\../doc/docs.md:4:12
  |
3 | assert_eq!(include_bytes!("foo"), &[]);
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
    src\../doc/docs.md - (line 3)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s

error: doctest failed, to rerun pass `--doc`

Version it worked on

Rust 1.82.0 runs the doctest in the reproduction successfully

Version with regression

rustc --version --verbose:

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-pc-windows-msvc
release: 1.83.0
LLVM version: 19.1.1

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Dec 3, 2024
added 2 commits that reference this issue on Dec 3, 2024
added
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on Dec 3, 2024
added
A-attributesArea: Attributes (`#[…]`, `#![…]`)
A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
and removed
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on Dec 3, 2024
jieyouxu

jieyouxu commented on Dec 3, 2024

@jieyouxu
Member

(Sorry label raced)

added
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
and removed
A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Dec 3, 2024
fmease

fmease commented on Dec 3, 2024

@fmease
Member

I think this is #130582 (likely "regressor"). If so, this should be fixed in 1.84 via #132210.

added
A-doctestsArea: Documentation tests, run by rustdoc
on Dec 3, 2024
removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Dec 3, 2024
fmease

fmease commented on Dec 3, 2024

@fmease
Member

After manual checkout: Indeed, fixed on beta (1.84). Sorry for the inconvenience.

added
regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
and removed
regression-untriagedUntriaged performance or correctness regression.
on Dec 3, 2024
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Dec 3, 2024
removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-doctestsArea: Documentation tests, run by rustdocC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @fmease@andrewhickman@jieyouxu@rustbot

        Issue actions

          Change in resolution of relative paths in doctest included with #[doc = include_str(...)] in 1.83.0 · Issue #133824 · rust-lang/rust