Doc tests never run under release mode

I have a library that really needs optimizations turned on to run efficiently. Hence, in CI I always run cargo test --release. I noticed that a doc test takes over a minute to run when the same test completes in under a second when run outside of a doc example.

However, doc tests always seem to run in debug mode as confirmed by this playground snippet. If you run the tests in debug mode, the non-doc test will panic. However, if you run in release mode, the same test put in a doc comment will panic while the non-doc test passes. Is this expected?

1 Like

-Copt-level is ignored by rustdoc. The full set of arguments that rustdoc passes to rustc for compiling doc tests can be found at

3 Likes

Is this an oversight or intentional design? Naively, I'd expect to run doc tests with the same profile settings as my application tests.

4 Likes

This is a reasonable expectation. File a bug.

2 Likes

Filed. doctest doesn't run under the same profile as the rest of the tests · Issue #139603 · rust-lang/rust · GitHub