Skip to content

Commit 698bbe5

Browse files
committed
Replaced self-reflective explicit types with clearer Self or Self::… in stdlib docs
1 parent cd45b19 commit 698bbe5

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

src/libcore/cmp.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use self::Ordering::*;
7272
/// }
7373
///
7474
/// impl PartialEq for Book {
75-
/// fn eq(&self, other: &Book) -> bool {
75+
/// fn eq(&self, other: &Self) -> bool {
7676
/// self.isbn == other.isbn
7777
/// }
7878
/// }
@@ -233,7 +233,7 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
233233
/// format: BookFormat,
234234
/// }
235235
/// impl PartialEq for Book {
236-
/// fn eq(&self, other: &Book) -> bool {
236+
/// fn eq(&self, other: &Self) -> bool {
237237
/// self.isbn == other.isbn
238238
/// }
239239
/// }
@@ -493,19 +493,19 @@ impl<T: Ord> Ord for Reverse<T> {
493493
/// }
494494
///
495495
/// impl Ord for Person {
496-
/// fn cmp(&self, other: &Person) -> Ordering {
496+
/// fn cmp(&self, other: &Self) -> Ordering {
497497
/// self.height.cmp(&other.height)
498498
/// }
499499
/// }
500500
///
501501
/// impl PartialOrd for Person {
502-
/// fn partial_cmp(&self, other: &Person) -> Option<Ordering> {
502+
/// fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
503503
/// Some(self.cmp(other))
504504
/// }
505505
/// }
506506
///
507507
/// impl PartialEq for Person {
508-
/// fn eq(&self, other: &Person) -> bool {
508+
/// fn eq(&self, other: &Self) -> bool {
509509
/// self.height == other.height
510510
/// }
511511
/// }
@@ -691,13 +691,13 @@ impl PartialOrd for Ordering {
691691
/// }
692692
///
693693
/// impl PartialOrd for Person {
694-
/// fn partial_cmp(&self, other: &Person) -> Option<Ordering> {
694+
/// fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
695695
/// self.height.partial_cmp(&other.height)
696696
/// }
697697
/// }
698698
///
699699
/// impl PartialEq for Person {
700-
/// fn eq(&self, other: &Person) -> bool {
700+
/// fn eq(&self, other: &Self) -> bool {
701701
/// self.height == other.height
702702
/// }
703703
/// }

src/libcore/iter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
//! type Item = usize;
102102
//!
103103
//! // next() is the only required method
104-
//! fn next(&mut self) -> Option<usize> {
104+
//! fn next(&mut self) -> Option<Self::Item> {
105105
//! // Increment our count. This is why we started at zero.
106106
//! self.count += 1;
107107
//!

src/libcore/iter/traits/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub trait FromIterator<A>: Sized {
167167
/// // and we'll implement IntoIterator
168168
/// impl IntoIterator for MyCollection {
169169
/// type Item = i32;
170-
/// type IntoIter = ::std::vec::IntoIter<i32>;
170+
/// type IntoIter = ::std::vec::IntoIter<Self::Item>;
171171
///
172172
/// fn into_iter(self) -> Self::IntoIter {
173173
/// self.0.into_iter()

src/libcore/iter/traits/exact_size.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
/// # }
4646
/// # impl Iterator for Counter {
4747
/// # type Item = usize;
48-
/// # fn next(&mut self) -> Option<usize> {
48+
/// # fn next(&mut self) -> Option<Self::Item> {
4949
/// # self.count += 1;
5050
/// # if self.count < 6 {
5151
/// # Some(self.count)

src/libcore/ops/arith.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
/// }
2121
///
2222
/// impl Add for Point {
23-
/// type Output = Point;
23+
/// type Output = Self;
2424
///
25-
/// fn add(self, other: Point) -> Point {
26-
/// Point {
25+
/// fn add(self, other: Self) -> Self {
26+
/// Self {
2727
/// x: self.x + other.x,
2828
/// y: self.y + other.y,
2929
/// }
@@ -50,10 +50,10 @@
5050
///
5151
/// // Notice that the implementation uses the associated type `Output`.
5252
/// impl<T: Add<Output = T>> Add for Point<T> {
53-
/// type Output = Point<T>;
53+
/// type Output = Self;
5454
///
55-
/// fn add(self, other: Point<T>) -> Point<T> {
56-
/// Point {
55+
/// fn add(self, other: Self) -> Self::Output {
56+
/// Self {
5757
/// x: self.x + other.x,
5858
/// y: self.y + other.y,
5959
/// }
@@ -158,9 +158,9 @@ add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
158158
///
159159
/// // Notice that the implementation uses the associated type `Output`.
160160
/// impl<T: Sub<Output = T>> Sub for Point<T> {
161-
/// type Output = Point<T>;
161+
/// type Output = Self;
162162
///
163-
/// fn sub(self, other: Point<T>) -> Point<T> {
163+
/// fn sub(self, other: Self) -> Self::Output {
164164
/// Point {
165165
/// x: self.x - other.x,
166166
/// y: self.y - other.y,
@@ -280,9 +280,9 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
280280
/// struct Vector { value: Vec<usize> }
281281
///
282282
/// impl Mul<Scalar> for Vector {
283-
/// type Output = Vector;
283+
/// type Output = Self;
284284
///
285-
/// fn mul(self, rhs: Scalar) -> Vector {
285+
/// fn mul(self, rhs: Scalar) -> Self::Output {
286286
/// Vector { value: self.value.iter().map(|v| v * rhs.value).collect() }
287287
/// }
288288
/// }
@@ -364,7 +364,7 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
364364
/// // The division of rational numbers is a closed operation.
365365
/// type Output = Self;
366366
///
367-
/// fn div(self, rhs: Self) -> Self {
367+
/// fn div(self, rhs: Self) -> Self::Output {
368368
/// if rhs.nominator == 0 {
369369
/// panic!("Cannot divide by zero-valued `Rational`!");
370370
/// }
@@ -404,9 +404,9 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
404404
/// struct Vector { value: Vec<f32> }
405405
///
406406
/// impl Div<Scalar> for Vector {
407-
/// type Output = Vector;
407+
/// type Output = Self;
408408
///
409-
/// fn div(self, rhs: Scalar) -> Vector {
409+
/// fn div(self, rhs: Scalar) -> Self::Output {
410410
/// Vector { value: self.value.iter().map(|v| v / rhs.value).collect() }
411411
/// }
412412
/// }
@@ -485,9 +485,9 @@ div_impl_float! { f32 f64 }
485485
/// }
486486
///
487487
/// impl<'a, T> Rem<usize> for SplitSlice<'a, T> {
488-
/// type Output = SplitSlice<'a, T>;
488+
/// type Output = Self;
489489
///
490-
/// fn rem(self, modulus: usize) -> Self {
490+
/// fn rem(self, modulus: usize) -> Self::Output {
491491
/// let len = self.slice.len();
492492
/// let rem = len % modulus;
493493
/// let start = len - rem;
@@ -571,7 +571,7 @@ rem_impl_float! { f32 f64 }
571571
/// impl Neg for Sign {
572572
/// type Output = Sign;
573573
///
574-
/// fn neg(self) -> Sign {
574+
/// fn neg(self) -> Self::Output {
575575
/// match self {
576576
/// Sign::Negative => Sign::Positive,
577577
/// Sign::Zero => Sign::Zero,
@@ -650,8 +650,8 @@ neg_impl_numeric! { isize i8 i16 i32 i64 i128 f32 f64 }
650650
/// }
651651
///
652652
/// impl AddAssign for Point {
653-
/// fn add_assign(&mut self, other: Point) {
654-
/// *self = Point {
653+
/// fn add_assign(&mut self, other: Self) {
654+
/// *self = Self {
655655
/// x: self.x + other.x,
656656
/// y: self.y + other.y,
657657
/// };
@@ -706,8 +706,8 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
706706
/// }
707707
///
708708
/// impl SubAssign for Point {
709-
/// fn sub_assign(&mut self, other: Point) {
710-
/// *self = Point {
709+
/// fn sub_assign(&mut self, other: Self) {
710+
/// *self = Self {
711711
/// x: self.x - other.x,
712712
/// y: self.y - other.y,
713713
/// };

src/libcore/ops/bit.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/// impl Not for Answer {
1818
/// type Output = Answer;
1919
///
20-
/// fn not(self) -> Answer {
20+
/// fn not(self) -> Self::Output {
2121
/// match self {
2222
/// Answer::Yes => Answer::No,
2323
/// Answer::No => Answer::Yes
@@ -75,7 +75,7 @@ not_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
7575
/// type Output = Self;
7676
///
7777
/// // rhs is the "right-hand side" of the expression `a & b`
78-
/// fn bitand(self, rhs: Self) -> Self {
78+
/// fn bitand(self, rhs: Self) -> Self::Output {
7979
/// Scalar(self.0 & rhs.0)
8080
/// }
8181
/// }
@@ -97,7 +97,7 @@ not_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
9797
/// impl BitAnd for BooleanVector {
9898
/// type Output = Self;
9999
///
100-
/// fn bitand(self, BooleanVector(rhs): Self) -> Self {
100+
/// fn bitand(self, BooleanVector(rhs): Self) -> Self::Output {
101101
/// let BooleanVector(lhs) = self;
102102
/// assert_eq!(lhs.len(), rhs.len());
103103
/// BooleanVector(lhs.iter().zip(rhs.iter()).map(|(x, y)| *x && *y).collect())
@@ -181,7 +181,7 @@ bitand_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
181181
/// impl BitOr for BooleanVector {
182182
/// type Output = Self;
183183
///
184-
/// fn bitor(self, BooleanVector(rhs): Self) -> Self {
184+
/// fn bitor(self, BooleanVector(rhs): Self) -> Self::Output {
185185
/// let BooleanVector(lhs) = self;
186186
/// assert_eq!(lhs.len(), rhs.len());
187187
/// BooleanVector(lhs.iter().zip(rhs.iter()).map(|(x, y)| *x || *y).collect())
@@ -243,7 +243,7 @@ bitor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
243243
/// type Output = Self;
244244
///
245245
/// // rhs is the "right-hand side" of the expression `a ^ b`
246-
/// fn bitxor(self, rhs: Self) -> Self {
246+
/// fn bitxor(self, rhs: Self) -> Self::Output {
247247
/// Scalar(self.0 ^ rhs.0)
248248
/// }
249249
/// }
@@ -265,7 +265,7 @@ bitor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
265265
/// impl BitXor for BooleanVector {
266266
/// type Output = Self;
267267
///
268-
/// fn bitxor(self, BooleanVector(rhs): Self) -> Self {
268+
/// fn bitxor(self, BooleanVector(rhs): Self) -> Self::Output {
269269
/// let BooleanVector(lhs) = self;
270270
/// assert_eq!(lhs.len(), rhs.len());
271271
/// BooleanVector(lhs.iter()
@@ -355,7 +355,7 @@ bitxor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
355355
/// impl<T: Clone> Shl<usize> for SpinVector<T> {
356356
/// type Output = Self;
357357
///
358-
/// fn shl(self, rhs: usize) -> SpinVector<T> {
358+
/// fn shl(self, rhs: usize) -> Self::Output {
359359
/// // Rotate the vector by `rhs` places.
360360
/// let (a, b) = self.vec.split_at(rhs);
361361
/// let mut spun_vector: Vec<T> = vec![];
@@ -464,7 +464,7 @@ shl_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 isize i128 }
464464
/// impl<T: Clone> Shr<usize> for SpinVector<T> {
465465
/// type Output = Self;
466466
///
467-
/// fn shr(self, rhs: usize) -> SpinVector<T> {
467+
/// fn shr(self, rhs: usize) -> Self::Output {
468468
/// // Rotate the vector by `rhs` places.
469469
/// let (a, b) = self.vec.split_at(self.vec.len() - rhs);
470470
/// let mut spun_vector: Vec<T> = vec![];

src/libcore/ops/deref.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
/// impl<T> Deref for DerefExample<T> {
5050
/// type Target = T;
5151
///
52-
/// fn deref(&self) -> &T {
52+
/// fn deref(&self) -> &Self::Target {
5353
/// &self.value
5454
/// }
5555
/// }
@@ -139,13 +139,13 @@ impl<T: ?Sized> Deref for &mut T {
139139
/// impl<T> Deref for DerefMutExample<T> {
140140
/// type Target = T;
141141
///
142-
/// fn deref(&self) -> &T {
142+
/// fn deref(&self) -> &Self::Target {
143143
/// &self.value
144144
/// }
145145
/// }
146146
///
147147
/// impl<T> DerefMut for DerefMutExample<T> {
148-
/// fn deref_mut(&mut self) -> &mut T {
148+
/// fn deref_mut(&mut self) -> &mut Self::Target {
149149
/// &mut self.value
150150
/// }
151151
/// }

src/libcore/ops/index.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
/// impl Index<Nucleotide> for NucleotideCount {
3434
/// type Output = usize;
3535
///
36-
/// fn index(&self, nucleotide: Nucleotide) -> &usize {
36+
/// fn index(&self, nucleotide: Nucleotide) -> &Self::Output {
3737
/// match nucleotide {
3838
/// Nucleotide::A => &self.a,
3939
/// Nucleotide::C => &self.c,
@@ -105,7 +105,7 @@ pub trait Index<Idx: ?Sized> {
105105
/// impl Index<Side> for Balance {
106106
/// type Output = Weight;
107107
///
108-
/// fn index<'a>(&'a self, index: Side) -> &'a Weight {
108+
/// fn index<'a>(&'a self, index: Side) -> &'a Self::Output {
109109
/// println!("Accessing {:?}-side of balance immutably", index);
110110
/// match index {
111111
/// Side::Left => &self.left,
@@ -115,7 +115,7 @@ pub trait Index<Idx: ?Sized> {
115115
/// }
116116
///
117117
/// impl IndexMut<Side> for Balance {
118-
/// fn index_mut<'a>(&'a mut self, index: Side) -> &'a mut Weight {
118+
/// fn index_mut<'a>(&'a mut self, index: Side) -> &'a mut Self::Output {
119119
/// println!("Accessing {:?}-side of balance mutably", index);
120120
/// match index {
121121
/// Side::Left => &mut self.left,

0 commit comments

Comments
 (0)