Closed
Description
The below code (in cf/lib.rs) has three doc tests:
- The first succeeds as expected.
- The second test fails as expected: the constant
M
would be6 - 8
and there is an attempt to subtract with overflow. - 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 markedcompile_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;
}
}