You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using std::arch::is_<arch>_feature_detected!("feature") + #[target_feature = "feature"] doesn't work in doctests:
/// ```/// let result = miri_doctest::add(2, 2);/// assert_eq!(result, 4);/// ```pubfnadd(left:u64,right:u64) -> u64{if !std::arch::is_x86_feature_detected!("ssse3"){panic!("SSSE3 is not supported");}unsafe{add_with_ssse3(left, right)}}#[target_feature(enable = "ssse3")]pubunsafefnadd_with_ssse3(left:u64,right:u64) -> u64{
left + right
}#[cfg(test)]mod tests {usesuper::*;#[test]fnit_works(){let result = add(2,2);assert_eq!(result,4);}}
The #[test]it_works works fine, but the add doctest doesn't; looks like the is_feature_detected call returns true but Miri still errors out:
$ RUSTFLAGS=-Ctarget-feature=+ssse3 cargo miri test --target x86_64-unknown-linux-gnu
Compiling miri-doctest v0.1.0 (/tmp/miri-doctest)
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.08s
Running unittests src/lib.rs (target/miri/x86_64-unknown-linux-gnu/debug/deps/miri_doctest-0d5da2e0254807af)
running 1 testtest tests::it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.17s
Doc-tests miri_doctest
running 1 testtest src/lib.rs - add (line 1) ... FAILED
failures:
---- src/lib.rs - add (line 1) stdout ----
Test executable failed (exit status: 1).
stderr:
error: Undefined Behavior: calling a functionthat requires unavailable target features: ssse3
--> /tmp/miri-doctest/src/lib.rs:9:14
|
9 | unsafe { add_with_ssse3(left, right) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a functionthat requires unavailable target features: ssse3
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `miri_doctest::add` at /tmp/miri-doctest/src/lib.rs:9:14: 9:41
note: inside `main::_doctest_main_src_lib_rs_1_0`
--> src/lib.rs:3:14
|
5 |let result = miri_doctest::add(2, 2);| ^^^^^^^^^^^^^^^^^^^^^^^
note: inside `main`
--> src/lib.rs:5:3
|
7 | } _doctest_main_src_lib_rs_1_0() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full`for a verbose backtrace
error: aborting due to 1 previous error
failures:
src/lib.rs - add (line 1)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.08s
error: doctest failed, to rerun pass `--doc`
The text was updated successfully, but these errors were encountered:
I do not know why rustdoc behaves like this, but I suspect there was a good reason for it at some point. If you figure out the reason, don't hesitate to give a shout on this issue, it's probably buried in the rust-lang/rust issue tracker.
Using
std::arch::is_<arch>_feature_detected!("feature")
+#[target_feature = "feature"]
doesn't work in doctests:The
#[test]
it_works
works fine, but theadd
doctest doesn't; looks like theis_feature_detected
call returnstrue
but Miri still errors out:The text was updated successfully, but these errors were encountered: