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

rustdoc doesn't execute documentation tests for #[target_feature] functions #49723

Closed
gnzlbg opened this issue Apr 6, 2018 · 4 comments
Closed
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 6, 2018

Example:

#![feature(target_feature)]

/// Foo
///
/// # Examples
///
/// ```
/// assert!(false);
/// ```
#[target_feature(enable="sse")]
pub unsafe fn foo() {}

$ cargo test

Doc-tests foo

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
@QuietMisdreavus
Copy link
Member

I wonder if it has to do with #49225? I checked the sample with the nightlies that were made right before and after the change. The previous nightly finds the test, the next nightly does not:

$ rustdoc +nightly-2018-03-21 --test h.rs

running 1 test
test h.rs - foo (line 7) ... FAILED

failures:

---- h.rs - foo (line 7) stdout ----
        thread 'rustc' panicked at 'test executable failed:

thread 'main' panicked at 'assertion failed: false', h.rs:3:1
note: Run with `RUST_BACKTRACE=1` for a backtrace.

', librustdoc/test.rs:331:17
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    h.rs - foo (line 7)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

$ rustdoc +nightly-2018-03-24 --test h.rs

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

@QuietMisdreavus
Copy link
Member

Oh wait, it's not that change, it's #48759 - it dynamically adds doc(cfg) flags to the item, which rustdoc reads before executing the doctests.

@QuietMisdreavus QuietMisdreavus added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Apr 9, 2018
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Apr 10, 2018

@QuietMisdreavus can we revert the part of #48759 that adds doc(cfg) from #[target_feature] ? It is not working properly and it is at least unclear to me what the default behavior for this should be at this point. Not doing anything about it allows people to do whatever they want. Figuring a good default and coming at a working implementation might be easier if we have a body of working doc tests that can be studied.

@QuietMisdreavus
Copy link
Member

After some conversations on IRC, we discovered that rustdoc doesn't add target features to the configuration environment when extracting and running doctests. I've opened #49864 to fix this.

kennytm added a commit to kennytm/rust that referenced this issue Apr 14, 2018
…ures, r=GuillaumeGomez

add target features when extracting and running doctests

When rendering documentation, rustdoc will happily load target features into the cfg environment from the current target, but fails to do this when doing anything with doctests. This would lead to situations where, thanks to rust-lang#48759, functions tagged with `#[target_feature]` couldn't run doctests, thanks to the automatic `#[doc(cfg(target_feature = "..."))]`.

Currently, there's no way to pass codegen options to rustdoc that will affect its rustc sessions, but for now this will let you use target features that come default on the platform you're targeting.

Fixes rust-lang#49723
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants