mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
Add tests and improve checks.
This commit is contained in:
parent
0b168c693a
commit
0ee393cf01
@ -1,4 +1,4 @@
|
|||||||
use crate::utils::{is_entrypoint_fn, match_type, paths, return_ty, span_lint};
|
use crate::utils::{get_trait_def_id, implements_trait, is_entrypoint_fn, match_type, paths, return_ty, span_lint};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc::lint::in_external_macro;
|
use rustc::lint::in_external_macro;
|
||||||
use rustc::ty::TyKind;
|
use rustc::ty::TyKind;
|
||||||
@ -223,19 +223,24 @@ fn lint_for_missing_headers<'a, 'tcx>(
|
|||||||
"docs for function returning `Result` missing `# Errors` section",
|
"docs for function returning `Result` missing `# Errors` section",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
use TyKind::*;
|
|
||||||
let def_id = cx.tcx.hir().local_def_id(hir_id);
|
let def_id = cx.tcx.hir().local_def_id(hir_id);
|
||||||
let mir = cx.tcx.optimized_mir(def_id);
|
let mir = cx.tcx.optimized_mir(def_id);
|
||||||
if let Opaque(_, subs) = mir.return_ty().kind {
|
if let Some(future) = get_trait_def_id(cx, &paths::FUTURE) {
|
||||||
if let Some(ty) = subs.types().next() {
|
if implements_trait(cx, mir.return_ty(), future, &[]) {
|
||||||
if let Generator(_, subs, _) = ty.kind {
|
use TyKind::*;
|
||||||
if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT) {
|
|
||||||
span_lint(
|
if let Opaque(_, subs) = mir.return_ty().kind {
|
||||||
cx,
|
if let Some(ty) = subs.types().next() {
|
||||||
MISSING_ERRORS_DOC,
|
if let Generator(_, subs, _) = ty.kind {
|
||||||
span,
|
if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT) {
|
||||||
"docs for function returning `Result` missing `# Errors` section",
|
span_lint(
|
||||||
);
|
cx,
|
||||||
|
MISSING_ERRORS_DOC,
|
||||||
|
span,
|
||||||
|
"docs for function returning `Result` missing `# Errors` section",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ pub const FMT_ARGUMENTS_NEW_V1_FORMATTED: [&str; 4] = ["core", "fmt", "Arguments
|
|||||||
pub const FMT_ARGUMENTV1_NEW: [&str; 4] = ["core", "fmt", "ArgumentV1", "new"];
|
pub const FMT_ARGUMENTV1_NEW: [&str; 4] = ["core", "fmt", "ArgumentV1", "new"];
|
||||||
pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"];
|
pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"];
|
||||||
pub const FROM_TRAIT: [&str; 3] = ["core", "convert", "From"];
|
pub const FROM_TRAIT: [&str; 3] = ["core", "convert", "From"];
|
||||||
|
pub const FUTURE: [&str; 3] = ["std", "future", "Future"];
|
||||||
pub const HASH: [&str; 2] = ["hash", "Hash"];
|
pub const HASH: [&str; 2] = ["hash", "Hash"];
|
||||||
pub const HASHMAP: [&str; 5] = ["std", "collections", "hash", "map", "HashMap"];
|
pub const HASHMAP: [&str; 5] = ["std", "collections", "hash", "map", "HashMap"];
|
||||||
pub const HASHMAP_ENTRY: [&str; 5] = ["std", "collections", "hash", "map", "Entry"];
|
pub const HASHMAP_ENTRY: [&str; 5] = ["std", "collections", "hash", "map", "Entry"];
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// compile-flags: --edition 2018
|
||||||
#![warn(clippy::missing_errors_doc)]
|
#![warn(clippy::missing_errors_doc)]
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -6,22 +7,42 @@ pub fn pub_fn_missing_errors_header() -> Result<(), ()> {
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
/// This is not sufficiently documented.
|
/// This is not sufficiently documented.
|
||||||
pub fn pub_fn_returning_io_result() -> io::Result<()> {
|
pub fn pub_fn_returning_io_result() -> io::Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This is not sufficiently documented.
|
||||||
|
pub async fn async_pub_fn_returning_io_result() -> io::Result<()> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// A description of the errors goes here.
|
/// A description of the errors goes here.
|
||||||
pub fn pub_fn_with_errors_header() -> Result<(), ()> {
|
pub fn pub_fn_with_errors_header() -> Result<(), ()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// A description of the errors goes here.
|
||||||
|
pub async fn async_pub_fn_with_errors_header() -> Result<(), ()> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
/// This function doesn't require the documentation because it is private
|
/// This function doesn't require the documentation because it is private
|
||||||
fn priv_fn_missing_errors_header() -> Result<(), ()> {
|
fn priv_fn_missing_errors_header() -> Result<(), ()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This function doesn't require the documentation because it is private
|
||||||
|
async fn async_priv_fn_missing_errors_header() -> Result<(), ()> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Struct1;
|
pub struct Struct1;
|
||||||
|
|
||||||
impl Struct1 {
|
impl Struct1 {
|
||||||
@ -30,16 +51,32 @@ impl Struct1 {
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This is not sufficiently documented.
|
||||||
|
pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// A description of the errors goes here.
|
/// A description of the errors goes here.
|
||||||
pub fn pub_method_with_errors_header() -> Result<(), ()> {
|
pub fn pub_method_with_errors_header() -> Result<(), ()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// A description of the errors goes here.
|
||||||
|
pub async fn async_pub_method_with_errors_header() -> Result<(), ()> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
/// This function doesn't require the documentation because it is private.
|
/// This function doesn't require the documentation because it is private.
|
||||||
fn priv_method_missing_errors_header() -> Result<(), ()> {
|
fn priv_method_missing_errors_header() -> Result<(), ()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This function doesn't require the documentation because it is private.
|
||||||
|
async fn async_priv_method_missing_errors_header() -> Result<(), ()> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Trait1 {
|
pub trait Trait1 {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error: docs for function returning `Result` missing `# Errors` section
|
error: docs for function returning `Result` missing `# Errors` section
|
||||||
--> $DIR/doc_errors.rs:5:1
|
--> $DIR/doc_errors.rs:6:1
|
||||||
|
|
|
|
||||||
LL | / pub fn pub_fn_missing_errors_header() -> Result<(), ()> {
|
LL | / pub fn pub_fn_missing_errors_header() -> Result<(), ()> {
|
||||||
LL | | unimplemented!();
|
LL | | unimplemented!();
|
||||||
@ -11,13 +11,29 @@ LL | | }
|
|||||||
error: docs for function returning `Result` missing `# Errors` section
|
error: docs for function returning `Result` missing `# Errors` section
|
||||||
--> $DIR/doc_errors.rs:10:1
|
--> $DIR/doc_errors.rs:10:1
|
||||||
|
|
|
|
||||||
|
LL | / pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> {
|
||||||
|
LL | | unimplemented!();
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
||||||
|
error: docs for function returning `Result` missing `# Errors` section
|
||||||
|
--> $DIR/doc_errors.rs:15:1
|
||||||
|
|
|
||||||
LL | / pub fn pub_fn_returning_io_result() -> io::Result<()> {
|
LL | / pub fn pub_fn_returning_io_result() -> io::Result<()> {
|
||||||
LL | | unimplemented!();
|
LL | | unimplemented!();
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
|
||||||
error: docs for function returning `Result` missing `# Errors` section
|
error: docs for function returning `Result` missing `# Errors` section
|
||||||
--> $DIR/doc_errors.rs:29:5
|
--> $DIR/doc_errors.rs:20:1
|
||||||
|
|
|
||||||
|
LL | / pub async fn async_pub_fn_returning_io_result() -> io::Result<()> {
|
||||||
|
LL | | unimplemented!();
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
||||||
|
error: docs for function returning `Result` missing `# Errors` section
|
||||||
|
--> $DIR/doc_errors.rs:50:5
|
||||||
|
|
|
|
||||||
LL | / pub fn pub_method_missing_errors_header() -> Result<(), ()> {
|
LL | / pub fn pub_method_missing_errors_header() -> Result<(), ()> {
|
||||||
LL | | unimplemented!();
|
LL | | unimplemented!();
|
||||||
@ -25,10 +41,18 @@ LL | | }
|
|||||||
| |_____^
|
| |_____^
|
||||||
|
|
||||||
error: docs for function returning `Result` missing `# Errors` section
|
error: docs for function returning `Result` missing `# Errors` section
|
||||||
--> $DIR/doc_errors.rs:47:5
|
--> $DIR/doc_errors.rs:55:5
|
||||||
|
|
|
||||||
|
LL | / pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> {
|
||||||
|
LL | | unimplemented!();
|
||||||
|
LL | | }
|
||||||
|
| |_____^
|
||||||
|
|
||||||
|
error: docs for function returning `Result` missing `# Errors` section
|
||||||
|
--> $DIR/doc_errors.rs:84:5
|
||||||
|
|
|
|
||||||
LL | fn trait_method_missing_errors_header() -> Result<(), ()>;
|
LL | fn trait_method_missing_errors_header() -> Result<(), ()>;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user