Skip to content

ICE in library/test/src/lib.rs:356 on Nightly when running doc-tests, where the first doc-test is executed twice in a row. #81852

Description

@yoanlcq

Hi,

When running doc-tests with the latest Nightly on my crate, I get an ICE after the first doc-test is executed twice in a row.
The issue does not occur on Stable.
The issue seems to be caused when multiple threads are used for doc-tests.

The ICE is caused by unwrap() in /library/test/src/lib.rs:356.

The issue occured on the x86_64-pc-windows-msvc and x86_64-unknown-linux-gnu targets. Curiously, there are multiple targets on which it does not occur (according to Travic CI builds).
The Travis CI build status is available here : https://travis-ci.com/github/yoanlcq/vek/builds/216330500.

Steps to reproduce

  1. Clone the repo for the vek crate;
  2. Checkout commit a18c2dc5af092caba2daae232d168f1c75c5d039;
  3. Run either cargo test --doc or cargo test --doc -- --test-threads 2.

The actual number of threads does not seem to matter as long as there is more than one.
In my case, specifying -- --test-threads 2 was not necessary, since I think the number of threads is determined automatically in this case.

Code

// No code in particular. The doc-test refers to a line where a macro is expanded.
//
//
// That being said, the line in the compiler's source where the crash occured is : 
let running_test = running_tests.remove(&completed_test.desc).unwrap(); // <--- Unwraps on None

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (04caa632d 2021-01-30)
binary: rustc
commit-hash: 04caa632dd10c2bf64b69524c7f9c4c30a436877
commit-date: 2021-01-30
host: x86_64-pc-windows-msvc
release: 1.51.0-nightly
LLVM version: 11.0.1

Error output

    Finished test [unoptimized + debuginfo] target(s) in 0.03s
   Doc-tests vek

running 1283 tests
test src\mat.rs - mat::repr_c::column_major::mat2::Mat2<T> (line 4154) ... ok
test src\mat.rs - mat::repr_c::column_major::mat2::Mat2<T> (line 4154) ... ok
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', library\test\src\lib.rs:356:75
stack backtrace:
   0:     0x7fff9fee9755 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   1:     0x7fff9ff15fdb - core::fmt::write::ha3ea633b18d2da75
   2:     0x7fff9fedc08d - <std::io::IoSlice as core::fmt::Debug>::fmt::h8573cdc9b491acbf
   3:     0x7fff9feed8fd - std::panicking::take_hook::h462942ea222a8ec2
   4:     0x7fff9feed3c9 - std::panicking::take_hook::h462942ea222a8ec2
   5:     0x7fff840a96f7 - rustc_driver::report_ice::hc33e4d260fbc44ec
   6:     0x7fff9feee362 - std::panicking::rust_panic_with_hook::h18985e2f09a20bf1
   7:     0x7fff9feede23 - rust_begin_unwind
   8:     0x7fff9feea12f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   9:     0x7fff9feedda9 - rust_begin_unwind
  10:     0x7fff9ff12070 - core::panicking::panic_fmt::h45da916c710b88f7
  11:     0x7fff9ff11fbc - core::panicking::panic::h3a7a516f2be28c18
  12:     0x7fffbac0cffb - test::test_main_static_abort::h4318bb20d9dc449a
  13:     0x7fffbabf7b72 - test::console::run_tests_console::h6776da77c8860d5d
  14:     0x7fffbac06e77 - test::test_main::h7d9e75411069f83b
  15:     0x7ff6d9c9e2c6 - <unknown>
  16:     0x7ff6d9bb5f77 - <unknown>
  17:     0x7ff6d9d93220 - <unknown>
  18:     0x7ff6d9bc3e0b - <unknown>
  19:     0x7ff6d9d2e69d - <unknown>
  20:     0x7fff9fefe0ca - std::sys::windows::thread::Thread::new::ha39cc759d7fbecd8
  21:     0x7ff8004a7034 - BaseThreadInitThunk
  22:     0x7ff80095d0d1 - RtlUserThreadStart

error: internal compiler error: unexpected panic

error: Unrecognized option: 'test-args'

thread 'src\mat.rs - mat::repr_c::column_major::mat2::Mat2<T> (line 4156)' panicked at 'called `Result::unwrap()` on an `Err` value: "SendError(..)"', library\test\src\lib.rs:592:30
stack backtrace:
   0:     0x7fff9fee9755 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   1:     0x7fff9ff15fdb - core::fmt::write::ha3ea633b18d2da75
   2:     0x7fff9fedc08d - <std::io::IoSlice as core::fmt::Debug>::fmt::h8573cdc9b491acbf
   3:     0x7fff9feed8fd - std::panicking::take_hook::h462942ea222a8ec2
   4:     0x7fff9feed3c9 - std::panicking::take_hook::h462942ea222a8ec2
   5:     0x7fff840a96f7 - rustc_driver::report_ice::hc33e4d260fbc44ec
   6:     0x7fff9feee362 - std::panicking::rust_panic_with_hook::h18985e2f09a20bf1
   7:     0x7fff9feede51 - rust_begin_unwind
   8:     0x7fff9feea12f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   9:     0x7fff9feedda9 - rust_begin_unwind
  10:     0x7fff9ff12070 - core::panicking::panic_fmt::h45da916c710b88f7
  11:     0x7fff9ff11d03 - core::result::unwrap_failed::h8a30362b6787a796
  12:     0x7fffbac17ab2 - test::run_test::h5515debdb9b010cd
  13:     0x7fffbabe15c6 - <unknown>
  14:     0x7fffbabe8cb4 - <unknown>
  15:     0x7fff9fefe0ca - std::sys::windows::thread::Thread::new::ha39cc759d7fbecd8
  16:     0x7ff8004a7034 - BaseThreadInitThunk
  17:     0x7ff80095d0d1 - RtlUserThreadStart

error: internal compiler error: unexpected panic

error: Unrecognized option: 'test-args'

error: test failed, to rerun pass '--doc'
Backtrace

   0:     0x7fff9fee9755 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   1:     0x7fff9ff15fdb - core::fmt::write::ha3ea633b18d2da75
   2:     0x7fff9fedc08d - <std::io::IoSlice as core::fmt::Debug>::fmt::h8573cdc9b491acbf
   3:     0x7fff9feed8fd - std::panicking::take_hook::h462942ea222a8ec2
   4:     0x7fff9feed3c9 - std::panicking::take_hook::h462942ea222a8ec2
   5:     0x7fff840a96f7 - rustc_driver::report_ice::hc33e4d260fbc44ec
   6:     0x7fff9feee362 - std::panicking::rust_panic_with_hook::h18985e2f09a20bf1
   7:     0x7fff9feede51 - rust_begin_unwind
   8:     0x7fff9feea12f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h07eb7c6246901ad5
   9:     0x7fff9feedda9 - rust_begin_unwind
  10:     0x7fff9ff12070 - core::panicking::panic_fmt::h45da916c710b88f7
  11:     0x7fff9ff11d03 - core::result::unwrap_failed::h8a30362b6787a796
  12:     0x7fffbac17ab2 - test::run_test::h5515debdb9b010cd
  13:     0x7fffbabe15c6 - <unknown>
  14:     0x7fffbabe8cb4 - <unknown>
  15:     0x7fff9fefe0ca - std::sys::windows::thread::Thread::new::ha39cc759d7fbecd8
  16:     0x7ff8004a7034 - BaseThreadInitThunk
  17:     0x7ff80095d0d1 - RtlUserThreadStart

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Feb 7, 2021
  2. added
    A-libtestArea: `#[test]` / the `test` library
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Feb 7, 2021
  3. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    and removed
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Feb 7, 2021
  4. tspiteri commented on Feb 18, 2021

    @tspiteri
    Contributor

    This is now a regression from stable to beta.

  5. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    and removed on Feb 18, 2021
  6. hkmatsumoto commented on Feb 18, 2021

    @hkmatsumoto
    Contributor

    Bisection says the regression happened in 1483e67.
    @rustbot label -E-needs-bisection

  7. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Feb 18, 2021
  8. jyn514 commented on Feb 18, 2021

    @jyn514
    Member

    cc @andersk, do you have time to take a look?

  9. removed
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    on Feb 18, 2021
  10. andersk commented on Feb 18, 2021

    @andersk
    Contributor

    It seems like the underlying problem is that it’s possible for different tests to collide to the same TestDesc when macros are involved. Minimal example:

    struct S;
    trait A {}
    trait B {}
    
    macro_rules! whoops {
        () => {
            /// ```
            /// assert_eq!(1, 1);
            /// ```
            impl A for S {}
    
            /// ```
            /// assert_eq!(1, 1);
            /// ```
            impl B for S {}
        };
    }
    
    whoops!();

    Before #81367, this produced

    running 2 tests
    test src/lib.rs - S (line 19) ... ok
    test src/lib.rs - S (line 19) ... ok
    
    test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.15s
    

    and now it panics.

    We should fix the underlying problem, but a simple band-aid for beta would be to turn the unwrap into an if let. The only side effect would be that we don’t get the benefits of #81367 in the presence of these collisions.

  11. added a commit that references this issue on Feb 18, 2021
    1605af0
  12. andersk commented on Feb 18, 2021

    @andersk
    Contributor

    I’ve submitted that workaround as #82274.

  13. added a commit that references this issue on Feb 19, 2021
    36a348b
  14. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Feb 28, 2021
  15. added a commit that references this issue on Mar 10, 2021
    03fe394
  16. added 2 commits that reference this issue on Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions