shrink `missing_{safety,errors,panics}_doc` spans
This commit is contained in:
parent
7600535511
commit
d35b7de1d5
|
@ -11,7 +11,7 @@ use rustc_ast::token::CommentKind;
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
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::intravisit::{self, Visitor};
|
||||
use rustc_hir::{AnonConst, Expr};
|
||||
|
@ -265,15 +265,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
|||
panic_span: None,
|
||||
};
|
||||
fpu.visit_expr(body.value);
|
||||
lint_for_missing_headers(
|
||||
cx,
|
||||
item.def_id.def_id,
|
||||
item.span,
|
||||
sig,
|
||||
headers,
|
||||
Some(body_id),
|
||||
fpu.panic_span,
|
||||
);
|
||||
lint_for_missing_headers(cx, item.def_id.def_id, sig, headers, Some(body_id), fpu.panic_span);
|
||||
}
|
||||
},
|
||||
hir::ItemKind::Impl(impl_) => {
|
||||
|
@ -284,7 +276,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
|||
span_lint(
|
||||
cx,
|
||||
MISSING_SAFETY_DOC,
|
||||
item.span,
|
||||
cx.tcx.def_span(item.def_id),
|
||||
"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);
|
||||
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
|
||||
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,
|
||||
};
|
||||
fpu.visit_expr(body.value);
|
||||
lint_for_missing_headers(
|
||||
cx,
|
||||
item.def_id.def_id,
|
||||
item.span,
|
||||
sig,
|
||||
headers,
|
||||
Some(body_id),
|
||||
fpu.panic_span,
|
||||
);
|
||||
lint_for_missing_headers(cx, item.def_id.def_id, sig, headers, Some(body_id), fpu.panic_span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -339,7 +323,6 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
|||
fn lint_for_missing_headers(
|
||||
cx: &LateContext<'_>,
|
||||
def_id: LocalDefId,
|
||||
span: impl Into<MultiSpan> + Copy,
|
||||
sig: &hir::FnSig<'_>,
|
||||
headers: DocHeaders,
|
||||
body_id: Option<hir::BodyId>,
|
||||
|
@ -359,6 +342,8 @@ fn lint_for_missing_headers(
|
|||
return;
|
||||
}
|
||||
|
||||
let span = cx.tcx.def_span(def_id);
|
||||
|
||||
if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe {
|
||||
span_lint(
|
||||
cx,
|
||||
|
|
|
@ -1,52 +1,40 @@
|
|||
error: docs for function returning `Result` missing `# Errors` section
|
||||
--> $DIR/doc_errors.rs:7:1
|
||||
|
|
||||
LL | / pub fn pub_fn_missing_errors_header() -> Result<(), ()> {
|
||||
LL | | unimplemented!();
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn pub_fn_missing_errors_header() -> Result<(), ()> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::missing-errors-doc` implied by `-D warnings`
|
||||
|
||||
error: docs for function returning `Result` missing `# Errors` section
|
||||
--> $DIR/doc_errors.rs:11:1
|
||||
|
|
||||
LL | / pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> {
|
||||
LL | | unimplemented!();
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: docs for function returning `Result` missing `# Errors` section
|
||||
--> $DIR/doc_errors.rs:16:1
|
||||
|
|
||||
LL | / pub fn pub_fn_returning_io_result() -> io::Result<()> {
|
||||
LL | | unimplemented!();
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn pub_fn_returning_io_result() -> io::Result<()> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: docs for function returning `Result` missing `# Errors` section
|
||||
--> $DIR/doc_errors.rs:21:1
|
||||
|
|
||||
LL | / pub async fn async_pub_fn_returning_io_result() -> io::Result<()> {
|
||||
LL | | unimplemented!();
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub async fn async_pub_fn_returning_io_result() -> io::Result<()> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: docs for function returning `Result` missing `# Errors` section
|
||||
--> $DIR/doc_errors.rs:51:5
|
||||
|
|
||||
LL | / pub fn pub_method_missing_errors_header() -> Result<(), ()> {
|
||||
LL | | unimplemented!();
|
||||
LL | | }
|
||||
| |_____^
|
||||
LL | pub fn pub_method_missing_errors_header() -> Result<(), ()> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: docs for function returning `Result` missing `# Errors` section
|
||||
--> $DIR/doc_errors.rs:56:5
|
||||
|
|
||||
LL | / pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> {
|
||||
LL | | unimplemented!();
|
||||
LL | | }
|
||||
| |_____^
|
||||
LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: docs for function returning `Result` missing `# Errors` section
|
||||
--> $DIR/doc_errors.rs:85:5
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
error: unsafe function's docs miss `# Safety` section
|
||||
--> $DIR/doc_unsafe.rs:9:1
|
||||
|
|
||||
LL | / pub unsafe fn destroy_the_planet() {
|
||||
LL | | unimplemented!();
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub unsafe fn destroy_the_planet() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::missing-safety-doc` implied by `-D warnings`
|
||||
|
||||
error: unsafe function's docs miss `# Safety` section
|
||||
--> $DIR/doc_unsafe.rs:32:5
|
||||
|
|
||||
LL | / pub unsafe fn republished() {
|
||||
LL | | unimplemented!();
|
||||
LL | | }
|
||||
| |_____^
|
||||
LL | pub unsafe fn republished() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unsafe function's docs miss `# Safety` section
|
||||
--> $DIR/doc_unsafe.rs:40:5
|
||||
|
@ -25,29 +21,23 @@ LL | unsafe fn woefully_underdocumented(self);
|
|||
error: docs for unsafe trait missing `# Safety` section
|
||||
--> $DIR/doc_unsafe.rs:46:1
|
||||
|
|
||||
LL | / pub unsafe trait UnsafeTrait {
|
||||
LL | | fn method();
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub unsafe trait UnsafeTrait {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unsafe function's docs miss `# Safety` section
|
||||
--> $DIR/doc_unsafe.rs:76:5
|
||||
|
|
||||
LL | / pub unsafe fn more_undocumented_unsafe() -> Self {
|
||||
LL | | unimplemented!();
|
||||
LL | | }
|
||||
| |_____^
|
||||
LL | pub unsafe fn more_undocumented_unsafe() -> Self {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unsafe function's docs miss `# Safety` section
|
||||
--> $DIR/doc_unsafe.rs:92:9
|
||||
|
|
||||
LL | / pub unsafe fn whee() {
|
||||
LL | | unimplemented!()
|
||||
LL | | }
|
||||
| |_________^
|
||||
LL | pub unsafe fn whee() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | very_unsafe!();
|
||||
| -------------- in this macro invocation
|
||||
LL | very_unsafe!();
|
||||
| -------------- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error: docs for function which may panic missing `# Panics` section
|
||||
--> $DIR/missing_panics_doc.rs:6:1
|
||||
|
|
||||
LL | / pub fn unwrap() {
|
||||
LL | | let result = Err("Hi");
|
||||
LL | | result.unwrap()
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn unwrap() {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: first possible panic found here
|
||||
--> $DIR/missing_panics_doc.rs:8:5
|
||||
|
@ -17,10 +14,8 @@ LL | result.unwrap()
|
|||
error: docs for function which may panic missing `# Panics` section
|
||||
--> $DIR/missing_panics_doc.rs:12:1
|
||||
|
|
||||
LL | / pub fn panic() {
|
||||
LL | | panic!("This function panics")
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn panic() {
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: first possible panic found here
|
||||
--> $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
|
||||
--> $DIR/missing_panics_doc.rs:17:1
|
||||
|
|
||||
LL | / pub fn todo() {
|
||||
LL | | todo!()
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn todo() {
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: first possible panic found here
|
||||
--> $DIR/missing_panics_doc.rs:18:5
|
||||
|
@ -45,14 +38,8 @@ LL | todo!()
|
|||
error: docs for function which may panic missing `# Panics` section
|
||||
--> $DIR/missing_panics_doc.rs:22:1
|
||||
|
|
||||
LL | / pub fn inner_body(opt: Option<u32>) {
|
||||
LL | | opt.map(|x| {
|
||||
LL | | if x == 10 {
|
||||
LL | | panic!()
|
||||
LL | | }
|
||||
LL | | });
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn inner_body(opt: Option<u32>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: first possible panic found here
|
||||
--> $DIR/missing_panics_doc.rs:25:13
|
||||
|
@ -63,10 +50,8 @@ LL | panic!()
|
|||
error: docs for function which may panic missing `# Panics` section
|
||||
--> $DIR/missing_panics_doc.rs:31:1
|
||||
|
|
||||
LL | / pub fn unreachable_and_panic() {
|
||||
LL | | if true { unreachable!() } else { panic!() }
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn unreachable_and_panic() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: first possible panic found here
|
||||
--> $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
|
||||
--> $DIR/missing_panics_doc.rs:36:1
|
||||
|
|
||||
LL | / pub fn assert_eq() {
|
||||
LL | | let x = 0;
|
||||
LL | | assert_eq!(x, 0);
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn assert_eq() {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: first possible panic found here
|
||||
--> $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
|
||||
--> $DIR/missing_panics_doc.rs:42:1
|
||||
|
|
||||
LL | / pub fn assert_ne() {
|
||||
LL | | let x = 0;
|
||||
LL | | assert_ne!(x, 0);
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn assert_ne() {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: first possible panic found here
|
||||
--> $DIR/missing_panics_doc.rs:44:5
|
||||
|
|
Loading…
Reference in New Issue