summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/missing_inline_in_public_items.txt
blob: d90c50fe7f9e822898d034c60d377d2e04da4c02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
### What it does
It lints if an exported function, method, trait method with default impl,
or trait method impl is not `#[inline]`.

### Why is this bad?
In general, it is not. Functions can be inlined across
crates when that's profitable as long as any form of LTO is used. When LTO is disabled,
functions that are not `#[inline]` cannot be inlined across crates. Certain types of crates
might intend for most of the methods in their public API to be able to be inlined across
crates even when LTO is disabled. For these types of crates, enabling this lint might make
sense. It allows the crate to require all exported methods to be `#[inline]` by default, and
then opt out for specific methods where this might not make sense.

### Example
```
pub fn foo() {} // missing #[inline]
fn ok() {} // ok
#[inline] pub fn bar() {} // ok
#[inline(always)] pub fn baz() {} // ok

pub trait Bar {
  fn bar(); // ok
  fn def_bar() {} // missing #[inline]
}

struct Baz;
impl Baz {
   fn private() {} // ok
}

impl Bar for Baz {
  fn bar() {} // ok - Baz is not exported
}

pub struct PubBaz;
impl PubBaz {
   fn private() {} // ok
   pub fn not_private() {} // missing #[inline]
}

impl Bar for PubBaz {
   fn bar() {} // missing #[inline]
   fn def_bar() {} // missing #[inline]
}
```