removing if chain and renaming lint
This commit is contained in:
parent
f9fcbbea03
commit
3550568a54
@ -1651,7 +1651,7 @@ Released 2018-09-13
|
||||
[`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing
|
||||
[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional
|
||||
[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic
|
||||
[`panic_in_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result
|
||||
[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result
|
||||
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
|
||||
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
|
||||
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
|
||||
|
@ -267,7 +267,7 @@ macro_rules! declare_clippy_lint {
|
||||
mod option_env_unwrap;
|
||||
mod option_if_let_else;
|
||||
mod overflow_check_conditional;
|
||||
mod panic_in_result;
|
||||
mod panic_in_result_fn;
|
||||
mod panic_unimplemented;
|
||||
mod partialeq_ne_impl;
|
||||
mod path_buf_push_overwrite;
|
||||
@ -748,7 +748,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
&option_env_unwrap::OPTION_ENV_UNWRAP,
|
||||
&option_if_let_else::OPTION_IF_LET_ELSE,
|
||||
&overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
|
||||
&panic_in_result::PANIC_IN_RESULT,
|
||||
&panic_in_result_fn::PANIC_IN_RESULT_FN,
|
||||
&panic_unimplemented::PANIC,
|
||||
&panic_unimplemented::PANIC_PARAMS,
|
||||
&panic_unimplemented::TODO,
|
||||
@ -1088,7 +1088,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
store.register_late_pass(|| box manual_async_fn::ManualAsyncFn);
|
||||
store.register_early_pass(|| box redundant_field_names::RedundantFieldNames);
|
||||
store.register_late_pass(|| box vec_resize_to_zero::VecResizeToZero);
|
||||
store.register_late_pass(|| box panic_in_result::PanicInResult);
|
||||
store.register_late_pass(|| box panic_in_result_fn::PanicInResultFn);
|
||||
|
||||
let single_char_binding_names_threshold = conf.single_char_binding_names_threshold;
|
||||
store.register_early_pass(move || box non_expressive_names::NonExpressiveNames {
|
||||
@ -1132,7 +1132,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
LintId::of(&missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS),
|
||||
LintId::of(&missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS),
|
||||
LintId::of(&modulo_arithmetic::MODULO_ARITHMETIC),
|
||||
LintId::of(&panic_in_result::PANIC_IN_RESULT),
|
||||
LintId::of(&panic_in_result_fn::PANIC_IN_RESULT_FN),
|
||||
LintId::of(&panic_unimplemented::PANIC),
|
||||
LintId::of(&panic_unimplemented::TODO),
|
||||
LintId::of(&panic_unimplemented::UNIMPLEMENTED),
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::utils::{is_expn_of, is_type_diagnostic_item, return_ty, span_lint_and_then};
|
||||
use if_chain::if_chain;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::Expr;
|
||||
@ -23,14 +22,14 @@
|
||||
/// panic!("error");
|
||||
/// }
|
||||
/// ```
|
||||
pub PANIC_IN_RESULT,
|
||||
pub PANIC_IN_RESULT_FN,
|
||||
restriction,
|
||||
"functions of type `Result<..>` that contain `panic!()`, `todo!()` or `unreachable()` or `unimplemented()` "
|
||||
}
|
||||
|
||||
declare_lint_pass!(PanicInResult => [PANIC_IN_RESULT]);
|
||||
declare_lint_pass!(PanicInResultFn => [PANIC_IN_RESULT_FN]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for PanicInResult {
|
||||
impl<'tcx> LateLintPass<'tcx> for PanicInResultFn {
|
||||
fn check_fn(
|
||||
&mut self,
|
||||
cx: &LateContext<'tcx>,
|
||||
@ -40,15 +39,10 @@ fn check_fn(
|
||||
span: Span,
|
||||
hir_id: hir::HirId,
|
||||
) {
|
||||
if let FnKind::Closure(_) = fn_kind {
|
||||
return;
|
||||
}
|
||||
if_chain! {
|
||||
if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym!(result_type));
|
||||
then
|
||||
{
|
||||
lint_impl_body(cx, span, body);
|
||||
}
|
||||
if !matches!(fn_kind, FnKind::Closure(_))
|
||||
&& is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym!(result_type))
|
||||
{
|
||||
lint_impl_body(cx, span, body);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,10 +55,9 @@ impl<'tcx> Visitor<'tcx> for FindPanicUnimplementedUnreachable {
|
||||
type Map = Map<'tcx>;
|
||||
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if is_expn_of(expr.span, "unimplemented").is_some()
|
||||
|| is_expn_of(expr.span, "unreachable").is_some()
|
||||
|| is_expn_of(expr.span, "panic").is_some()
|
||||
|| is_expn_of(expr.span, "todo").is_some()
|
||||
if ["unimplemented", "unreachable", "panic", "todo"]
|
||||
.iter()
|
||||
.any(|fun| is_expn_of(expr.span, fun).is_some())
|
||||
{
|
||||
self.result.push(expr.span);
|
||||
}
|
||||
@ -83,7 +76,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir
|
||||
if !panics.result.is_empty() {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
PANIC_IN_RESULT,
|
||||
PANIC_IN_RESULT_FN,
|
||||
impl_span,
|
||||
"used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`",
|
||||
move |diag| {
|
@ -1705,11 +1705,11 @@
|
||||
module: "panic_unimplemented",
|
||||
},
|
||||
Lint {
|
||||
name: "panic_in_result",
|
||||
name: "panic_in_result_fn",
|
||||
group: "restriction",
|
||||
desc: "functions of type `Result<..>` that contain `panic!()`, `todo!()` or `unreachable()` or `unimplemented()` ",
|
||||
deprecation: None,
|
||||
module: "panic_in_result",
|
||||
module: "panic_in_result_fn",
|
||||
},
|
||||
Lint {
|
||||
name: "panic_params",
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![warn(clippy::panic_in_result)]
|
||||
#![warn(clippy::panic_in_result_fn)]
|
||||
|
||||
struct A;
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
|
||||
--> $DIR/panic_in_result.rs:6:5
|
||||
--> $DIR/panic_in_result_fn.rs:6:5
|
||||
|
|
||||
LL | / fn result_with_panic() -> Result<bool, String> // should emit lint
|
||||
LL | | {
|
||||
@ -7,17 +7,17 @@ LL | | panic!("error");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: `-D clippy::panic-in-result` implied by `-D warnings`
|
||||
= note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
|
||||
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
|
||||
note: return Err() instead of panicking
|
||||
--> $DIR/panic_in_result.rs:8:9
|
||||
--> $DIR/panic_in_result_fn.rs:8:9
|
||||
|
|
||||
LL | panic!("error");
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
|
||||
--> $DIR/panic_in_result.rs:11:5
|
||||
--> $DIR/panic_in_result_fn.rs:11:5
|
||||
|
|
||||
LL | / fn result_with_unimplemented() -> Result<bool, String> // should emit lint
|
||||
LL | | {
|
||||
@ -27,14 +27,14 @@ LL | | }
|
||||
|
|
||||
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
|
||||
note: return Err() instead of panicking
|
||||
--> $DIR/panic_in_result.rs:13:9
|
||||
--> $DIR/panic_in_result_fn.rs:13:9
|
||||
|
|
||||
LL | unimplemented!();
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
|
||||
--> $DIR/panic_in_result.rs:16:5
|
||||
--> $DIR/panic_in_result_fn.rs:16:5
|
||||
|
|
||||
LL | / fn result_with_unreachable() -> Result<bool, String> // should emit lint
|
||||
LL | | {
|
||||
@ -44,14 +44,14 @@ LL | | }
|
||||
|
|
||||
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
|
||||
note: return Err() instead of panicking
|
||||
--> $DIR/panic_in_result.rs:18:9
|
||||
--> $DIR/panic_in_result_fn.rs:18:9
|
||||
|
|
||||
LL | unreachable!();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
|
||||
--> $DIR/panic_in_result.rs:21:5
|
||||
--> $DIR/panic_in_result_fn.rs:21:5
|
||||
|
|
||||
LL | / fn result_with_todo() -> Result<bool, String> // should emit lint
|
||||
LL | | {
|
||||
@ -61,14 +61,14 @@ LL | | }
|
||||
|
|
||||
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
|
||||
note: return Err() instead of panicking
|
||||
--> $DIR/panic_in_result.rs:23:9
|
||||
--> $DIR/panic_in_result_fn.rs:23:9
|
||||
|
|
||||
LL | todo!("Finish this");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
|
||||
--> $DIR/panic_in_result.rs:52:1
|
||||
--> $DIR/panic_in_result_fn.rs:52:1
|
||||
|
|
||||
LL | / fn function_result_with_panic() -> Result<bool, String> // should emit lint
|
||||
LL | | {
|
||||
@ -78,14 +78,14 @@ LL | | }
|
||||
|
|
||||
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
|
||||
note: return Err() instead of panicking
|
||||
--> $DIR/panic_in_result.rs:54:5
|
||||
--> $DIR/panic_in_result_fn.rs:54:5
|
||||
|
|
||||
LL | panic!("error");
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
|
||||
--> $DIR/panic_in_result.rs:67:1
|
||||
--> $DIR/panic_in_result_fn.rs:67:1
|
||||
|
|
||||
LL | / fn main() -> Result<(), String> {
|
||||
LL | | todo!("finish main method");
|
||||
@ -95,7 +95,7 @@ LL | | }
|
||||
|
|
||||
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
|
||||
note: return Err() instead of panicking
|
||||
--> $DIR/panic_in_result.rs:68:5
|
||||
--> $DIR/panic_in_result_fn.rs:68:5
|
||||
|
|
||||
LL | todo!("finish main method");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
Loading…
Reference in New Issue
Block a user