From b7faf0558a12339a9dd6bda1a23db08896fb1340 Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Sun, 22 Mar 2020 23:47:25 +0800 Subject: [PATCH] Why Cow<'a, str> == Cow<'a, str> not matched? --- clippy_lints/src/utils/internal_lints.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 35c2040c8b0a..454ddea7ecb3 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -418,7 +418,7 @@ impl EarlyLintPass for CollapsibleCalls { if let ExprKind::Block(block, _) = &block.kind; let stmts = &block.stmts; if stmts.len() == 1; - if let StmtKind::Expr(only_expr) = &stmts[0].kind; + if let StmtKind::Semi(only_expr) = &stmts[0].kind; if let ExprKind::MethodCall(ref ps, ref span_call_args) = &only_expr.kind; let and_then_args = get_and_then_args(cx, and_then_args); then { @@ -480,7 +480,6 @@ fn suggestion_args<'a>(cx: &EarlyContext<'_>, span_call_args: &Vec>) fn suggest_span_suggestion(cx: &EarlyContext<'_>, expr: &AstExpr, and_then_args: AndThenArgs<'_>, suggestion_args: SuggestionArgs<'_>) { if and_then_args.span == suggestion_args.span { - println!("suggestion true"); span_lint_and_sugg ( cx, COLLAPSIBLE_SPAN_LINT_CALLS, @@ -499,6 +498,16 @@ fn suggest_span_suggestion(cx: &EarlyContext<'_>, expr: &AstExpr, and_then_args: ), Applicability::MachineApplicable ); + } else { + span_lint_and_sugg( + cx, + COLLAPSIBLE_SPAN_LINT_CALLS, + expr.span, + "Lint activated", + "Lint helped", + "modify to".to_string(), + Applicability::MachineApplicable + ) } } @@ -562,11 +571,12 @@ fn suggest_span_note(cx: &EarlyContext<'_>, expr: &AstExpr, and_then_args: AndTh "this call is collspible", "collapse into", format!( - "span_lint_and_note({},{}, {}, {}, {})", + "span_lint_and_note({}, {}, {}, {}, {}, {})", and_then_args.cx, and_then_args.lint, and_then_args.span, and_then_args.msg, + and_then_args.span, note_args.note ), Applicability::MachineApplicable @@ -575,5 +585,5 @@ fn suggest_span_note(cx: &EarlyContext<'_>, expr: &AstExpr, and_then_args: AndTh } fn snippet<'a>(cx: &EarlyContext<'_>, span: Span) -> Cow<'a, str> { - other_snippet(cx, span, "Should not be") + other_snippet(cx, span, "Should not be this snippet") }