book
book copied to clipboard
mdbook test fails with "error[E0463]: can't find crate for trpl"
- I have searched open and closed issues and pull requests for duplicates, using these search terms:
- trpl
URL to the section(s) of the book with this problem: https://github.com/rust-lang/book/blob/main/README.md
Description of the problem:
I followed the instructions on a local git-cloned copy of the book. After following instructions to install mdbook & mdbook-trpl, I ran mdbook test and encountered a number of errors to the effect of:
error[E0463]: can't find crate for `trpl`
--> <chapter>.md:<line>:<position>
|
2 | extern crate trpl; // for mdbook test
| ^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to 1 previous error
Not sure why I'm running into this error. Either I'm actually missing a crate (so installation instructions should be added to the README), or there's an error in the software.
On macOS ~~there was a simple fix.~~
❯ cd packages/trpl
❯ mdbook test --library-path packages/trpl/target/debug/deps
2025-06-30 10:09:36 [ERROR] (mdbook::utils): Error: Couldn't open SUMMARY.md in "/Users/nathany/Development/rust/books/the-rust-programming-language-manuscript/packages/trpl/src" directory
2025-06-30 10:09:36 [ERROR] (mdbook::utils): Caused By: No such file or directory (os error 2)
But if I run it from the book folder on macOS (no change directory #4426), it runs fine ~~and all the tests pass.~~ Update: the tests fail on macOS too, I was just multi-tasking when the failures scrolled by.
On Windows 11 it's ~~a different~~ the same story. Testing in Git Bash from the packages/trpl folder is basically the same error
nathany@Owl MINGW64 ~/src/github.com/rust-lang/book/packages/trpl (readme-mdbook)
$ mdbook test --library-path packages/trpl/target/debug/deps
2025-06-30 14:16:47 [ERROR] (mdbook::utils): Error: Couldn't open SUMMARY.md in "C:\\Users\\nathany\\src\\github.com\\rust-lang\\book\\packages\\trpl\\src" directory
2025-06-30 14:16:47 [ERROR] (mdbook::utils): Caused By: The system cannot find the file specified. (os error 2)
Running from the book/ folder gets through chapters 1-16, but then fails on chapter 17 with the errors @bordenc mentioned.
2025-06-30 14:18:37 [INFO] (mdbook::book): Testing chapter 'Futures and the Async Syntax': "ch17-01-futures-and-syntax.md"
2025-06-30 14:18:38 [ERROR] (mdbook::book): rustdoc returned an error:
--- stdout
running 8 tests
test ch17-01-futures-and-syntax.md - _::Determining_a_Single_Page_s_Title (line 243) ... ignored
test ch17-01-futures-and-syntax.md - _::Determining_a_Single_Page_s_Title (line 376) ... FAILED
test ch17-01-futures-and-syntax.md - _::Determining_a_Single_Page_s_Title (line 319) ... FAILED
test ch17-01-futures-and-syntax.md - _::Our_First_Async_Program::Defining_the_page_title_Function (line 162) ... FAILED
test ch17-01-futures-and-syntax.md - _::Our_First_Async_Program::Defining_the_page_title_Function (line 197) ... FAILED
test ch17-01-futures-and-syntax.md - _::Our_First_Async_Program::Defining_the_page_title_Function (line 84) ... FAILED
test ch17-01-futures-and-syntax.md - _::Determining_a_Single_Page_s_Title::Racing_Our_Two_URLs_Against_Each_Other (line 428) ... FAILED
test ch17-01-futures-and-syntax.md - _::Determining_a_Single_Page_s_Title::Racing_Our_Two_URLs_Against_Each_Other (line 490) ... ok
failures:
---- ch17-01-futures-and-syntax.md - _::Determining_a_Single_Page_s_Title (line 376) stdout ----
error[E0463]: can't find crate for `trpl`
--> ch17-01-futures-and-syntax.md:376:1
|
2 | extern crate trpl;
| ^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0463`.
Couldn't compile the test.
~~The CI actions only run on ubuntu-latest, so I'm not sure if there's something different on Windows.~~
The same errors occur in Powershell.
For further clarity, I'm getting the error on Debian Trixie, so this bug has officially scored the OS hat trick.
I think it's not OS-specific -- I was wrong about it passing on macOS in my original post. (Updated)
It looks like trpl is a support crate for the book, so hopefully there isn't anything wrong with Chapter 17 itself.
GitHub Actions is passing, so that provides a clue. From https://github.com/rust-lang/book/blob/main/.github/workflows/main.yml
# mdBook does not currently have particularly good support for “external”
# crates. To make the test suite work correctly with `trpl`, we must first
# build `trpl` itself (`mdbook` will not do it), and then explicitly pass
# its `deps` path as a library search path for `mdbook test`. That will make
# sure all the crates can be resolved when running the tests.
- name: Build `trpl` crate
run: |
cd packages/trpl
cargo build
- name: Run tests
run:
mdbook test --library-path packages/trpl/target/debug/deps
I built the trpl crate successfully, but when I back out of the folder and run the tests, it is still failing locally with the same errors. 🤷♂
At least it works in CI.