Skip to content

Commit 1a5ad59

Browse files
authored
Rollup merge of rust-lang#69740 - mark-i-m:describe-it-3, r=eddyb
Replace some desc logic in librustc_lint with article_and_desc r? @eddyb @Centril @matthewjasper Followup to rust-lang#69674 Blocked on rust-lang#69498
2 parents ed3d9e7 + 5e8b795 commit 1a5ad59

10 files changed

+50
-46
lines changed

src/librustc_lint/builtin.rs

+37-33
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ impl MissingDoc {
349349
id: Option<hir::HirId>,
350350
attrs: &[ast::Attribute],
351351
sp: Span,
352+
article: &'static str,
352353
desc: &'static str,
353354
) {
354355
// If we're building a test harness, then warning about
@@ -374,7 +375,7 @@ impl MissingDoc {
374375
let has_doc = attrs.iter().any(|a| has_doc(a));
375376
if !has_doc {
376377
cx.struct_span_lint(MISSING_DOCS, cx.tcx.sess.source_map().def_span(sp), |lint| {
377-
lint.build(&format!("missing documentation for {}", desc)).emit()
378+
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
378379
});
379380
}
380381
}
@@ -398,7 +399,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
398399
}
399400

400401
fn check_crate(&mut self, cx: &LateContext<'_, '_>, krate: &hir::Crate<'_>) {
401-
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "crate");
402+
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "the", "crate");
402403

403404
for macro_def in krate.exported_macros {
404405
let has_doc = macro_def.attrs.iter().any(|a| has_doc(a));
@@ -413,12 +414,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
413414
}
414415

415416
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
416-
let desc = match it.kind {
417-
hir::ItemKind::Fn(..) => "a function",
418-
hir::ItemKind::Mod(..) => "a module",
419-
hir::ItemKind::Enum(..) => "an enum",
420-
hir::ItemKind::Struct(..) => "a struct",
421-
hir::ItemKind::Union(..) => "a union",
417+
match it.kind {
422418
hir::ItemKind::Trait(.., trait_item_refs) => {
423419
// Issue #11592: traits are always considered exported, even when private.
424420
if let hir::VisibilityKind::Inherited = it.vis.node {
@@ -428,51 +424,55 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
428424
}
429425
return;
430426
}
431-
"a trait"
432427
}
433-
hir::ItemKind::TyAlias(..) => "a type alias",
434428
hir::ItemKind::Impl { of_trait: Some(ref trait_ref), items, .. } => {
435429
// If the trait is private, add the impl items to `private_traits` so they don't get
436430
// reported for missing docs.
437431
let real_trait = trait_ref.path.res.def_id();
438432
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) {
439-
match cx.tcx.hir().find(hir_id) {
440-
Some(Node::Item(item)) => {
441-
if let hir::VisibilityKind::Inherited = item.vis.node {
442-
for impl_item_ref in items {
443-
self.private_traits.insert(impl_item_ref.id.hir_id);
444-
}
433+
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
434+
if let hir::VisibilityKind::Inherited = item.vis.node {
435+
for impl_item_ref in items {
436+
self.private_traits.insert(impl_item_ref.id.hir_id);
445437
}
446438
}
447-
_ => {}
448439
}
449440
}
450441
return;
451442
}
452-
hir::ItemKind::Const(..) => "a constant",
453-
hir::ItemKind::Static(..) => "a static",
443+
444+
hir::ItemKind::TyAlias(..)
445+
| hir::ItemKind::Fn(..)
446+
| hir::ItemKind::Mod(..)
447+
| hir::ItemKind::Enum(..)
448+
| hir::ItemKind::Struct(..)
449+
| hir::ItemKind::Union(..)
450+
| hir::ItemKind::Const(..)
451+
| hir::ItemKind::Static(..) => {}
452+
454453
_ => return,
455454
};
456455

457-
self.check_missing_docs_attrs(cx, Some(it.hir_id), &it.attrs, it.span, desc);
456+
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
457+
let (article, desc) = cx.tcx.article_and_description(def_id);
458+
459+
self.check_missing_docs_attrs(cx, Some(it.hir_id), &it.attrs, it.span, article, desc);
458460
}
459461

460462
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, trait_item: &hir::TraitItem<'_>) {
461463
if self.private_traits.contains(&trait_item.hir_id) {
462464
return;
463465
}
464466

465-
let desc = match trait_item.kind {
466-
hir::TraitItemKind::Const(..) => "an associated constant",
467-
hir::TraitItemKind::Fn(..) => "a trait method",
468-
hir::TraitItemKind::Type(..) => "an associated type",
469-
};
467+
let def_id = cx.tcx.hir().local_def_id(trait_item.hir_id);
468+
let (article, desc) = cx.tcx.article_and_description(def_id);
470469

471470
self.check_missing_docs_attrs(
472471
cx,
473472
Some(trait_item.hir_id),
474473
&trait_item.attrs,
475474
trait_item.span,
475+
article,
476476
desc,
477477
);
478478
}
@@ -483,29 +483,33 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
483483
return;
484484
}
485485

486-
let desc = match impl_item.kind {
487-
hir::ImplItemKind::Const(..) => "an associated constant",
488-
hir::ImplItemKind::Fn(..) => "a method",
489-
hir::ImplItemKind::TyAlias(_) => "an associated type",
490-
hir::ImplItemKind::OpaqueTy(_) => "an associated `impl Trait` type",
491-
};
486+
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
487+
let (article, desc) = cx.tcx.article_and_description(def_id);
492488
self.check_missing_docs_attrs(
493489
cx,
494490
Some(impl_item.hir_id),
495491
&impl_item.attrs,
496492
impl_item.span,
493+
article,
497494
desc,
498495
);
499496
}
500497

501498
fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, sf: &hir::StructField<'_>) {
502499
if !sf.is_positional() {
503-
self.check_missing_docs_attrs(cx, Some(sf.hir_id), &sf.attrs, sf.span, "a struct field")
500+
self.check_missing_docs_attrs(
501+
cx,
502+
Some(sf.hir_id),
503+
&sf.attrs,
504+
sf.span,
505+
"a",
506+
"struct field",
507+
)
504508
}
505509
}
506510

507511
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant<'_>) {
508-
self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, v.span, "a variant");
512+
self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, v.span, "a", "variant");
509513
}
510514
}
511515

src/test/rustdoc-ui/deny-missing-docs-crate.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/deny-missing-docs-crate.rs:1:1
33
|
44
LL | / #![deny(missing_docs)]

src/test/ui/issues/issue-10656.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#![deny(missing_docs)]
22
#![crate_type="lib"]
3-
//~^^ ERROR missing documentation for crate
3+
//~^^ ERROR missing documentation for the crate

src/test/ui/issues/issue-10656.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/issue-10656.rs:1:1
33
|
44
LL | / #![deny(missing_docs)]

src/test/ui/lint/lint-missing-doc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ trait B {
5050
}
5151

5252
pub trait C { //~ ERROR: missing documentation for a trait
53-
fn foo(&self); //~ ERROR: missing documentation for a trait method
54-
fn foo_with_impl(&self) {} //~ ERROR: missing documentation for a trait method
53+
fn foo(&self); //~ ERROR: missing documentation for an associated function
54+
fn foo_with_impl(&self) {} //~ ERROR: missing documentation for an associated function
5555
}
5656

5757
#[allow(missing_docs)]
@@ -78,7 +78,7 @@ impl Foo {
7878
}
7979

8080
impl PubFoo {
81-
pub fn foo() {} //~ ERROR: missing documentation for a method
81+
pub fn foo() {} //~ ERROR: missing documentation for an associated function
8282
/// dox
8383
pub fn foo1() {}
8484
fn foo2() {}

src/test/ui/lint/lint-missing-doc.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ error: missing documentation for a trait
4040
LL | pub trait C {
4141
| ^^^^^^^^^^^
4242

43-
error: missing documentation for a trait method
43+
error: missing documentation for an associated function
4444
--> $DIR/lint-missing-doc.rs:53:5
4545
|
4646
LL | fn foo(&self);
4747
| ^^^^^^^^^^^^^^
4848

49-
error: missing documentation for a trait method
49+
error: missing documentation for an associated function
5050
--> $DIR/lint-missing-doc.rs:54:5
5151
|
5252
LL | fn foo_with_impl(&self) {}
@@ -64,7 +64,7 @@ error: missing documentation for an associated type
6464
LL | type AssociatedTypeDef = Self;
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6666

67-
error: missing documentation for a method
67+
error: missing documentation for an associated function
6868
--> $DIR/lint-missing-doc.rs:81:5
6969
|
7070
LL | pub fn foo() {}

src/test/ui/lint/lints-in-foreign-macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// aux-build:lints-in-foreign-macros.rs
22
// check-pass
33

4-
#![warn(unused_imports)] //~ missing documentation for crate [missing_docs]
4+
#![warn(unused_imports)] //~ missing documentation for the crate [missing_docs]
55
#![warn(missing_docs)]
66

77
#[macro_use]

src/test/ui/lint/lints-in-foreign-macros.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ warning: unused import: `std::string::ToString`
2626
LL | mod d { baz2!(use std::string::ToString;); }
2727
| ^^^^^^^^^^^^^^^^^^^^^
2828

29-
warning: missing documentation for crate
29+
warning: missing documentation for the crate
3030
--> $DIR/lints-in-foreign-macros.rs:4:1
3131
|
3232
LL | / #![warn(unused_imports)]

src/test/ui/privacy/private-in-public-non-principal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loo
1010
#[deny(missing_docs)]
1111
fn container() {
1212
impl dyn PubPrincipal {
13-
pub fn check_doc_lint() {} //~ ERROR missing documentation for a method
13+
pub fn check_doc_lint() {} //~ ERROR missing documentation for an associated function
1414
}
1515
impl dyn PubPrincipal + PrivNonPrincipal {
1616
pub fn check_doc_lint() {} // OK, no missing doc lint

src/test/ui/privacy/private-in-public-non-principal.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal>
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
1010

11-
error: missing documentation for a method
11+
error: missing documentation for an associated function
1212
--> $DIR/private-in-public-non-principal.rs:13:9
1313
|
1414
LL | pub fn check_doc_lint() {}

0 commit comments

Comments
 (0)