File tree Expand file tree Collapse file tree 1 file changed +57
-2
lines changed Expand file tree Collapse file tree 1 file changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -1217,11 +1217,66 @@ mod self_keyword {}
12171217/// The implementing type within a [`trait`] or [`impl`] block, or the current type within a type
12181218/// definition.
12191219///
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+ /// ```
12211277///
12221278/// [`impl`]: keyword.impl.html
12231279/// [`trait`]: keyword.trait.html
1224- /// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
12251280mod self_upper_keyword { }
12261281
12271282#[ doc( keyword = "static" ) ]
You can’t perform that action at this time.
0 commit comments