Skip to content

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

Closed
@tspiteri

Description

@tspiteri

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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions