Skip to content

Commit 5ad4cf4

Browse files
committed
Auto merge of #12116 - ehuss:semver-fn-unsafe-safe, r=epage
Semver: Note that it is not a breaking change to make an unsafe function safe This is a repost of #11200 with some requested edits made. This makes it clear that it is a minor change due to our policy that triggering new lints is not a breaking change. I also simplified it by not repeating what constitutes a breaking change for a trait definition, and instead link to the rule that specifies no signature changes are allowed.
2 parents 0e93732 + 8782f79 commit 5ad4cf4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/doc/src/reference/semver.md

+43
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ considered incompatible.
8888
* [Possibly-breaking: introducing a new function type parameter](#fn-generic-new)
8989
* [Minor: generalizing a function to use generics (supporting original type)](#fn-generalize-compatible)
9090
* [Major: generalizing a function to use generics with type mismatch](#fn-generalize-mismatch)
91+
* [Minor: making an `unsafe` function safe](#fn-unsafe-safe)
9192
* Attributes
9293
* [Major: switching from `no_std` support to requiring `std`](#attr-no-std-to-std)
9394
* [Major: adding `non_exhaustive` to an existing enum, variant, or struct with no private fields](#attr-adding-non-exhaustive)
@@ -1080,6 +1081,47 @@ fn main() {
10801081
}
10811082
```
10821083

1084+
<a id="fn-unsafe-safe"></a>
1085+
### Minor: making an `unsafe` function safe
1086+
1087+
A previously `unsafe` function can be made safe without breaking code.
1088+
1089+
Note however that it may cause the [`unused_unsafe`][unused_unsafe] lint to
1090+
trigger as in the example below, which will cause local crates that have
1091+
specified `#![deny(warnings)]` to stop compiling. Per [introducing new
1092+
lints](#new-lints), it is allowed for updates to introduce new warnings.
1093+
1094+
Going the other way (making a safe function `unsafe`) is a breaking change.
1095+
1096+
```rust,ignore
1097+
// MINOR CHANGE
1098+
1099+
///////////////////////////////////////////////////////////
1100+
// Before
1101+
pub unsafe fn foo() {}
1102+
1103+
///////////////////////////////////////////////////////////
1104+
// After
1105+
pub fn foo() {}
1106+
1107+
///////////////////////////////////////////////////////////
1108+
// Example use of the library that will trigger a lint.
1109+
use updated_crate::foo;
1110+
1111+
unsafe fn bar(f: unsafe fn()) {
1112+
f()
1113+
}
1114+
1115+
fn main() {
1116+
unsafe { foo() }; // The `unused_unsafe` lint will trigger here
1117+
unsafe { bar(foo) };
1118+
}
1119+
```
1120+
1121+
Making a previously `unsafe` associated function or method on structs / enums
1122+
safe is also a minor change, while the same is not true for associated
1123+
function on traits (see [any change to trait item signatures](#trait-item-signature)).
1124+
10831125
<a id="attr-no-std-to-std"></a>
10841126
### Major: switching from `no_std` support to requiring `std`
10851127

@@ -1487,3 +1529,4 @@ document what your commitments are.
14871529
[SemVer]: https://semver.org/
14881530
[struct literal]: ../../reference/expressions/struct-expr.html
14891531
[wildcard patterns]: ../../reference/patterns.html#wildcard-pattern
1532+
[unused_unsafe]: ../../rustc/lints/listing/warn-by-default.html#unused-unsafe

0 commit comments

Comments
 (0)