rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.31k stars 12.58k forks source link

doctests broken on `macos-latest` (github actions image) on 1.79 #126643

Closed dj8yfo closed 2 months ago

dj8yfo commented 3 months ago

I tried this code:

https://github.com/near/near-sdk-rs/actions/runs/9571406393/job/26388439567

in this environment:

Runner Image
  Image: macos-14-arm64
  Version: 20240611.1
  Included Software: https://github.com/actions/runner-images/blob/macos-14-arm64/20240611.1/images/macos/macos-14-arm64-Readme.md
  Image Release: https://github.com/actions/runner-images/releases/tag/macos-14-arm64%2F20240611.1  

I expected to see this happen: doctests pass as well as in a rust 1.78 run.

Instead, this happened: doctests fail with somewhat otherworldly backtraces, having no origin in the tested code. The problem has been confirmed to be pertinent to doctests specifically by applying the following to Cargo.toml:

[lib]
doctest = false

Meta

Run rustc --version && rustdoc --version:

rustc 1.79.0 (129f3b996 2024-06-10)
rustdoc 1.79.0 (129f3b996 2024-06-10)
Backtrace

``` 2024-06-18T14:34:08.7215730Z ---- near-sdk/src/collections/lazy_option.rs - collections::lazy_option::LazyOption::remove (line 113) stdout ---- 2024-06-18T14:34:08.7216320Z Test executable failed (signal: 6 (SIGABRT)). 2024-06-18T14:34:08.7216670Z 2024-06-18T14:34:08.7216730Z stderr: 2024-06-18T14:34:08.7217060Z thread '' panicked at library/core/src/panicking.rs:220:5: 2024-06-18T14:34:08.7217710Z unsafe precondition(s) violated: ptr::replace requires that the pointer argument is aligned and non-null 2024-06-18T14:34:08.7218180Z stack backtrace: 2024-06-18T14:34:08.7218590Z 0: 0x1030723d8 - std::backtrace_rs::backtrace::libunwind::trace::he4f0a5f56afe8e37 2024-06-18T14:34:08.7219290Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 2024-06-18T14:34:08.7220070Z 1: 0x1030723d8 - std::backtrace_rs::backtrace::trace_unsynchronized::habb302958e80f800 2024-06-18T14:34:08.7220750Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2024-06-18T14:34:08.7221700Z 2: 0x1030723d8 - std::sys_common::backtrace::_print_fmt::h9819d35e2a5cda77 2024-06-18T14:34:08.7222280Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:68:5 2024-06-18T14:34:08.7223070Z 3: 0x1030723d8 - ::fmt::h1f3776e0b5c7517d 2024-06-18T14:34:08.7223780Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:44:22 2024-06-18T14:34:08.7224390Z 4: 0x10308bbb4 - core::fmt::rt::Argument::fmt::h626862aa6242248a 2024-06-18T14:34:08.7224910Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/fmt/rt.rs:165:63 2024-06-18T14:34:08.7225450Z 5: 0x10308bbb4 - core::fmt::write::heedef092c8c0962e 2024-06-18T14:34:08.7225940Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/fmt/mod.rs:1157:21 2024-06-18T14:34:08.7226500Z 6: 0x103070798 - std::io::Write::write_fmt::h7178e8e2ea928914 2024-06-18T14:34:08.7227000Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/io/mod.rs:1832:15 2024-06-18T14:34:08.7227570Z 7: 0x103072230 - std::sys_common::backtrace::_print::ha0f584bc7bfb9d2b 2024-06-18T14:34:08.7228270Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:47:5 2024-06-18T14:34:08.7228890Z 8: 0x103072230 - std::sys_common::backtrace::print::h417292deb95532ed 2024-06-18T14:34:08.7229460Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:34:9 2024-06-18T14:34:08.7230100Z 9: 0x10307338c - std::panicking::default_hook::{{closure}}::h0cb68f1228c4613a 2024-06-18T14:34:08.7230630Z 10: 0x103073080 - std::panicking::default_hook::h24535936bc1f51de 2024-06-18T14:34:08.7231160Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:298:9 2024-06-18T14:34:08.7231860Z 11: 0x103073c44 - std::panicking::rust_panic_with_hook::h5db4d2345b297bed 2024-06-18T14:34:08.7232480Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:795:13 2024-06-18T14:34:08.7233170Z 12: 0x103073648 - std::panicking::begin_panic_handler::{{closure}}::h3fd558f09a0d5492 2024-06-18T14:34:08.7233750Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:656:13 2024-06-18T14:34:08.7234760Z 13: 0x103072860 - std::sys_common::backtrace::__rust_end_short_backtrace::hfc76eebe1ce501b2 2024-06-18T14:34:08.7235430Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys_common/backtrace.rs:171:18 2024-06-18T14:34:08.7235970Z 14: 0x1030733e4 - rust_begin_unwind 2024-06-18T14:34:08.7236420Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5 2024-06-18T14:34:08.7237050Z 15: 0x103096960 - core::panicking::panic_nounwind_fmt::runtime::h6aaba2885d9c2d14 2024-06-18T14:34:08.7237630Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:110:18 2024-06-18T14:34:08.7238230Z 16: 0x103096960 - core::panicking::panic_nounwind_fmt::hcce2987b0dd42723 2024-06-18T14:34:08.7238780Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:120:5 2024-06-18T14:34:08.7239370Z 17: 0x1030969d8 - core::panicking::panic_nounwind::h355f878b46c24ec3 2024-06-18T14:34:08.7239910Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:220:5 2024-06-18T14:34:08.7240710Z 18: 0x102f59080 - core::ptr::replace::precondition_check::h3e6a922a4436b8b5 2024-06-18T14:34:08.7264840Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ub_checks.rs:66:21 2024-06-18T14:34:08.7265720Z 19: 0x102f569ec - core::ptr::replace::he9e2c42f9fe96d9b 2024-06-18T14:34:08.7266300Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ub_checks.rs:73:17 2024-06-18T14:34:08.7268680Z 20: 0x102f569ec - core::ptr::mut_ptr::::replace::hcc3425bab485c184 2024-06-18T14:34:08.7269330Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ptr/mut_ptr.rs:1560:18 2024-06-18T14:34:08.7270070Z 21: 0x102f569ec - std::sys::thread_local::lazy::LazyKeyInner::take::h11414c1b64d26b2a 2024-06-18T14:34:08.7270710Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/thread_local/mod.rs:102:30 2024-06-18T14:34:08.7271450Z 22: 0x102f58ef8 - std::sys::thread_local::fast_local::destroy_value::{{closure}}::hd845f603301381c7 2024-06-18T14:34:08.7272260Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/thread_local/fast_local.rs:241:21 2024-06-18T14:34:08.7273090Z 23: 0x102f56bd0 - core::ops::function::FnOnce::call_once::hd86e155e4dc90a36 2024-06-18T14:34:08.7273960Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5 2024-06-18T14:34:08.7275000Z 24: 0x102f556d0 - as core::ops::function::FnOnce<()>>::call_once::h8d0664d8779d012d 2024-06-18T14:34:08.7275890Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panic/unwind_safe.rs:272:9 2024-06-18T14:34:08.7276580Z 25: 0x102f59fe0 - std::panicking::try::do_call::hc4392c4b4683de80 2024-06-18T14:34:08.7277170Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:559:40 2024-06-18T14:34:08.7277660Z 26: 0x102f5cc68 - ___rust_try 2024-06-18T14:34:08.7278030Z 27: 0x102f59f60 - std::panicking::try::h66751cbb6f40519b 2024-06-18T14:34:08.7278540Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:523:19 2024-06-18T14:34:08.7279150Z 28: 0x102f58da0 - std::panic::catch_unwind::h846c7e1ad8cfb94e 2024-06-18T14:34:08.7279740Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panic.rs:149:14 2024-06-18T14:34:08.7280840Z 29: 0x102f58da0 - std::sys::thread_local::fast_local::destroy_value::h9becbbdb9420a8a3 2024-06-18T14:34:08.7281630Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/thread_local/fast_local.rs:239:21 2024-06-18T14:34:08.7282470Z 30: 0x103075bfc - std::sys::pal::unix::thread_local_dtor::register_dtor::run_dtors::h1fa3585f7318df66 2024-06-18T14:34:08.7283230Z at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/sys/pal/unix/thread_local_dtor.rs:114:17 2024-06-18T14:34:08.7283840Z thread caused non-unwinding panic. aborting. ```

Unfortunately, a minimalistic example doesn't reproduce the same problem.

workingjubilee commented 3 months ago

does this reproduce with nightly?

workingjubilee commented 3 months ago

cc @joboet this almost certainly has to be one of our PRs, but mine were supposedly no-ops???

dj8yfo commented 3 months ago

does this reproduce with nightly?

@workingjubilee it does on 1.81 with a similar message, but now with some added spice, on what looks to be on an assert_eq! in a regular test (not a doctest), but it's hard to judge about on what exactly from error message

https://github.com/near/near-sdk-rs/actions/runs/9580409261/job/26414970534 , https://github.com/near/near-sdk-rs/blob/master/near-contract-standards/src/fungible_token/events.rs#L165

dj8yfo commented 3 months ago

similar behaviour on macos-13-xlarge https://github.com/near/near-sdk-rs/actions/runs/9581013781/job/26416865346

veera-sivarajan commented 3 months ago

@rustbot label -needs-triage +T-rustdoc

dj8yfo commented 2 months ago

@workingjubilee the issue has somewhat magically fixed itself when going from

image to image

https://github.com/near/near-sdk-rs/pull/1231

workingjubilee commented 2 months ago

...weird and unexplained. Usually the reason for this is unsound code, so I feel it is very likely that your SDK has unsound code somewhere in it that is causing an unsound interaction with std's unsafe code. But I cannot prove anything like that, so!

dj8yfo commented 1 month ago

@workingjubilee , somewhat high level, it might have been the env/image problem, as it was reported at the time that a physical MacOs 13 with m2-pro wasn't having the very same problem of this issue as macos-13-xlarge vm.

workingjubilee commented 1 month ago

Ah, I see. I'm pro "blame it on QEMU or sth" there in the absence of anything else clear.