Skip to content

Commit 5ed42a1

Browse files
authored
Update maintaining-std.md (#424)
- 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]`
1 parent acda148 commit 5ed42a1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/libs/maintaining-std.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@ The rules around what's sound and what's not can be subtle. See the [Unsafe Code
4646

4747
### Is that `#[inline]` right?
4848

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:
5050

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]`:
5254

5355
- To public, small, non-generic functions.
5456

55-
You shouldnt need `#[inline]`:
57+
You shouldn't need `#[inline]`:
5658

5759
- 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.
5963

6064
#### What about `#[inline(always)]`?
6165

@@ -75,6 +79,10 @@ If the impact isn't too high:
7579

7680
- Looping in maintainers of broken crates and submitting PRs to fix them.
7781

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+
7886
### Are there new impls for stable traits?
7987

8088
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
177185

178186
Changes to collection internals may affect the order their items are dropped in. This has been accepted in the past, but should be noted.
179187

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+
180192
### How could `mem` break assumptions?
181193

182194
#### `mem::replace` and `mem::swap`
@@ -244,7 +256,10 @@ Where `unsafe` and `const` is involved, e.g., for operations which are "unconst"
244256
[`rust-timer`]: https://github.com/rust-lang-nursery/rustc-perf
245257
[Libs tracking issues]: https://github.com/rust-lang/rust/issues?q=label%3AC-tracking-issue+label%3AT-libs
246258
[Drop guarantee]: https://doc.rust-lang.org/nightly/std/pin/index.html#drop-guarantee
259+
[dropck]: https://doc.rust-lang.org/nomicon/dropck.html
247260
[Forge]: https://forge.rust-lang.org/
248261
[RFC 1023]: https://rust-lang.github.io/rfcs/1023-rebalancing-coherence.html
249262
[RFC 1105]: https://rust-lang.github.io/rfcs/1105-api-evolution.html
250263
[Everyone Poops]: http://cglab.ca/~abeinges/blah/everyone-poops
264+
[rust/pull/46799]: https://github.com/rust-lang/rust/pull/46799
265+
[hashbrown/pull/119]: https://github.com/rust-lang/hashbrown/pull/119

0 commit comments

Comments
 (0)