You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Include a link to `hashbrown` with a description of how `#[inline]` works
- Add a note about breaking changes to stable behavior
- Add a note about `#[may_dangle]`
Copy file name to clipboardExpand all lines: src/libs/maintaining-std.md
+19-4Lines changed: 19 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -46,16 +46,20 @@ The rules around what's sound and what's not can be subtle. See the [Unsafe Code
46
46
47
47
### Is that `#[inline]` right?
48
48
49
-
Inlining is a trade-off between potential execution speed, compile time and code size.
49
+
Inlining is a trade-off between potential execution speed, compile time and code size. There's some discussion about it in [this PR to the `hashbrown` crate][hashbrown/pull/119]. From the thread:
50
50
51
-
You should add `#[inline]`:
51
+
> `#[inline]` is very different than simply just an inline hint. As I mentioned before, there's no equivalent in C++ for what `#[inline]` does. In debug mode rustc basically ignores `#[inline]`, pretending you didn't even write it. In release mode the compiler will, by default, codegen an `#[inline]` function into every single referencing codegen unit, and then it will also add `inlinehin`t. This means that if you have 16 CGUs and they all reference an item, every single one is getting the entire item's implementation inlined into it.
52
+
53
+
You can add `#[inline]`:
52
54
53
55
- To public, small, non-generic functions.
54
56
55
-
You shouldn’t need `#[inline]`:
57
+
You shouldn't need `#[inline]`:
56
58
57
59
- On methods that have any generics in scope.
58
-
- On methods on traits that don’t have a default implementation.
60
+
- On methods on traits that don't have a default implementation.
61
+
62
+
`#[inline]` can always be introduced later, so if you're in doubt they can just be removed.
59
63
60
64
#### What about `#[inline(always)]`?
61
65
@@ -75,6 +79,10 @@ If the impact isn't too high:
75
79
76
80
- Looping in maintainers of broken crates and submitting PRs to fix them.
77
81
82
+
### Is behavior changed?
83
+
84
+
Breaking changes aren't just limited to compilation failures. Behavioral changes to stable functions generally can't be accepted. See [the `home_dir` issue][rust/pull/46799] for an example.
85
+
78
86
### Are there new impls for stable traits?
79
87
80
88
A lot of PRs to the standard library are adding new impls for already stable traits, which can break consumers in many weird and wonderful ways. The following sections gives some examples of breakage from new trait impls that may not be obvious just from the change made to the standard library.
@@ -177,6 +185,10 @@ Public enums should have a `#[non_exhaustive]` attribute if there's any possibil
177
185
178
186
Changes to collection internals may affect the order their items are dropped in. This has been accepted in the past, but should be noted.
179
187
188
+
### Is there a manual `Drop` implementation?
189
+
190
+
Generic types that manually implement `Drop` should consider whether a `#[may_dangle]` attribute is appropriate. The [Nomicon][dropck] has some details on what `#[may_dangle]` is all about.
191
+
180
192
### How could `mem` break assumptions?
181
193
182
194
#### `mem::replace` and `mem::swap`
@@ -244,7 +256,10 @@ Where `unsafe` and `const` is involved, e.g., for operations which are "unconst"
0 commit comments