File tree 1 file changed +57
-2
lines changed
1 file changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -1217,11 +1217,66 @@ mod self_keyword {}
1217
1217
/// The implementing type within a [`trait`] or [`impl`] block, or the current type within a type
1218
1218
/// definition.
1219
1219
///
1220
- /// The documentation for this keyword is [not yet complete]. Pull requests welcome!
1220
+ /// Within a type definition:
1221
+ ///
1222
+ /// ```
1223
+ /// # #![allow(dead_code)]
1224
+ /// struct Node {
1225
+ /// elem: i32,
1226
+ /// // `Self` is a `Node` here.
1227
+ /// next: Option<Box<Self>>,
1228
+ /// }
1229
+ /// ```
1230
+ ///
1231
+ /// In an [`impl`] block:
1232
+ ///
1233
+ /// ```
1234
+ /// struct Foo(i32);
1235
+ ///
1236
+ /// impl Foo {
1237
+ /// fn new() -> Self {
1238
+ /// Self(0)
1239
+ /// }
1240
+ /// }
1241
+ ///
1242
+ /// assert_eq!(Foo::new().0, Foo(0).0);
1243
+ /// ```
1244
+ ///
1245
+ /// Generic parameters are implicit with `Self`:
1246
+ ///
1247
+ /// ```
1248
+ /// # #![allow(dead_code)]
1249
+ /// struct Wrap<T> {
1250
+ /// elem: T,
1251
+ /// }
1252
+ ///
1253
+ /// impl<T> Wrap<T> {
1254
+ /// fn new(elem: T) -> Self {
1255
+ /// Self { elem }
1256
+ /// }
1257
+ /// }
1258
+ /// ```
1259
+ ///
1260
+ /// In a [`trait`] definition and related [`impl`] block:
1261
+ ///
1262
+ /// ```
1263
+ /// trait Example {
1264
+ /// fn example() -> Self;
1265
+ /// }
1266
+ ///
1267
+ /// struct Foo(i32);
1268
+ ///
1269
+ /// impl Example for Foo {
1270
+ /// fn example() -> Self {
1271
+ /// Self(42)
1272
+ /// }
1273
+ /// }
1274
+ ///
1275
+ /// assert_eq!(Foo::example().0, Foo(42).0);
1276
+ /// ```
1221
1277
///
1222
1278
/// [`impl`]: keyword.impl.html
1223
1279
/// [`trait`]: keyword.trait.html
1224
- /// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
1225
1280
mod self_upper_keyword { }
1226
1281
1227
1282
#[ doc( keyword = "static" ) ]
You can’t perform that action at this time.
0 commit comments