Skip to content

Commit 89c282f

Browse files
committed
Auto merge of rust-lang#6318 - camsteffen:article-description, r=Manishearth
Use article_and_description for missing docs Moves closer to the current rustc missing_doc lint changelog: none
2 parents 3b89a67 + a8c4744 commit 89c282f

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

clippy_lints/src/missing_doc.rs

+33-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// *rustc*'s
33
// [`missing_doc`].
44
//
5-
// [`missing_doc`]: https://github.com/rust-lang/rust/blob/d6d05904697d89099b55da3331155392f1db9c00/src/librustc_lint/builtin.rs#L246
5+
// [`missing_doc`]: https://github.com/rust-lang/rust/blob/cf9cf7c923eb01146971429044f216a3ca905e06/compiler/rustc_lint/src/builtin.rs#L415
66
//
77

88
use crate::utils::span_lint;
@@ -70,7 +70,14 @@ impl MissingDoc {
7070
}
7171
}
7272

73-
fn check_missing_docs_attrs(&self, cx: &LateContext<'_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) {
73+
fn check_missing_docs_attrs(
74+
&self,
75+
cx: &LateContext<'_>,
76+
attrs: &[ast::Attribute],
77+
sp: Span,
78+
article: &'static str,
79+
desc: &'static str,
80+
) {
7481
// If we're building a test harness, then warning about
7582
// documentation is probably not really relevant right now.
7683
if cx.sess().opts.test {
@@ -94,7 +101,7 @@ impl MissingDoc {
94101
cx,
95102
MISSING_DOCS_IN_PRIVATE_ITEMS,
96103
sp,
97-
&format!("missing documentation for {}", desc),
104+
&format!("missing documentation for {} {}", article, desc),
98105
);
99106
}
100107
}
@@ -120,13 +127,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
120127
}
121128

122129
fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
123-
self.check_missing_docs_attrs(cx, &krate.item.attrs, krate.item.span, "crate");
130+
self.check_missing_docs_attrs(cx, &krate.item.attrs, krate.item.span, "the", "crate");
124131
}
125132

126133
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
127-
let desc = match it.kind {
128-
hir::ItemKind::Const(..) => "a constant",
129-
hir::ItemKind::Enum(..) => "an enum",
134+
match it.kind {
130135
hir::ItemKind::Fn(..) => {
131136
// ignore main()
132137
if it.ident.name == sym::main {
@@ -136,34 +141,35 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
136141
return;
137142
}
138143
}
139-
"a function"
140144
},
141-
hir::ItemKind::Mod(..) => "a module",
142-
hir::ItemKind::Static(..) => "a static",
143-
hir::ItemKind::Struct(..) => "a struct",
144-
hir::ItemKind::Trait(..) => "a trait",
145-
hir::ItemKind::TraitAlias(..) => "a trait alias",
146-
hir::ItemKind::TyAlias(..) => "a type alias",
147-
hir::ItemKind::Union(..) => "a union",
148-
hir::ItemKind::OpaqueTy(..) => "an existential type",
145+
hir::ItemKind::Const(..)
146+
| hir::ItemKind::Enum(..)
147+
| hir::ItemKind::Mod(..)
148+
| hir::ItemKind::Static(..)
149+
| hir::ItemKind::Struct(..)
150+
| hir::ItemKind::Trait(..)
151+
| hir::ItemKind::TraitAlias(..)
152+
| hir::ItemKind::TyAlias(..)
153+
| hir::ItemKind::Union(..)
154+
| hir::ItemKind::OpaqueTy(..) => {},
149155
hir::ItemKind::ExternCrate(..)
150156
| hir::ItemKind::ForeignMod { .. }
151157
| hir::ItemKind::GlobalAsm(..)
152158
| hir::ItemKind::Impl { .. }
153159
| hir::ItemKind::Use(..) => return,
154160
};
155161

156-
self.check_missing_docs_attrs(cx, &it.attrs, it.span, desc);
162+
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
163+
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
164+
165+
self.check_missing_docs_attrs(cx, &it.attrs, it.span, article, desc);
157166
}
158167

159168
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) {
160-
let desc = match trait_item.kind {
161-
hir::TraitItemKind::Const(..) => "an associated constant",
162-
hir::TraitItemKind::Fn(..) => "a trait method",
163-
hir::TraitItemKind::Type(..) => "an associated type",
164-
};
169+
let def_id = cx.tcx.hir().local_def_id(trait_item.hir_id);
170+
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
165171

166-
self.check_missing_docs_attrs(cx, &trait_item.attrs, trait_item.span, desc);
172+
self.check_missing_docs_attrs(cx, &trait_item.attrs, trait_item.span, article, desc);
167173
}
168174

169175
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
@@ -178,21 +184,17 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
178184
},
179185
}
180186

181-
let desc = match impl_item.kind {
182-
hir::ImplItemKind::Const(..) => "an associated constant",
183-
hir::ImplItemKind::Fn(..) => "a method",
184-
hir::ImplItemKind::TyAlias(_) => "an associated type",
185-
};
186-
self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, desc);
187+
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
188+
self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, article, desc);
187189
}
188190

189191
fn check_struct_field(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::StructField<'_>) {
190192
if !sf.is_positional() {
191-
self.check_missing_docs_attrs(cx, &sf.attrs, sf.span, "a struct field");
193+
self.check_missing_docs_attrs(cx, &sf.attrs, sf.span, "a", "struct field");
192194
}
193195
}
194196

195197
fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) {
196-
self.check_missing_docs_attrs(cx, &v.attrs, v.span, "a variant");
198+
self.check_missing_docs_attrs(cx, &v.attrs, v.span, "a", "variant");
197199
}
198200
}

tests/ui/missing-doc-crate-missing.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: missing documentation for crate
1+
error: missing documentation for the crate
22
--> $DIR/missing-doc-crate-missing.rs:1:1
33
|
44
LL | / #![warn(clippy::missing_docs_in_private_items)]

tests/ui/missing-doc-impl.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ LL | | fn foo_with_impl(&self) {}
5151
LL | | }
5252
| |_^
5353

54-
error: missing documentation for a trait method
54+
error: missing documentation for an associated function
5555
--> $DIR/missing-doc-impl.rs:39:5
5656
|
5757
LL | fn foo(&self);
5858
| ^^^^^^^^^^^^^^
5959

60-
error: missing documentation for a trait method
60+
error: missing documentation for an associated function
6161
--> $DIR/missing-doc-impl.rs:40:5
6262
|
6363
LL | fn foo_with_impl(&self) {}
@@ -75,25 +75,25 @@ error: missing documentation for an associated type
7575
LL | type AssociatedTypeDef = Self;
7676
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7777

78-
error: missing documentation for a method
78+
error: missing documentation for an associated function
7979
--> $DIR/missing-doc-impl.rs:62:5
8080
|
8181
LL | pub fn foo() {}
8282
| ^^^^^^^^^^^^^^^
8383

84-
error: missing documentation for a method
84+
error: missing documentation for an associated function
8585
--> $DIR/missing-doc-impl.rs:63:5
8686
|
8787
LL | fn bar() {}
8888
| ^^^^^^^^^^^
8989

90-
error: missing documentation for a method
90+
error: missing documentation for an associated function
9191
--> $DIR/missing-doc-impl.rs:67:5
9292
|
9393
LL | pub fn foo() {}
9494
| ^^^^^^^^^^^^^^^
9595

96-
error: missing documentation for a method
96+
error: missing documentation for an associated function
9797
--> $DIR/missing-doc-impl.rs:70:5
9898
|
9999
LL | fn foo2() {}

0 commit comments

Comments
 (0)