Skip to content

Commit 768ba40

Browse files
committed
Rollup merge of #22730 - ipetkov:lint-docs, r=alexcrichton
This is a breaking change if missing docs are forbidden in any module or crate. I had to add documentation to undocumented associated types in libstd and libcore, please let me know if the documentation is inadequate anywhere! Fixes #20648
2 parents ea72161 + 3fdfbb1 commit 768ba40

File tree

7 files changed

+60
-15
lines changed

7 files changed

+60
-15
lines changed

src/libcore/iter.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ use usize;
8686
#[rustc_on_unimplemented = "`{Self}` is not an iterator; maybe try calling `.iter()` or a similar \
8787
method"]
8888
pub trait Iterator {
89+
/// The type of the elements being iterated
8990
#[stable(feature = "rust1", since = "1.0.0")]
9091
type Item;
9192

@@ -122,9 +123,11 @@ pub trait FromIterator<A> {
122123
/// Conversion into an `Iterator`
123124
#[stable(feature = "rust1", since = "1.0.0")]
124125
pub trait IntoIterator {
126+
/// The type of the elements being iterated
125127
#[stable(feature = "rust1", since = "1.0.0")]
126128
type Item;
127129

130+
/// A container for iterating over elements of type Item
128131
#[stable(feature = "rust1", since = "1.0.0")]
129132
type IntoIter: Iterator<Item=Self::Item>;
130133

src/libcore/ops.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ macro_rules! forward_ref_binop {
184184
#[lang="add"]
185185
#[stable(feature = "rust1", since = "1.0.0")]
186186
pub trait Add<RHS=Self> {
187+
/// The resulting type after applying the `+` operator
187188
#[stable(feature = "rust1", since = "1.0.0")]
188189
type Output;
189190

@@ -237,6 +238,7 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
237238
#[lang="sub"]
238239
#[stable(feature = "rust1", since = "1.0.0")]
239240
pub trait Sub<RHS=Self> {
241+
/// The resulting type after applying the `-` operator
240242
#[stable(feature = "rust1", since = "1.0.0")]
241243
type Output;
242244

@@ -290,6 +292,7 @@ sub_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
290292
#[lang="mul"]
291293
#[stable(feature = "rust1", since = "1.0.0")]
292294
pub trait Mul<RHS=Self> {
295+
/// The resulting type after applying the `*` operator
293296
#[stable(feature = "rust1", since = "1.0.0")]
294297
type Output;
295298

@@ -343,6 +346,7 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
343346
#[lang="div"]
344347
#[stable(feature = "rust1", since = "1.0.0")]
345348
pub trait Div<RHS=Self> {
349+
/// The resulting type after applying the `/` operator
346350
#[stable(feature = "rust1", since = "1.0.0")]
347351
type Output;
348352

@@ -396,6 +400,7 @@ div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
396400
#[lang="rem"]
397401
#[stable(feature = "rust1", since = "1.0.0")]
398402
pub trait Rem<RHS=Self> {
403+
/// The resulting type after applying the `%` operator
399404
#[stable(feature = "rust1", since = "1.0.0")]
400405
type Output = Self;
401406

@@ -468,6 +473,7 @@ rem_float_impl! { f64, fmod }
468473
#[lang="neg"]
469474
#[stable(feature = "rust1", since = "1.0.0")]
470475
pub trait Neg {
476+
/// The resulting type after applying the `-` operator
471477
#[stable(feature = "rust1", since = "1.0.0")]
472478
type Output;
473479

@@ -544,6 +550,7 @@ neg_uint_impl! { u64, i64 }
544550
#[lang="not"]
545551
#[stable(feature = "rust1", since = "1.0.0")]
546552
pub trait Not {
553+
/// The resulting type after applying the `!` operator
547554
#[stable(feature = "rust1", since = "1.0.0")]
548555
type Output;
549556

@@ -597,6 +604,7 @@ not_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
597604
#[lang="bitand"]
598605
#[stable(feature = "rust1", since = "1.0.0")]
599606
pub trait BitAnd<RHS=Self> {
607+
/// The resulting type after applying the `&` operator
600608
#[stable(feature = "rust1", since = "1.0.0")]
601609
type Output;
602610

@@ -650,6 +658,7 @@ bitand_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
650658
#[lang="bitor"]
651659
#[stable(feature = "rust1", since = "1.0.0")]
652660
pub trait BitOr<RHS=Self> {
661+
/// The resulting type after applying the `|` operator
653662
#[stable(feature = "rust1", since = "1.0.0")]
654663
type Output;
655664

@@ -703,6 +712,7 @@ bitor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
703712
#[lang="bitxor"]
704713
#[stable(feature = "rust1", since = "1.0.0")]
705714
pub trait BitXor<RHS=Self> {
715+
/// The resulting type after applying the `^` operator
706716
#[stable(feature = "rust1", since = "1.0.0")]
707717
type Output;
708718

@@ -756,6 +766,7 @@ bitxor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
756766
#[lang="shl"]
757767
#[stable(feature = "rust1", since = "1.0.0")]
758768
pub trait Shl<RHS> {
769+
/// The resulting type after applying the `<<` operator
759770
#[stable(feature = "rust1", since = "1.0.0")]
760771
type Output;
761772

@@ -827,6 +838,7 @@ shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
827838
#[lang="shr"]
828839
#[stable(feature = "rust1", since = "1.0.0")]
829840
pub trait Shr<RHS> {
841+
/// The resulting type after applying the `>>` operator
830842
#[stable(feature = "rust1", since = "1.0.0")]
831843
type Output;
832844

@@ -900,6 +912,7 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
900912
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
901913
#[stable(feature = "rust1", since = "1.0.0")]
902914
pub trait Index<Idx: ?Sized> {
915+
/// The returned type after indexing
903916
type Output: ?Sized;
904917

905918
/// The method for the indexing (`Foo[Bar]`) operation
@@ -1047,6 +1060,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
10471060
#[lang="deref"]
10481061
#[stable(feature = "rust1", since = "1.0.0")]
10491062
pub trait Deref {
1063+
/// The resulting type after dereferencing
10501064
#[stable(feature = "rust1", since = "1.0.0")]
10511065
type Target: ?Sized;
10521066

@@ -1122,6 +1136,7 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T {
11221136
#[stable(feature = "rust1", since = "1.0.0")]
11231137
#[rustc_paren_sugar]
11241138
pub trait Fn<Args> {
1139+
/// The returned type after the call operator is used.
11251140
type Output;
11261141

11271142
/// This is called when the call operator is used.
@@ -1133,6 +1148,7 @@ pub trait Fn<Args> {
11331148
#[stable(feature = "rust1", since = "1.0.0")]
11341149
#[rustc_paren_sugar]
11351150
pub trait FnMut<Args> {
1151+
/// The returned type after the call operator is used.
11361152
type Output;
11371153

11381154
/// This is called when the call operator is used.
@@ -1144,6 +1160,7 @@ pub trait FnMut<Args> {
11441160
#[stable(feature = "rust1", since = "1.0.0")]
11451161
#[rustc_paren_sugar]
11461162
pub trait FnOnce<Args> {
1163+
/// The returned type after the call operator is used.
11471164
type Output;
11481165

11491166
/// This is called when the call operator is used.

src/libcore/ptr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
249249
/// Methods on raw pointers
250250
#[stable(feature = "rust1", since = "1.0.0")]
251251
pub trait PtrExt: Sized {
252+
/// The type which is being pointed at
252253
type Target;
253254

254255
/// Returns true if the pointer is null.
@@ -284,6 +285,7 @@ pub trait PtrExt: Sized {
284285
/// Methods on mutable raw pointers
285286
#[stable(feature = "rust1", since = "1.0.0")]
286287
pub trait MutPtrExt {
288+
/// The type which is being pointed at
287289
type Target;
288290

289291
/// Returns `None` if the pointer is null, or else returns a mutable

src/librustc/lint/builtin.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,14 @@ impl LintPass for MissingDoc {
15771577
tm.span, "a type method");
15781578
}
15791579

1580+
fn check_trait_method(&mut self, cx: &Context, it: &ast::TraitItem) {
1581+
if let ast::TraitItem::TypeTraitItem(ref ty) = *it {
1582+
let assoc_ty = &ty.ty_param;
1583+
self.check_missing_docs_attrs(cx, Some(assoc_ty.id), &ty.attrs,
1584+
assoc_ty.span, "an associated type");
1585+
}
1586+
}
1587+
15801588
fn check_struct_field(&mut self, cx: &Context, sf: &ast::StructField) {
15811589
if let ast::NamedField(_, vis) = sf.node.kind {
15821590
if vis == ast::Public || self.in_variant {

src/libstd/ascii.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub trait OwnedAsciiExt {
3737
/// Extension methods for ASCII-subset only operations on string slices
3838
#[stable(feature = "rust1", since = "1.0.0")]
3939
pub trait AsciiExt {
40+
/// Container type for copied ASCII characters.
4041
#[stable(feature = "rust1", since = "1.0.0")]
4142
type Owned;
4243

src/libstd/collections/hash/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use marker;
2727
/// to `Default` when asked to create a hasher.
2828
#[unstable(feature = "std_misc", reason = "hasher stuff is unclear")]
2929
pub trait HashState {
30+
/// Type of the hasher that will be created.
3031
type Hasher: hash::Hasher;
3132

3233
/// Creates a new hasher based on the given state of this object.

src/test/compile-fail/lint-missing-doc.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
#![doc="More garbage"]
1818

1919
type Typedef = String;
20-
pub type PubTypedef = String; //~ ERROR: missing documentation
20+
pub type PubTypedef = String; //~ ERROR: missing documentation for a type alias
2121

2222
struct Foo {
2323
a: isize,
2424
b: isize,
2525
}
2626

27-
pub struct PubFoo { //~ ERROR: missing documentation
28-
pub a: isize, //~ ERROR: missing documentation
27+
pub struct PubFoo { //~ ERROR: missing documentation for a struct
28+
pub a: isize, //~ ERROR: missing documentation for a struct field
2929
b: isize,
3030
}
3131

@@ -36,11 +36,11 @@ pub struct PubFoo2 {
3636
}
3737

3838
mod module_no_dox {}
39-
pub mod pub_module_no_dox {} //~ ERROR: missing documentation
39+
pub mod pub_module_no_dox {} //~ ERROR: missing documentation for a module
4040

4141
/// dox
4242
pub fn foo() {}
43-
pub fn foo2() {} //~ ERROR: missing documentation
43+
pub fn foo2() {} //~ ERROR: missing documentation for a function
4444
fn foo3() {}
4545
#[allow(missing_docs)] pub fn foo4() {}
4646

@@ -58,23 +58,36 @@ trait B {
5858
fn foo_with_impl(&self) {}
5959
}
6060

61-
pub trait C { //~ ERROR: missing documentation
62-
fn foo(&self); //~ ERROR: missing documentation
63-
fn foo_with_impl(&self) {} //~ ERROR: missing documentation
61+
pub trait C { //~ ERROR: missing documentation for a trait
62+
fn foo(&self); //~ ERROR: missing documentation for a type method
63+
fn foo_with_impl(&self) {} //~ ERROR: missing documentation for a method
6464
}
6565

6666
#[allow(missing_docs)]
6767
pub trait D {
6868
fn dummy(&self) { }
6969
}
7070

71+
/// dox
72+
pub trait E {
73+
type AssociatedType; //~ ERROR: missing documentation for an associated type
74+
type AssociatedTypeDef = Self; //~ ERROR: missing documentation for an associated type
75+
76+
/// dox
77+
type DocumentedType;
78+
/// dox
79+
type DocumentedTypeDef = Self;
80+
/// dox
81+
fn dummy(&self) {}
82+
}
83+
7184
impl Foo {
7285
pub fn foo() {}
7386
fn bar() {}
7487
}
7588

7689
impl PubFoo {
77-
pub fn foo() {} //~ ERROR: missing documentation
90+
pub fn foo() {} //~ ERROR: missing documentation for a method
7891
/// dox
7992
pub fn foo1() {}
8093
fn foo2() {}
@@ -111,9 +124,9 @@ enum Baz {
111124
BarB
112125
}
113126

114-
pub enum PubBaz { //~ ERROR: missing documentation
115-
PubBazA { //~ ERROR: missing documentation
116-
a: isize, //~ ERROR: missing documentation
127+
pub enum PubBaz { //~ ERROR: missing documentation for an enum
128+
PubBazA { //~ ERROR: missing documentation for a variant
129+
a: isize, //~ ERROR: missing documentation for a struct field
117130
},
118131
}
119132

@@ -139,14 +152,14 @@ pub fn baz() {}
139152
mod internal_impl {
140153
/// dox
141154
pub fn documented() {}
142-
pub fn undocumented1() {} //~ ERROR: missing documentation
143-
pub fn undocumented2() {} //~ ERROR: missing documentation
155+
pub fn undocumented1() {} //~ ERROR: missing documentation for a function
156+
pub fn undocumented2() {} //~ ERROR: missing documentation for a function
144157
fn undocumented3() {}
145158
/// dox
146159
pub mod globbed {
147160
/// dox
148161
pub fn also_documented() {}
149-
pub fn also_undocumented1() {} //~ ERROR: missing documentation
162+
pub fn also_undocumented1() {} //~ ERROR: missing documentation for a function
150163
fn also_undocumented2() {}
151164
}
152165
}

0 commit comments

Comments
 (0)