@@ -335,3 +335,43 @@ mod deprecated_attribute {}
335335///
336336/// [the `warn` attribute]: ../reference/attributes/diagnostics.html#lint-check-attributes
337337mod warn_attribute { }
338+
339+ #[ doc( attribute = "inline" ) ]
340+ //
341+ /// Suggest that the compiler inline a function at its call sites.
342+ ///
343+ /// Inlining replaces a call with a copy of the called function's body, which can remove the
344+ /// overhead of the call. The `inline` attribute is only a hint: the compiler may ignore it, and
345+ /// it already inlines functions on its own when that looks worthwhile. Poor choices about what to
346+ /// inline can make a program larger or slower.
347+ ///
348+ /// Where it does matter is inlining across crate boundaries. A non-generic function is not
349+ /// normally inlined into another crate, since the calling crate compiles against only its
350+ /// signature. Marking it `#[inline]` makes the body available to other crates so they can inline
351+ /// it too:
352+ ///
353+ /// ```rust
354+ /// # #![allow(dead_code)]
355+ /// #[inline]
356+ /// pub fn square(x: i32) -> i32 {
357+ /// x * x
358+ /// }
359+ /// ```
360+ ///
361+ /// Generic functions do not need this. They are instantiated in each crate that uses them, so
362+ /// their bodies are already available to inline.
363+ ///
364+ /// The attribute applies to functions and has three forms:
365+ ///
366+ /// - `#[inline]` suggests inlining the function.
367+ /// - `#[inline(always)]` suggests inlining it at every call site.
368+ /// - `#[inline(never)]` suggests never inlining it.
369+ ///
370+ /// You should almost never need `#[inline(always)]`: prefer to let the compiler decide unless
371+ /// profiling shows a small, hot function that benefits from it. `#[inline(never)]` is useful to
372+ /// keep a rarely used path, such as a function that only reports an error, out of its caller.
373+ ///
374+ /// For more information, see the Reference on [the `inline` attribute].
375+ ///
376+ /// [the `inline` attribute]: ../reference/attributes/codegen.html#the-inline-attribute
377+ mod inline_attribute { }
0 commit comments