1 use if_chain::if_chain;
2 use rustc::declare_lint_pass;
4 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5 use rustc_session::declare_tool_lint;
7 use crate::utils::{is_must_use_func_call, is_must_use_ty, span_help_and_lint};
10 /// **What it does:** Checks for `let _ = <expr>`
11 /// where expr is #[must_use]
13 /// **Why is this bad?** It's better to explicitly
14 /// handle the value of a #[must_use] expr
16 /// **Known problems:** None.
20 /// fn f() -> Result<u32, u32> {
25 /// // is_ok() is marked #[must_use]
26 /// let _ = f().is_ok();
28 pub LET_UNDERSCORE_MUST_USE,
30 "non-binding let on a #[must_use] expression"
33 declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE]);
35 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
36 fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt) {
38 if let StmtKind::Local(ref local) = stmt.kind;
39 if let PatKind::Wild = local.pat.kind;
40 if let Some(ref init) = local.init;
42 if is_must_use_ty(cx, cx.tables.expr_ty(init)) {
45 LET_UNDERSCORE_MUST_USE,
47 "non-binding let on an expression with #[must_use] type",
48 "consider explicitly using expression value"
50 } else if is_must_use_func_call(cx, init) {
53 LET_UNDERSCORE_MUST_USE,
55 "non-binding let on a result of a #[must_use] function",
56 "consider explicitly using function result"