@@ -2146,10 +2146,12 @@ mod unsafe_keyword {}
2146
2146
2147
2147
#[ doc( keyword = "use" ) ]
2148
2148
//
2149
- /// Import or rename items from other crates or modules.
2149
+ /// Import or rename items from other crates or modules, or specify precise capturing with `use<..>` .
2150
2150
///
2151
- /// Usually a `use` keyword is used to shorten the path required to refer to a module item.
2152
- /// The keyword may appear in modules, blocks and even functions, usually at the top.
2151
+ /// ## Importing items
2152
+ ///
2153
+ /// The `use` keyword is employed to shorten the path required to refer to a module item.
2154
+ /// The keyword may appear in modules, blocks, and even functions, typically at the top.
2153
2155
///
2154
2156
/// The most basic usage of the keyword is `use path::to::item;`,
2155
2157
/// though a number of convenient shortcuts are supported:
@@ -2190,19 +2192,48 @@ mod unsafe_keyword {}
2190
2192
/// // Compiles.
2191
2193
/// let _ = VariantA;
2192
2194
///
2193
- /// // Does not compile !
2195
+ /// // Does not compile!
2194
2196
/// let n = new();
2195
2197
/// ```
2196
2198
///
2197
- /// For more information on `use` and paths in general, see the [Reference].
2199
+ /// For more information on `use` and paths in general, see the [Reference][ref-use-decls] .
2198
2200
///
2199
2201
/// The differences about paths and the `use` keyword between the 2015 and 2018 editions
2200
- /// can also be found in the [Reference].
2202
+ /// can also be found in the [Reference][ref-use-decls].
2203
+ ///
2204
+ /// ## Precise capturing
2205
+ ///
2206
+ /// The `use<..>` syntax is used within certain `impl Trait` bounds to control which generic
2207
+ /// parameters are captured. This is important for return-position `impl Trait` (RPIT) types,
2208
+ /// as it affects borrow checking by controlling which generic parameters can be used in the
2209
+ /// hidden type.
2210
+ ///
2211
+ /// For example, the following function demonstrates an error without precise capturing in
2212
+ /// Rust 2021 and earlier editions:
2213
+ ///
2214
+ /// ```rust,compile_fail,edition2021
2215
+ /// fn f(x: &()) -> impl Sized { x }
2216
+ /// ```
2217
+ ///
2218
+ /// By using `use<'_>` for precise capturing, it can be resolved:
2219
+ ///
2220
+ /// ```rust
2221
+ /// fn f(x: &()) -> impl Sized + use<'_> { x }
2222
+ /// ```
2223
+ ///
2224
+ /// This syntax specifies that the elided lifetime be captured and therefore available for
2225
+ /// use in the hidden type.
2226
+ ///
2227
+ /// In Rust 2024, opaque types automatically capture all lifetime parameters in scope.
2228
+ /// `use<..>` syntax serves as an important way of opting-out of that default.
2229
+ ///
2230
+ /// For more details about precise capturing, see the [Reference][ref-impl-trait].
2201
2231
///
2202
2232
/// [`crate`]: keyword.crate.html
2203
2233
/// [`self`]: keyword.self.html
2204
2234
/// [`super`]: keyword.super.html
2205
- /// [Reference]: ../reference/items/use-declarations.html
2235
+ /// [ref-use-decls]: ../reference/items/use-declarations.html
2236
+ /// [ref-impl-trait]: ../reference/types/impl-trait.html
2206
2237
mod use_keyword { }
2207
2238
2208
2239
#[ doc( keyword = "where" ) ]
0 commit comments