shrink missing_{safety,errors,panics}_doc spans

This commit is contained in:
Lukas Markeffsky
2022-11-02 12:47:46 +01:00
parent 7600535511
commit d35b7de1d5
4 changed files with 45 additions and 103 deletions

View File

@@ -11,7 +11,7 @@ use rustc_ast::token::CommentKind;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_errors::emitter::EmitterWriter; use rustc_errors::emitter::EmitterWriter;
use rustc_errors::{Applicability, Handler, MultiSpan, SuggestionStyle}; use rustc_errors::{Applicability, Handler, SuggestionStyle};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{AnonConst, Expr}; use rustc_hir::{AnonConst, Expr};
@@ -265,15 +265,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
panic_span: None, panic_span: None,
}; };
fpu.visit_expr(body.value); fpu.visit_expr(body.value);
lint_for_missing_headers( lint_for_missing_headers(cx, item.def_id.def_id, sig, headers, Some(body_id), fpu.panic_span);
cx,
item.def_id.def_id,
item.span,
sig,
headers,
Some(body_id),
fpu.panic_span,
);
} }
}, },
hir::ItemKind::Impl(impl_) => { hir::ItemKind::Impl(impl_) => {
@@ -284,7 +276,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
span_lint( span_lint(
cx, cx,
MISSING_SAFETY_DOC, MISSING_SAFETY_DOC,
item.span, cx.tcx.def_span(item.def_id),
"docs for unsafe trait missing `# Safety` section", "docs for unsafe trait missing `# Safety` section",
); );
} }
@@ -304,7 +296,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let headers = check_attrs(cx, &self.valid_idents, attrs); let headers = check_attrs(cx, &self.valid_idents, attrs);
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
if !in_external_macro(cx.tcx.sess, item.span) { if !in_external_macro(cx.tcx.sess, item.span) {
lint_for_missing_headers(cx, item.def_id.def_id, item.span, sig, headers, None, None); lint_for_missing_headers(cx, item.def_id.def_id, sig, headers, None, None);
} }
} }
} }
@@ -323,15 +315,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
panic_span: None, panic_span: None,
}; };
fpu.visit_expr(body.value); fpu.visit_expr(body.value);
lint_for_missing_headers( lint_for_missing_headers(cx, item.def_id.def_id, sig, headers, Some(body_id), fpu.panic_span);
cx,
item.def_id.def_id,
item.span,
sig,
headers,
Some(body_id),
fpu.panic_span,
);
} }
} }
} }
@@ -339,7 +323,6 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
fn lint_for_missing_headers( fn lint_for_missing_headers(
cx: &LateContext<'_>, cx: &LateContext<'_>,
def_id: LocalDefId, def_id: LocalDefId,
span: impl Into<MultiSpan> + Copy,
sig: &hir::FnSig<'_>, sig: &hir::FnSig<'_>,
headers: DocHeaders, headers: DocHeaders,
body_id: Option<hir::BodyId>, body_id: Option<hir::BodyId>,
@@ -359,6 +342,8 @@ fn lint_for_missing_headers(
return; return;
} }
let span = cx.tcx.def_span(def_id);
if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe { if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe {
span_lint( span_lint(
cx, cx,

View File

@@ -1,52 +1,40 @@
error: docs for function returning `Result` missing `# Errors` section error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:7:1 --> $DIR/doc_errors.rs:7:1
| |
LL | / pub fn pub_fn_missing_errors_header() -> Result<(), ()> { LL | pub fn pub_fn_missing_errors_header() -> Result<(), ()> {
LL | | unimplemented!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_^
| |
= note: `-D clippy::missing-errors-doc` implied by `-D warnings` = note: `-D clippy::missing-errors-doc` implied by `-D warnings`
error: docs for function returning `Result` missing `# Errors` section error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:11:1 --> $DIR/doc_errors.rs:11:1
| |
LL | / pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { LL | pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> {
LL | | unimplemented!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_^
error: docs for function returning `Result` missing `# Errors` section error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:16:1 --> $DIR/doc_errors.rs:16:1
| |
LL | / pub fn pub_fn_returning_io_result() -> io::Result<()> { LL | pub fn pub_fn_returning_io_result() -> io::Result<()> {
LL | | unimplemented!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_^
error: docs for function returning `Result` missing `# Errors` section error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:21:1 --> $DIR/doc_errors.rs:21:1
| |
LL | / pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { LL | pub async fn async_pub_fn_returning_io_result() -> io::Result<()> {
LL | | unimplemented!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_^
error: docs for function returning `Result` missing `# Errors` section error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:51:5 --> $DIR/doc_errors.rs:51:5
| |
LL | / pub fn pub_method_missing_errors_header() -> Result<(), ()> { LL | pub fn pub_method_missing_errors_header() -> Result<(), ()> {
LL | | unimplemented!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_____^
error: docs for function returning `Result` missing `# Errors` section error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:56:5 --> $DIR/doc_errors.rs:56:5
| |
LL | / pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> {
LL | | unimplemented!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_____^
error: docs for function returning `Result` missing `# Errors` section error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:85:5 --> $DIR/doc_errors.rs:85:5

View File

@@ -1,20 +1,16 @@
error: unsafe function's docs miss `# Safety` section error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:9:1 --> $DIR/doc_unsafe.rs:9:1
| |
LL | / pub unsafe fn destroy_the_planet() { LL | pub unsafe fn destroy_the_planet() {
LL | | unimplemented!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_^
| |
= note: `-D clippy::missing-safety-doc` implied by `-D warnings` = note: `-D clippy::missing-safety-doc` implied by `-D warnings`
error: unsafe function's docs miss `# Safety` section error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:32:5 --> $DIR/doc_unsafe.rs:32:5
| |
LL | / pub unsafe fn republished() { LL | pub unsafe fn republished() {
LL | | unimplemented!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_____^
error: unsafe function's docs miss `# Safety` section error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:40:5 --> $DIR/doc_unsafe.rs:40:5
@@ -25,29 +21,23 @@ LL | unsafe fn woefully_underdocumented(self);
error: docs for unsafe trait missing `# Safety` section error: docs for unsafe trait missing `# Safety` section
--> $DIR/doc_unsafe.rs:46:1 --> $DIR/doc_unsafe.rs:46:1
| |
LL | / pub unsafe trait UnsafeTrait { LL | pub unsafe trait UnsafeTrait {
LL | | fn method(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_^
error: unsafe function's docs miss `# Safety` section error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:76:5 --> $DIR/doc_unsafe.rs:76:5
| |
LL | / pub unsafe fn more_undocumented_unsafe() -> Self { LL | pub unsafe fn more_undocumented_unsafe() -> Self {
LL | | unimplemented!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_____^
error: unsafe function's docs miss `# Safety` section error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:92:9 --> $DIR/doc_unsafe.rs:92:9
| |
LL | / pub unsafe fn whee() { LL | pub unsafe fn whee() {
LL | | unimplemented!() | ^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_________^
... ...
LL | very_unsafe!(); LL | very_unsafe!();
| -------------- in this macro invocation | -------------- in this macro invocation
| |
= note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@@ -1,11 +1,8 @@
error: docs for function which may panic missing `# Panics` section error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:6:1 --> $DIR/missing_panics_doc.rs:6:1
| |
LL | / pub fn unwrap() { LL | pub fn unwrap() {
LL | | let result = Err("Hi"); | ^^^^^^^^^^^^^^^
LL | | result.unwrap()
LL | | }
| |_^
| |
note: first possible panic found here note: first possible panic found here
--> $DIR/missing_panics_doc.rs:8:5 --> $DIR/missing_panics_doc.rs:8:5
@@ -17,10 +14,8 @@ LL | result.unwrap()
error: docs for function which may panic missing `# Panics` section error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:12:1 --> $DIR/missing_panics_doc.rs:12:1
| |
LL | / pub fn panic() { LL | pub fn panic() {
LL | | panic!("This function panics") | ^^^^^^^^^^^^^^
LL | | }
| |_^
| |
note: first possible panic found here note: first possible panic found here
--> $DIR/missing_panics_doc.rs:13:5 --> $DIR/missing_panics_doc.rs:13:5
@@ -31,10 +26,8 @@ LL | panic!("This function panics")
error: docs for function which may panic missing `# Panics` section error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:17:1 --> $DIR/missing_panics_doc.rs:17:1
| |
LL | / pub fn todo() { LL | pub fn todo() {
LL | | todo!() | ^^^^^^^^^^^^^
LL | | }
| |_^
| |
note: first possible panic found here note: first possible panic found here
--> $DIR/missing_panics_doc.rs:18:5 --> $DIR/missing_panics_doc.rs:18:5
@@ -45,14 +38,8 @@ LL | todo!()
error: docs for function which may panic missing `# Panics` section error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:22:1 --> $DIR/missing_panics_doc.rs:22:1
| |
LL | / pub fn inner_body(opt: Option<u32>) { LL | pub fn inner_body(opt: Option<u32>) {
LL | | opt.map(|x| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | if x == 10 {
LL | | panic!()
LL | | }
LL | | });
LL | | }
| |_^
| |
note: first possible panic found here note: first possible panic found here
--> $DIR/missing_panics_doc.rs:25:13 --> $DIR/missing_panics_doc.rs:25:13
@@ -63,10 +50,8 @@ LL | panic!()
error: docs for function which may panic missing `# Panics` section error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:31:1 --> $DIR/missing_panics_doc.rs:31:1
| |
LL | / pub fn unreachable_and_panic() { LL | pub fn unreachable_and_panic() {
LL | | if true { unreachable!() } else { panic!() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | | }
| |_^
| |
note: first possible panic found here note: first possible panic found here
--> $DIR/missing_panics_doc.rs:32:39 --> $DIR/missing_panics_doc.rs:32:39
@@ -77,11 +62,8 @@ LL | if true { unreachable!() } else { panic!() }
error: docs for function which may panic missing `# Panics` section error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:36:1 --> $DIR/missing_panics_doc.rs:36:1
| |
LL | / pub fn assert_eq() { LL | pub fn assert_eq() {
LL | | let x = 0; | ^^^^^^^^^^^^^^^^^^
LL | | assert_eq!(x, 0);
LL | | }
| |_^
| |
note: first possible panic found here note: first possible panic found here
--> $DIR/missing_panics_doc.rs:38:5 --> $DIR/missing_panics_doc.rs:38:5
@@ -92,11 +74,8 @@ LL | assert_eq!(x, 0);
error: docs for function which may panic missing `# Panics` section error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:42:1 --> $DIR/missing_panics_doc.rs:42:1
| |
LL | / pub fn assert_ne() { LL | pub fn assert_ne() {
LL | | let x = 0; | ^^^^^^^^^^^^^^^^^^
LL | | assert_ne!(x, 0);
LL | | }
| |_^
| |
note: first possible panic found here note: first possible panic found here
--> $DIR/missing_panics_doc.rs:44:5 --> $DIR/missing_panics_doc.rs:44:5