Compare commits

...

8 Commits

Author SHA1 Message Date
Nicolas Abram 31da0d9079
Merge e10ce23ed6 into 8e7887c8b7 2024-05-02 23:21:44 +02:00
Eric Huss 8e7887c8b7
Merge pull request #3622 from RalfJung/rfc-process-pr-number
both the RFC file name and link in the file should be updated
2024-05-02 06:11:14 -07:00
Ralf Jung 865c00519b both the RFC file name and link in the file should be updated 2024-05-02 13:37:00 +02:00
Eric Huss 930f5ab59b
Merge pull request #3620 from rust-lang/renovate/actions-checkout-digest
Update actions/checkout digest to 0ad4b8f
2024-05-01 12:01:20 -07:00
Eric Huss 793ffd107d
Add patch version for actions/checkout
This will make it so that renovatebot will update the comment with the full patch version.
2024-05-01 12:01:06 -07:00
renovate[bot] ddd8298de2
Update actions/checkout digest to 0ad4b8f 2024-05-01 00:31:21 +00:00
unknown e10ce23ed6 Update PR number 2022-05-04 02:30:29 -03:00
unknown a9d07d1731 Deprecating UnwindSafe 2022-05-04 02:23:32 -03:00
3 changed files with 74 additions and 2 deletions

View File

@ -12,7 +12,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- name: Install mdbook

View File

@ -115,7 +115,8 @@ merged into the RFC repository as a markdown file. At that point the RFC is
feedback from the larger community, and the author should be prepared to
revise it in response.
- Now that your RFC has an open pull request, use the issue number of the PR
to update your `0000-` prefix to that number.
to rename the file: update your `0000-` prefix to that number. Also
update the "RFC PR" link at the top of the file.
- Each pull request will be labeled with the most relevant [sub-team], which
will lead to its being triaged by that team in a future meeting and assigned
to a member of the subteam.

View File

@ -0,0 +1,71 @@
- Feature Name: deprecate_unwind_safe
- Start Date: 2022-01-17
- RFC PR: [rust-lang/rfcs#3260](https://github.com/rust-lang/rfcs/pull/3260)
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)
# Summary
[summary]: #summary
Currently rust has the [UnwindSafe](https://doc.rust-lang.org/std/panic/trait.UnwindSafe.html#) and [RefUnwindSafe](https://doc.rust-lang.org/core/panic/trait.RefUnwindSafe.html#) marker traits. This RFC proposes to deprecate them, and remove the `F: UnwindSafe` bound on [catch_unwind](https://doc.rust-lang.org/std/panic/fn.catch_unwind.html#).
# Motivation
[motivation]: #motivation
Unwind safety is not actually related to safety. It acts as a lint. [AssertUnwindSafe](https://doc.rust-lang.org/std/panic/struct.AssertUnwindSafe.html#) can be used to ignore it, and using it does not require unsafe. If using it results in undefined behaviour or unsoundness, the problem lies elsewhere. The existence of unwind safety makes it seem as if you can rely on it for soundness, which is not true (See discussion in [UnwindSafe docs are unclear](https://github.com/rust-lang/rust/issues/65717).)
It can also be problematic when a type does not implement the marker trait, but it could, notably with trait objects (See discussion in [`UnwindSafe` is unergonomic](https://github.com/rust-lang/rust/issues/40628)). It can also be a pain point for library authors, who are not sure if they should add a bound on them for their generic types to guarantee their types are UnwindSafe, which would make their downstream users sometimes have to use AssertUnwindSafe despite not using catch_unwind just to satisfy the bounds.
# Guide-level explanation
[guide-level-explanation]: #guide-level-explanation
UnwindSafe and RefUnwindSafe are deprecated, and you never need to use them. If you can cause undefined behaviour with catch_unwind, something else is unsound.
The following now compiles:
```rs
let x = std::cell::UnsafeCell::new(1u8);
let result = std::panic::catch_unwind(|| {
println!("{:p}", x.get());
panic!()
});
```
Which used to require AssertUnwindSafe:
```rs
let x = std::panic::AssertUnwindSafe(std::cell::UnsafeCell::new(1u8));
let result = std::panic::catch_unwind(|| {
println!("{:p}", x.get());
panic!()
});
```
# Reference-level explanation
[reference-level-explanation]: #reference-level-explanation
UnwindSafe and RefUnwindSafe are now deprecated, and the UnwindSafe bound on the F generic parameter of catch_unwind is removed.
# Drawbacks
[drawbacks]: #drawbacks
We lose any value that UnwindSafe was actually providing as a lint.
# Rationale and alternatives
[rationale-and-alternatives]: #rationale-and-alternatives
- We could keep UnwindSafe as-is without deprecating it.
- Rename UnwindSafe to something that does not mention "safety".
- We could make using something !UnwindSafe through catch_unwind a warning via language magic instead of completely removing it. This would probably require a fundamentally new feature of trait resolution, to turn a missing trait implementation into a warning.
# Prior art
[prior-art]: #prior-art
In the pull request where UnwindSafe was moved to core, it was mentioned the libs team may want to deprecate it https://github.com/rust-lang/rust/pull/84662#issuecomment-840010967
I found a comment in this issue mentioning deprecation as far back as 2019: https://github.com/rust-lang/rust/issues/40628#issuecomment-549050573
# Unresolved questions
[unresolved-questions]: #unresolved-questions
- How will this impact the ecosystem? How will libraries with an MSRV deal with this?
# Future possibilities
[future-possibilities]: #future-possibilities