diff options
| author | infrandomness <infrandomness@gmail.com> | 2022-04-08 21:27:01 +0200 |
|---|---|---|
| committer | infrandomness <infrandomness@gmail.com> | 2022-04-14 13:13:55 +0200 |
| commit | ee9281d7a241c448f6bcbbb6cb8bdf8b17251a92 (patch) | |
| tree | 7bfe45699118e9d81359e4bd52660fb9c0fcf4a3 | |
| parent | 262b35ea2c4dd9a16c28bf40cb5c124f664ce96c (diff) | |
| download | rust-ee9281d7a241c448f6bcbbb6cb8bdf8b17251a92.tar.gz rust-ee9281d7a241c448f6bcbbb6cb8bdf8b17251a92.zip | |
Implement checks to the expression
The implemented checks are for checking if the expression is either of type `Option` and isn't a syntactical place
| -rw-r--r-- | clippy_lints/src/methods/needless_option_take.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/clippy_lints/src/methods/needless_option_take.rs b/clippy_lints/src/methods/needless_option_take.rs index b3696273e1d..27ef9009328 100644 --- a/clippy_lints/src/methods/needless_option_take.rs +++ b/clippy_lints/src/methods/needless_option_take.rs @@ -2,15 +2,17 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::is_type_diagnostic_item; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_span::sym::Result as sym_result; +use rustc_span::sym; use super::NEEDLESS_OPTION_TAKE; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { - if_chain! { - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym_result); - let result_type = cx.typeck_results().expr_ty(recv); - +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, _recv: &'tcx Expr<'_>) { + // Checks if expression type is equal to sym::Option and if the expr is not a syntactic place + if is_expr_option(cx, expr) && !expr.is_syntactic_place_expr() { + span_lint(cx, OPTION_TAKE_ON_TEMPORARY, expr.span, "Format test"); + } + /* if_chain! { + is_expr_option(cx, expr); then { span_lint( cx, @@ -19,5 +21,10 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &' "Format test" ); } - }; + };*/ +} + +fn is_expr_option(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + let expr_type = cx.typeck_results().expr_ty(expr); + is_type_diagnostic_item(cx, expr_type, sym::Option) } |
