Skip to content

Commit 8eae2eb

Browse files
committed
Auto merge of #86968 - inquisitivecrystal:missing-docs-v2, r=oli-obk
Remove `missing_docs` lint on private 2.0 macros https://github.com/rust-lang/rust/blob/798baebde1fe77e5a660490ec64e727a5d79970d/compiler/rustc_lint/src/builtin.rs#L573-L584 This code is the source of #57569. The problem is subtle, so let me point it out. This code makes the mistake of assuming that all of the macros in `krate.exported_macros` are exported. ...Yeah. For some historical reason, all `macro` macros are marked as exported, regardless of whether they actually are, which is dreadfully confusing. It would be more accurate to say that `exported_macros` currently contains only macros that have paths. This PR renames `exported_macros` to `importable_macros`, since these macros can be imported with `use` while others cannot. It also fixes the code above to no longer lint on private `macro` macros, since the `missing_docs` lint should only appear on exported items. Fixes #57569.
2 parents 8d9d4c8 + b49936c commit 8eae2eb

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

compiler/rustc_lint/src/builtin.rs

+6
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
571571
self.check_missing_docs_attrs(cx, hir::CRATE_HIR_ID, krate.item.inner, "the", "crate");
572572

573573
for macro_def in krate.exported_macros {
574+
// Non exported macros should be skipped, since `missing_docs` only
575+
// applies to externally visible items.
576+
if !cx.access_levels.is_exported(macro_def.hir_id()) {
577+
continue;
578+
}
579+
574580
let attrs = cx.tcx.hir().attrs(macro_def.hir_id());
575581
let has_doc = attrs.iter().any(|a| has_doc(cx.sess(), a));
576582
if !has_doc {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Checks that undocumented private macros will not generate `missing_docs`
2+
// lints, but public ones will.
3+
//
4+
// This is a regression test for issue #57569
5+
#![deny(missing_docs)]
6+
#![feature(decl_macro)]
7+
//! Empty documentation.
8+
9+
macro new_style_private_macro {
10+
() => ()
11+
}
12+
13+
pub(crate) macro new_style_crate_macro {
14+
() => ()
15+
}
16+
17+
macro_rules! old_style_private_macro {
18+
() => ()
19+
}
20+
21+
mod submodule {
22+
pub macro new_style_macro_in_private_module {
23+
() => ()
24+
}
25+
26+
macro_rules! old_style_mod_private_macro {
27+
() => ()
28+
}
29+
30+
#[macro_export]
31+
macro_rules! exported_to_top_level {
32+
//~^ ERROR missing documentation for macro
33+
() => ()
34+
}
35+
}
36+
37+
pub macro top_level_pub_macro {
38+
//~^ ERROR missing documentation for macro
39+
() => ()
40+
}
41+
42+
/// Empty documentation.
43+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: missing documentation for macro
2+
--> $DIR/missing-doc-private-macro.rs:31:5
3+
|
4+
LL | macro_rules! exported_to_top_level {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/missing-doc-private-macro.rs:5:9
9+
|
10+
LL | #![deny(missing_docs)]
11+
| ^^^^^^^^^^^^
12+
13+
error: missing documentation for macro
14+
--> $DIR/missing-doc-private-macro.rs:37:1
15+
|
16+
LL | pub macro top_level_pub_macro {
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error: aborting due to 2 previous errors
20+

0 commit comments

Comments
 (0)