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

doc test that should not compile still fails compile_fail test #67771

Closed
tspiteri opened this issue Jan 1, 2020 · 1 comment · Fixed by #68664
Closed

doc test that should not compile still fails compile_fail test #67771

tspiteri opened this issue Jan 1, 2020 · 1 comment · Fixed by #68664
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@tspiteri
Copy link
Contributor

tspiteri commented Jan 1, 2020

The below code (in cf/lib.rs) has three doc tests:

  1. The first succeeds as expected.
  2. The second test fails as expected: the constant M would be 6 - 8 and there is an attempt to subtract with overflow.
  3. The third test should succeed as it has the exact same code as the second test but is marked as compile_fail. However the test fails with the message “Test compiled successfully, but it's marked compile_fail.”
use std::marker::PhantomData;
use std::mem;

/// This test succeeds as expected:
///
/// ```rust
/// let works = cf::S::<u32>::default();
/// works.foo();
/// ```
///
/// This test fails as expected, as it fails to compile:
///
/// ```rust
/// let should_fail = cf::S::<u64>::default();
/// should_fail.foo();
/// ```
///
/// This test should succeed, but fails with “Test compiled
/// successfully, but it's marked `compile_fail`.”:
///
/// ```compile_fail
/// let should_fail = cf::S::<u64>::default();
/// should_fail.foo();
/// ```
#[derive(Default)]
pub struct S<T>(PhantomData<T>);

impl<T> S<T> {
    const M: usize = 6 - mem::size_of::<T>();
    pub fn foo(&self) {
        let _ = Self::M;
    }
}
@jonas-schievink jonas-schievink added A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 1, 2020
@ehuss
Copy link
Contributor

ehuss commented Jan 1, 2020

This is a consequence of how compile_fail works. compile_fail (and no_run) does the equivalent of --emit=rmeta (or the same as cargo check), which does not perform all steps of compilation (like codegen and linking). One of the issues tracking this problem is #49292.

I'm not sure why rustdoc does not perform the full compilation steps for compile_fail and no_run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants