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

UnwindSafe and RefUnwindSafe should be in libcore #64086

Closed
matklad opened this issue Sep 2, 2019 · 4 comments
Closed

UnwindSafe and RefUnwindSafe should be in libcore #64086

matklad opened this issue Sep 2, 2019 · 4 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@matklad
Copy link
Member

matklad commented Sep 2, 2019

I think that would be useful to allow pure no_std libraries to implement those traits without needing the std cargo feature.

cc @gnzlbg, you've asked about this #40628.

@Mark-Simulacrum Mark-Simulacrum added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 2, 2019
@gnzlbg
Copy link
Contributor

gnzlbg commented Sep 6, 2019

FWIW I also needed AssertUnwindSafe in #[no_std] back then, but I don't remember why.

@ohadravid
Copy link
Contributor

I run into this when changing an std::sync::Mutex to a parking_lot one:

use std::panic::RefUnwindSafe;
use std::sync::Mutex as StdMutex;
use parking_lot::Mutex as ParkingLotMutex;

fn assert_ref_unwind_safe<T: RefUnwindSafe>(t: T) {

}

fn main() {
    assert_ref_unwind_safe(StdMutex::new(0));

    assert_ref_unwind_safe(ParkingLotMutex::new(0));
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0277]: the type `std::cell::UnsafeCell<{integer}>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
  --> src/main.rs:12:5
   |
5  | fn assert_ref_unwind_safe<T: RefUnwindSafe>(t: T) {
   |    ----------------------    ------------- required by this bound in `assert_ref_unwind_safe`
...
12 |     assert_ref_unwind_safe(ParkingLotMutex::new(0));
   |     ^^^^^^^^^^^^^^^^^^^^^^ `std::cell::UnsafeCell<{integer}>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
   |
   = help: within `lock_api::mutex::Mutex<parking_lot::raw_mutex::RawMutex, {integer}>`, the trait `std::panic::RefUnwindSafe` is not implemented for `std::cell::UnsafeCell<{integer}>`
   = note: required because it appears within the type `lock_api::mutex::Mutex<parking_lot::raw_mutex::RawMutex, {integer}>`
...

But parking_lot is no_std, so it can't implement it!

@steveklabnik
Copy link
Member

Triage: no change

@nico-abram
Copy link
Contributor

I believe this was implemented in #84662 and shipped with rustc 1.56, so this can be closed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants