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

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

Closed
andrewhickman opened this issue Dec 3, 2024 · 3 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@andrewhickman
Copy link
Contributor

andrewhickman commented Dec 3, 2024

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
@andrewhickman andrewhickman added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Dec 3, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 3, 2024
andrewhickman added a commit to andrewhickman/prost-reflect that referenced this issue Dec 3, 2024
andrewhickman added a commit to andrewhickman/prost-reflect that referenced this issue Dec 3, 2024
* Fix lints

* Fix lint

* Correct MSRV in README to match value in changelog, CI and Cargo.toml

* Update dependencies

* Fix build in 1.83.0

Workaround for rust-lang/rust#133824
@fmease fmease added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 3, 2024
@jieyouxu jieyouxu added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Dec 3, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 3, 2024

(Sorry label raced)

@fmease fmease added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 3, 2024
@fmease
Copy link
Member

fmease commented Dec 3, 2024

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

@fmease fmease added the A-doctests Area: Documentation tests, run by rustdoc label Dec 3, 2024
@jieyouxu jieyouxu removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 3, 2024
@fmease
Copy link
Member

fmease commented Dec 3, 2024

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

@fmease fmease closed this as completed Dec 3, 2024
@fmease fmease added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-untriaged Untriaged performance or correctness regression. labels Dec 3, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 3, 2024
@fmease fmease removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 3, 2024
@fmease fmease closed this as completed Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Development

No branches or pull requests

4 participants