Skip to content

Commit 74258ea

Browse files
committed
auto merge of #11491 : wting/rust/wting_7959_document_inline_attributes, r=alexcrichton
Closes #7959.
2 parents 3e8a4a0 + 826f24b commit 74258ea

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

doc/rust.md

+28-6
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ A static item must have a _constant expression_ giving its definition.
12151215

12161216
Static items must be explicitly typed.
12171217
The type may be ```bool```, ```char```, a number, or a type derived from those primitive types.
1218-
The derived types are references with the `'static` lifetime,
1218+
The derived types are references with the `static` lifetime,
12191219
fixed-size arrays, tuples, and structs.
12201220

12211221
~~~~
@@ -1730,14 +1730,17 @@ names are effectively reserved. Some significant attributes include:
17301730

17311731
* The `doc` attribute, for documenting code in-place.
17321732
* The `cfg` attribute, for conditional-compilation by build-configuration.
1733-
* The `lang` attribute, for custom definitions of traits and functions that are known to the Rust compiler (see [Language items](#language-items)).
1734-
* The `link` attribute, for describing linkage metadata for a extern blocks.
17351733
* The `crate_id` attribute, for describing the package ID of a crate.
1734+
* The `lang` attribute, for custom definitions of traits and functions that are
1735+
known to the Rust compiler (see [Language items](#language-items)).
1736+
* The `link` attribute, for describing linkage metadata for a extern blocks.
17361737
* The `test` attribute, for marking functions as unit tests.
17371738
* The `allow`, `warn`, `forbid`, and `deny` attributes, for
17381739
controlling lint checks (see [Lint check attributes](#lint-check-attributes)).
17391740
* The `deriving` attribute, for automatically generating
17401741
implementations of certain traits.
1742+
* The `inline` attribute, for expanding functions at caller location (see
1743+
[Inline attributes](#inline-attributes)).
17411744
* The `static_assert` attribute, for asserting that a static bool is true at compiletime
17421745
* The `thread_local` attribute, for defining a `static mut` as a thread-local. Note that this is
17431746
only a low-level building block, and is not local to a *task*, nor does it provide safety.
@@ -1910,6 +1913,25 @@ A complete list of the built-in language items follows:
19101913
> **Note:** This list is likely to become out of date. We should auto-generate it
19111914
> from `librustc/middle/lang_items.rs`.
19121915
1916+
### Inline attributes
1917+
1918+
The inline attribute is used to suggest to the compiler to perform an inline
1919+
expansion and place a copy of the function in the caller rather than generating
1920+
code to call the function where it is defined.
1921+
1922+
The compiler automatically inlines functions based on internal heuristics.
1923+
Incorrectly inlining functions can actually making the program slower, so it
1924+
should be used with care.
1925+
1926+
`#[inline]` and `#[inline(always)]` always causes the function to be serialized
1927+
into crate metadata to allow cross-crate inlining.
1928+
1929+
There are three different types of inline attributes:
1930+
1931+
* `#[inline]` hints the compiler to perform an inline expansion.
1932+
* `#[inline(always)]` asks the compiler to always perform an inline expansion.
1933+
* `#[inline(never)]` asks the compiler to never perform an inline expansion.
1934+
19131935
### Deriving
19141936

19151937
The `deriving` attribute allows certain traits to be automatically
@@ -3223,12 +3245,12 @@ The type of a closure mapping an input of type `A` to an output of type `B` is `
32233245
An example of creating and calling a closure:
32243246

32253247
```rust
3226-
let captured_var = 10;
3248+
let captured_var = 10;
32273249

3228-
let closure_no_args = || println!("captured_var={}", captured_var);
3250+
let closure_no_args = || println!("captured_var={}", captured_var);
32293251

32303252
let closure_args = |arg: int| -> int {
3231-
println!("captured_var={}, arg={}", captured_var, arg);
3253+
println!("captured_var={}, arg={}", captured_var, arg);
32323254
arg // Note lack of semicolon after 'arg'
32333255
};
32343256

0 commit comments

Comments
 (0)