Skip to content

Commit 2c1e796

Browse files
committed
Improve missing create level error message
1 parent 4fd3181 commit 2c1e796

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

src/librustdoc/core.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ pub(crate) fn run_global_ctxt(
407407
crate::lint::MISSING_CRATE_LEVEL_DOCS,
408408
DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(),
409409
|lint| {
410+
if let Some(local_def_id) = krate.module.item_id.as_local_def_id() {
411+
lint.span(tcx.def_span(local_def_id));
412+
}
410413
lint.primary_message("no documentation found for this crate's top-level module");
411414
lint.help(help);
412415
},

tests/rustdoc-ui/lints/check.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ compile-flags: -Z unstable-options --check
33
//@ normalize-stderr: "nightly|beta|1\.[0-9][0-9]\.[0-9]" -> "$$CHANNEL"
44

5-
#![feature(rustdoc_missing_doc_code_examples)]
5+
#![feature(rustdoc_missing_doc_code_examples)] //~ WARN no documentation found for this crate's top-level module
66
//~^ WARN
77

88
#![warn(missing_docs)]
@@ -12,5 +12,3 @@
1212
pub fn foo() {}
1313
//~^ WARN
1414
//~^^ WARN
15-
16-
//~? WARN no documentation found for this crate's top-level module

tests/rustdoc-ui/lints/check.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ LL | pub fn foo() {}
2222
| ^^^^^^^^^^^^
2323

2424
warning: no documentation found for this crate's top-level module
25+
--> $DIR/check.rs:5:1
26+
|
27+
LL | / #![feature(rustdoc_missing_doc_code_examples)]
28+
LL | |
29+
LL | |
30+
LL | | #![warn(missing_docs)]
31+
... |
32+
LL | | pub fn foo() {}
33+
| |_______________^
2534
|
2635
= help: The following guide may be of use:
2736
https://doc.rust-lang.org/$CHANNEL/rustdoc/how-to-write-documentation.html
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ normalize-stderr: "nightly|beta|1\.[0-9][0-9]\.[0-9]" -> "$$CHANNEL"
2-
#![deny(rustdoc::missing_crate_level_docs)]
2+
#![deny(rustdoc::missing_crate_level_docs)] //~ ERROR no documentation found for this crate's top-level module
33
//^~ NOTE defined here
44

55
pub fn foo() {}
6-
7-
//~? ERROR no documentation found for this crate's top-level module

tests/rustdoc-ui/lints/no-crate-level-doc-lint.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
error: no documentation found for this crate's top-level module
2+
--> $DIR/no-crate-level-doc-lint.rs:2:1
3+
|
4+
LL | / #![deny(rustdoc::missing_crate_level_docs)]
5+
... |
6+
LL | | pub fn foo() {}
7+
| |_______________^
28
|
39
= help: The following guide may be of use:
410
https://doc.rust-lang.org/$CHANNEL/rustdoc/how-to-write-documentation.html

0 commit comments

Comments
 (0)