From 92034e20c86bf3497b855dc3a756bfadae8ec006 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Sat, 15 Sep 2018 19:14:08 +0300 Subject: [PATCH 1/8] Use span_suggestion_with_applicability instead of span_suggestion --- clippy_lints/src/assign_ops.rs | 14 ++++-- clippy_lints/src/attrs.rs | 8 +++- clippy_lints/src/bit_mask.rs | 8 +++- clippy_lints/src/booleans.rs | 4 +- clippy_lints/src/collapsible_if.rs | 7 ++- clippy_lints/src/const_static_lifetime.rs | 8 +++- clippy_lints/src/copies.rs | 3 +- clippy_lints/src/entry.rs | 15 +++++- clippy_lints/src/eq_op.rs | 28 +++++++++-- clippy_lints/src/eta_reduction.rs | 8 +++- clippy_lints/src/format.rs | 15 +++++- clippy_lints/src/identity_conversion.rs | 22 +++++++-- .../src/if_let_redundant_pattern_matching.rs | 4 +- clippy_lints/src/int_plus_one.rs | 8 +++- clippy_lints/src/large_enum_variant.rs | 4 +- clippy_lints/src/let_if_seq.rs | 10 ++-- clippy_lints/src/loops.rs | 3 +- clippy_lints/src/map_unit_fn.rs | 7 ++- clippy_lints/src/matches.rs | 8 +++- clippy_lints/src/methods.rs | 29 +++++++++-- clippy_lints/src/misc.rs | 27 ++++++++--- clippy_lints/src/misc_early.rs | 14 ++++-- clippy_lints/src/needless_borrow.rs | 15 +++++- clippy_lints/src/needless_borrowed_ref.rs | 8 +++- clippy_lints/src/needless_pass_by_value.rs | 23 ++++++--- clippy_lints/src/ptr.rs | 28 +++++++++-- clippy_lints/src/question_mark.rs | 4 +- clippy_lints/src/ranges.rs | 19 +++++--- clippy_lints/src/returns.rs | 8 +++- clippy_lints/src/swap.rs | 18 +++++-- clippy_lints/src/transmute.rs | 48 +++++++++++++++---- clippy_lints/src/utils/mod.rs | 2 +- clippy_lints/src/utils/sugg.rs | 22 +++++++-- 33 files changed, 367 insertions(+), 82 deletions(-) diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index d50b72b19ac5..5cf714bed86a 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -6,6 +6,7 @@ use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use crate::rustc::{declare_tool_lint, lint_array}; use if_chain::if_chain; use crate::syntax::ast; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for `a = a op b` or `a = b commutative_op a` /// patterns. @@ -78,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { let r = &sugg::Sugg::hir(cx, rhs, ".."); let long = format!("{} = {}", snip_a, sugg::make_binop(higher::binop(op.node), a, r)); - db.span_suggestion( + db.span_suggestion_with_applicability( expr.span, &format!( "Did you mean {} = {} {} {} or {}? Consider replacing it with", @@ -89,8 +90,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { long ), format!("{} {}= {}", snip_a, op.node.as_str(), snip_r), + Applicability::Unspecified, ); - db.span_suggestion(expr.span, "or", long); + db.span_suggestion_with_applicability( + expr.span, + "or", + long, + Applicability::Unspecified, + ); } }, ); @@ -172,10 +179,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span)) { - db.span_suggestion( + db.span_suggestion_with_applicability( expr.span, "replace it with", format!("{} {}= {}", snip_a, op.node.as_str(), snip_r), + Applicability::Unspecified, ); } }, diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 128a5ab147ea..197aa88cbbea 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -13,6 +13,7 @@ use crate::rustc::ty::{self, TyCtxt}; use semver::Version; use crate::syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind}; use crate::syntax::source_map::Span; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for items annotated with `#[inline(always)]`, /// unless the annotated function is empty or simply panics. @@ -203,7 +204,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass { "useless lint attribute", |db| { sugg = sugg.replacen("#[", "#![", 1); - db.span_suggestion(line_span, "if you just forgot a `!`, use", sugg); + db.span_suggestion_with_applicability( + line_span, + "if you just forgot a `!`, use", + sugg, + Applicability::Unspecified, + ); }, ); } diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 93c6bee03bfe..52c6d4c71dcf 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -7,6 +7,7 @@ use crate::syntax::source_map::Span; use crate::utils::{span_lint, span_lint_and_then}; use crate::utils::sugg::Sugg; use crate::consts::{constant, Constant}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for incompatible bit masks in comparisons. /// @@ -138,7 +139,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { "bit mask could be simplified with a call to `trailing_zeros`", |db| { let sugg = Sugg::hir(cx, left1, "...").maybe_par(); - db.span_suggestion(e.span, "try", format!("{}.trailing_zeros() >= {}", sugg, n.count_ones())); + db.span_suggestion_with_applicability( + e.span, + "try", + format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()), + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index b2639330071c..85f6eeb19ef9 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -6,6 +6,7 @@ use crate::syntax::ast::{LitKind, NodeId, DUMMY_NODE_ID}; use crate::syntax::source_map::{dummy_spanned, Span, DUMMY_SP}; use crate::rustc_data_structures::thin_vec::ThinVec; use crate::utils::{in_macro, paths, match_type, snippet_opt, span_lint_and_then, SpanlessEq, get_trait_def_id, implements_trait}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for boolean expressions that can be written more /// concisely. @@ -390,10 +391,11 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { "this expression can be optimized out by applying boolean operations to the \ outer expression", ); - db.span_suggestion( + db.span_suggestion_with_applicability( e.span, "it would look like the following", suggest(self.cx, suggestion, &h2q.terminals).0, + Applicability::Unspecified, ); }, ); diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index a24436991e55..c139b0f0c1f1 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -19,6 +19,7 @@ use crate::syntax::ast; use crate::utils::{in_macro, snippet_block, span_lint_and_sugg, span_lint_and_then}; use crate::utils::sugg::Sugg; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for nested `if` statements which can be collapsed /// by `&&`-combining their conditions and for `else { if ... }` expressions @@ -133,11 +134,13 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: & span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this if statement can be collapsed", |db| { let lhs = Sugg::ast(cx, check, ".."); let rhs = Sugg::ast(cx, check_inner, ".."); - db.span_suggestion(expr.span, + db.span_suggestion_with_applicability(expr.span, "try", format!("if {} {}", lhs.and(&rhs), - snippet_block(cx, content.span, ".."))); + snippet_block(cx, content.span, "..")), + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/const_static_lifetime.rs b/clippy_lints/src/const_static_lifetime.rs index 6daddb5fe137..92c609d9858d 100644 --- a/clippy_lints/src/const_static_lifetime.rs +++ b/clippy_lints/src/const_static_lifetime.rs @@ -2,6 +2,7 @@ use crate::syntax::ast::*; use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; use crate::rustc::{declare_tool_lint, lint_array}; use crate::utils::{in_macro, snippet, span_lint_and_then}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for constants with an explicit `'static` lifetime. /// @@ -60,7 +61,12 @@ impl StaticConst { lifetime.ident.span, "Constants have by default a `'static` lifetime", |db| { - db.span_suggestion(ty.span, "consider removing `'static`", sugg); + db.span_suggestion_with_applicability( + ty.span, + "consider removing `'static`", + sugg, + Applicability::Unspecified, + ); }, ); } diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 76c8360be62d..04a297e5e7e9 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -202,7 +202,8 @@ fn lint_match_arms(cx: &LateContext<'_, '_>, expr: &Expr) { |db| { db.span_note(i.body.span, "same as this"); - // Note: this does not use `span_suggestion` on purpose: there is no clean way + // Note: this does not use `span_suggestion_with_applicability` on purpose: + // there is no clean way // to remove the other arm. Building a span and suggest to replace it to "" // makes an even more confusing error message. Also in order not to make up a // span for the whole pattern, the suggestion is only shown when there is only diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 167f5633b2e6..be9af18c9112 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -6,6 +6,7 @@ use if_chain::if_chain; use crate::syntax::source_map::Span; use crate::utils::SpanlessEq; use crate::utils::{get_item_name, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap` /// or `BTreeMap`. @@ -139,14 +140,24 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { snippet(self.cx, params[1].span, ".."), snippet(self.cx, params[2].span, "..")); - db.span_suggestion(self.span, "consider using", help); + db.span_suggestion_with_applicability( + self.span, + "consider using", + help, + Applicability::Unspecified, + ); } else { let help = format!("{}.entry({})", snippet(self.cx, self.map.span, "map"), snippet(self.cx, params[1].span, "..")); - db.span_suggestion(self.span, "consider using", help); + db.span_suggestion_with_applicability( + self.span, + "consider using", + help, + Applicability::Unspecified, + ); } }); } diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index d182faa1e5c9..2ad04cd6fbe2 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -2,6 +2,7 @@ use crate::rustc::hir::*; use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use crate::rustc::{declare_tool_lint, lint_array}; use crate::utils::{in_macro, implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for equal operands to comparison, logical and /// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`, @@ -113,7 +114,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { } else if lcpy && !rcpy && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()]) { span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| { let lsnip = snippet(cx, l.span, "...").to_string(); - db.span_suggestion(left.span, "use the left value directly", lsnip); + db.span_suggestion_with_applicability( + left.span, + "use the left value directly", + lsnip, + Applicability::Unspecified, + ); }) } else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) { span_lint_and_then( @@ -123,7 +129,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { "needlessly taken reference of right operand", |db| { let rsnip = snippet(cx, r.span, "...").to_string(); - db.span_suggestion(right.span, "use the right value directly", rsnip); + db.span_suggestion_with_applicability( + right.span, + "use the right value directly", + rsnip, + Applicability::Unspecified,); }, ) } @@ -135,7 +145,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { if (requires_ref || lcpy) && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()]) { span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| { let lsnip = snippet(cx, l.span, "...").to_string(); - db.span_suggestion(left.span, "use the left value directly", lsnip); + db.span_suggestion_with_applicability( + left.span, + "use the left value directly", + lsnip, + Applicability::Unspecified, + ); }) } }, @@ -146,7 +161,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { if (requires_ref || rcpy) && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) { span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| { let rsnip = snippet(cx, r.span, "...").to_string(); - db.span_suggestion(right.span, "use the right value directly", rsnip); + db.span_suggestion_with_applicability( + right.span, + "use the right value directly", + rsnip, + Applicability::Unspecified, + ); }) } }, diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index e331f6adf3ad..b40ff8b51cd1 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -3,6 +3,7 @@ use crate::rustc::{declare_tool_lint, lint_array}; use crate::rustc::ty; use crate::rustc::hir::*; use crate::utils::{is_adjusted, iter_input_pats, snippet_opt, span_lint_and_then}; +use crate::rustc_errors::Applicability; #[allow(missing_copy_implementations)] pub struct EtaPass; @@ -96,7 +97,12 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { } span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| { if let Some(snippet) = snippet_opt(cx, caller.span) { - db.span_suggestion(expr.span, "remove closure as shown", snippet); + db.span_suggestion_with_applicability( + expr.span, + "remove closure as shown", + snippet, + Applicability::Unspecified, + ); } }); } diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index fbc3c750cde4..868b7c19cef1 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -7,6 +7,7 @@ use crate::syntax::ast::LitKind; use crate::syntax_pos::Span; use crate::utils::paths; use crate::utils::{in_macro, is_expn_of, last_path_segment, match_def_path, match_type, opt_def_id, resolve_node, snippet, span_lint_and_then, walk_ptrs_ty}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for the use of `format!("string literal with no /// argument")` and `format!("{}", foo)` where `foo` is a string. @@ -60,7 +61,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { then { let sugg = format!("{}.to_string()", snippet(cx, format_arg, "").into_owned()); span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| { - db.span_suggestion(expr.span, "consider using .to_string()", sugg); + db.span_suggestion_with_applicability( + expr.span, + "consider using .to_string()", + sugg, + Applicability::Unspecified, + ); }); } } @@ -70,7 +76,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { if tup.is_empty() { let sugg = format!("{}.to_string()", snippet(cx, expr.span, "").into_owned()); span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| { - db.span_suggestion(span, "consider using .to_string()", sugg); + db.span_suggestion_with_applicability( + span, + "consider using .to_string()", + sugg, + Applicability::Unspecified, + ); }); } }, diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs index 24b0d57d0987..2a764ad73d47 100644 --- a/clippy_lints/src/identity_conversion.rs +++ b/clippy_lints/src/identity_conversion.rs @@ -4,6 +4,7 @@ use crate::rustc::hir::*; use crate::syntax::ast::NodeId; use crate::utils::{in_macro, match_def_path, match_trait_method, same_tys, snippet, span_lint_and_then}; use crate::utils::{opt_def_id, paths, resolve_node}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for always-identical `Into`/`From`/`IntoIter` conversions. /// @@ -63,7 +64,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { if same_tys(cx, a, b) { let sugg = snippet(cx, args[0].span, "").into_owned(); span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| { - db.span_suggestion(e.span, "consider removing `.into()`", sugg); + db.span_suggestion_with_applicability( + e.span, + "consider removing `.into()`", + sugg, + Applicability::Unspecified, + ); }); } } @@ -73,7 +79,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { if same_tys(cx, a, b) { let sugg = snippet(cx, args[0].span, "").into_owned(); span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| { - db.span_suggestion(e.span, "consider removing `.into_iter()`", sugg); + db.span_suggestion_with_applicability( + e.span, + "consider removing `.into_iter()`", + sugg, + Applicability::Unspecified, + ); }); } } @@ -88,7 +99,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { let sugg = snippet(cx, args[0].span.source_callsite(), "").into_owned(); let sugg_msg = format!("consider removing `{}()`", snippet(cx, path.span, "From::from")); span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| { - db.span_suggestion(e.span, &sugg_msg, sugg); + db.span_suggestion_with_applicability( + e.span, + &sugg_msg, + sugg, + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/if_let_redundant_pattern_matching.rs b/clippy_lints/src/if_let_redundant_pattern_matching.rs index c996c91b48b4..64d088d2a991 100644 --- a/clippy_lints/src/if_let_redundant_pattern_matching.rs +++ b/clippy_lints/src/if_let_redundant_pattern_matching.rs @@ -2,6 +2,7 @@ use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use crate::rustc::{declare_tool_lint, lint_array}; use crate::rustc::hir::*; use crate::utils::{match_qpath, paths, snippet, span_lint_and_then}; +use crate::rustc_errors::Applicability; /// **What it does:** Lint for redundant pattern matching over `Result` or /// `Option` @@ -77,10 +78,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { &format!("redundant pattern matching, consider using `{}`", good_method), |db| { let span = expr.span.with_hi(op.span.hi()); - db.span_suggestion( + db.span_suggestion_with_applicability( span, "try this", format!("if {}.{}", snippet(cx, op.span, "_"), good_method), + Applicability::Unspecified, ); }, ); diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 023a88e1ffae..4608ca696e1e 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -2,6 +2,7 @@ use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; use crate::rustc::{declare_tool_lint, lint_array}; +use crate::rustc_errors::Applicability; use crate::syntax::ast::*; use crate::utils::{snippet_opt, span_lint_and_then}; @@ -152,7 +153,12 @@ impl IntPlusOne { fn emit_warning(&self, cx: &EarlyContext<'_>, block: &Expr, recommendation: String) { span_lint_and_then(cx, INT_PLUS_ONE, block.span, "Unnecessary `>= y + 1` or `x - 1 >=`", |db| { - db.span_suggestion(block.span, "change `>= y + 1` to `> y` as shown", recommendation); + db.span_suggestion_with_applicability( + block.span, + "change `>= y + 1` to `> y` as shown", + recommendation, + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 87f9804c1ae9..8ff53e15c314 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -5,6 +5,7 @@ use crate::rustc::{declare_tool_lint, lint_array}; use crate::rustc::hir::*; use crate::utils::{snippet_opt, span_lint_and_then}; use crate::rustc::ty::layout::LayoutOf; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for large size differences between variants on /// `enum`s. @@ -96,11 +97,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant { VariantData::Unit(_) => unreachable!(), }; if let Some(snip) = snippet_opt(cx, span) { - db.span_suggestion( + db.span_suggestion_with_applicability( span, "consider boxing the large fields to reduce the total size of the \ enum", format!("Box<{}>", snip), + Applicability::Unspecified, ); return; } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 10dc3cae8af9..4947715e293d 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -6,6 +6,7 @@ use crate::rustc::hir::BindingAnnotation; use crate::rustc::hir::def::Def; use crate::syntax::ast; use crate::utils::{snippet, span_lint_and_then}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for variable declarations immediately followed by a /// conditional affectation. @@ -120,9 +121,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { span, "`if _ { .. } else { .. }` is an expression", |db| { - db.span_suggestion(span, - "it is more idiomatic to write", - sug); + db.span_suggestion_with_applicability( + span, + "it is more idiomatic to write", + sug, + Applicability::Unspecified, + ); if !mutability.is_empty() { db.note("you might not need `mut` at all"); } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 3adc4302730f..70608b9895fd 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1196,7 +1196,7 @@ fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx expr.span, "this range is empty so this for loop will never run", |db| { - db.span_suggestion( + db.span_suggestion_with_applicability( arg.span, "consider using the following if you are attempting to iterate over this \ range in reverse", @@ -1206,6 +1206,7 @@ fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx dots = dots, start = start_snippet ), + Applicability::Unspecified, ); }, ); diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 7187b79979f2..5f592a722d1d 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -228,7 +228,12 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr snippet(cx, binding.pat.span, "_"), snippet(cx, var_arg.span, "_"), snippet(cx, reduced_expr_span, "_")); - db.span_suggestion(stmt.span, "try this", suggestion); + db.span_suggestion_with_applicability( + stmt.span, + "try this", + suggestion, + Applicability::Unspecified, + ); } else { let suggestion = format!("if let {0}({1}) = {2} {{ ... }}", variant, diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index a4c2681e3598..7cc70cb0834b 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -12,6 +12,7 @@ use crate::utils::{expr_block, is_allowed, is_expn_of, match_qpath, match_type, remove_blocks, snippet, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty}; use crate::utils::sugg::Sugg; use crate::consts::{constant, Constant}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for matches with a single arm where an `if let` /// will usually suffice. @@ -339,7 +340,12 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex }; if let Some(sugg) = sugg { - db.span_suggestion(expr.span, "consider using an if/else expression", sugg); + db.span_suggestion_with_applicability( + expr.span, + "consider using an if/else expression", + sugg, + Applicability::Unspecified, + ); } } } diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 1e03503d3138..f61995cf2650 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -17,6 +17,7 @@ use crate::utils::{get_arg_name, get_trait_def_id, implements_trait, in_macro, i use crate::utils::paths; use crate::utils::sugg; use crate::consts::{constant, Constant}; +use crate::rustc_errors::Applicability; #[derive(Clone)] pub struct Pass; @@ -1127,8 +1128,18 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp let refs: String = iter::repeat('&').take(n + 1).collect(); let derefs: String = iter::repeat('*').take(n).collect(); let explicit = format!("{}{}::clone({})", refs, ty, snip); - db.span_suggestion(expr.span, "try dereferencing it", format!("{}({}{}).clone()", refs, derefs, snip.deref())); - db.span_suggestion(expr.span, "or try being explicit about what type to clone", explicit); + db.span_suggestion_with_applicability( + expr.span, + "try dereferencing it", + format!("{}({}{}).clone()", refs, derefs, snip.deref()), + Applicability::Unspecified, + ); + db.span_suggestion_with_applicability( + expr.span, + "or try being explicit about what type to clone", + explicit, + Applicability::Unspecified, + ); }, ); return; // don't report clone_on_copy @@ -1169,7 +1180,12 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp } span_lint_and_then(cx, CLONE_ON_COPY, expr.span, "using `clone` on a `Copy` type", |db| { if let Some((text, snip)) = snip { - db.span_suggestion(expr.span, text, snip); + db.span_suggestion_with_applicability( + expr.span, + text, + snip, + Applicability::Unspecified, + ); } }); } @@ -1639,7 +1655,12 @@ fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, let map_or_func_snippet = snippet(cx, map_or_args[2].span, ".."); let hint = format!("{0}.and_then({1})", map_or_self_snippet, map_or_func_snippet); span_lint_and_then(cx, OPTION_MAP_OR_NONE, expr.span, msg, |db| { - db.span_suggestion(expr.span, "try using and_then instead", hint); + db.span_suggestion_with_applicability( + expr.span, + "try using and_then instead", + hint, + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index dcc4dca39297..ac4e93f633a2 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -13,6 +13,7 @@ use crate::utils::{get_item_name, get_parent_expr, implements_trait, in_constant use crate::utils::sugg::Sugg; use crate::syntax::ast::{LitKind, CRATE_NODE_ID}; use crate::consts::{constant, Constant}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for function arguments and let bindings denoted as /// `ref`. @@ -294,12 +295,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { l.pat.span, "`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead", |db| { - db.span_suggestion(s.span, + db.span_suggestion_with_applicability(s.span, "try", format!("let {name}{tyopt} = {initref};", name=snippet(cx, i.span, "_"), tyopt=tyopt, - initref=initref)); + initref=initref), + Applicability::Unspecified, + ); } ); } @@ -317,8 +320,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { "boolean short circuit operator in statement may be clearer using an explicit test", |db| { let sugg = if binop.node == BinOpKind::Or { !sugg } else { sugg }; - db.span_suggestion(s.span, "replace it with", - format!("if {} {{ {}; }}", sugg, &snippet(cx, b.span, ".."))); + db.span_suggestion_with_applicability( + s.span, + "replace it with", + format!("if {} {{ {}; }}", + sugg, + &snippet(cx, b.span, "..")), + Applicability::Unspecified, + ); }); } }; @@ -363,10 +372,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let lhs = Sugg::hir(cx, left, ".."); let rhs = Sugg::hir(cx, right, ".."); - db.span_suggestion( + db.span_suggestion_with_applicability( expr.span, "consider comparing them within some error", format!("({}).abs() < error", lhs - rhs), + Applicability::Unspecified, ); db.span_note(expr.span, "std::f32::EPSILON and std::f64::EPSILON are available."); }); @@ -534,7 +544,12 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) { } } } - db.span_suggestion(expr.span, "try", snip.to_string()); + db.span_suggestion_with_applicability( + expr.span, + "try", + snip.to_string(), + Applicability::Unspecified, + ); }, ); } diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 5a509802b615..c66fb5d6e47f 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -7,6 +7,7 @@ use crate::syntax::ast::*; use crate::syntax::source_map::Span; use crate::syntax::visit::FnKind; use crate::utils::{constants, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for structure field patterns bound to wildcards. /// @@ -307,7 +308,12 @@ impl EarlyLintPass for MiscEarly { "Try not to call a closure in the expression where it is declared.", |db| if decl.inputs.is_empty() { let hint = snippet(cx, block.span, "..").into_owned(); - db.span_suggestion(expr.span, "Try doing something like: ", hint); + db.span_suggestion_with_applicability( + expr.span, + "Try doing something like: ", + hint, + Applicability::Unspecified, + ); }, ); } @@ -392,15 +398,17 @@ impl MiscEarly { lit.span, "this is a decimal constant", |db| { - db.span_suggestion( + db.span_suggestion_with_applicability( lit.span, "if you mean to use a decimal constant, remove the `0` to remove confusion", src.trim_left_matches(|c| c == '_' || c == '0').to_string(), + Applicability::Unspecified, ); - db.span_suggestion( + db.span_suggestion_with_applicability( lit.span, "if you mean to use an octal constant, use `0o`", format!("0o{}", src.trim_left_matches(|c| c == '_' || c == '0')), + Applicability::Unspecified, ); }); } diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index ec53f76095f3..11e1a99fd7fc 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -9,6 +9,7 @@ use crate::rustc::hir::{BindingAnnotation, Expr, ExprKind, MutImmutable, Pat, Pa use crate::rustc::ty; use crate::rustc::ty::adjustment::{Adjust, Adjustment}; use crate::utils::{in_macro, snippet_opt, span_lint_and_then}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for address of operations (`&`) that are going to /// be dereferenced immediately by the compiler. @@ -75,7 +76,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { by the compiler", |db| { if let Some(snippet) = snippet_opt(cx, inner.span) { - db.span_suggestion(e.span, "change this to", snippet); + db.span_suggestion_with_applicability( + e.span, + "change this to", + snippet, + Applicability::Unspecified, + ); } }, ); @@ -103,7 +109,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { "this pattern creates a reference to a reference", |db| { if let Some(snippet) = snippet_opt(cx, name.span) { - db.span_suggestion(pat.span, "change this to", snippet); + db.span_suggestion_with_applicability( + pat.span, + "change this to", + snippet, + Applicability::Unspecified, + ); } } ) diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index 2db9b9d165bf..08ce0de21c6f 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -7,6 +7,7 @@ use crate::rustc::{declare_tool_lint, lint_array}; use if_chain::if_chain; use crate::rustc::hir::{BindingAnnotation, MutImmutable, Pat, PatKind}; use crate::utils::{in_macro, snippet, span_lint_and_then}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for useless borrowed references. /// @@ -77,7 +78,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef { "this pattern takes a reference on something that is being de-referenced", |db| { let hint = snippet(cx, spanned_name.span, "..").into_owned(); - db.span_suggestion(pat.span, "try removing the `&ref` part and just keep", hint); + db.span_suggestion_with_applicability( + pat.span, + "try removing the `&ref` part and just keep", + hint, + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index eb4cbe22f30a..aa644e4c3398 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -17,6 +17,7 @@ use crate::utils::{get_trait_def_id, implements_trait, in_macro, is_copy, is_sel snippet, snippet_opt, span_lint_and_then}; use crate::utils::ptr::get_spans; use std::borrow::Cow; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for functions taking arguments by value, but not /// consuming them in its @@ -227,19 +228,23 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { }).unwrap()); then { let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_")); - db.span_suggestion(input.span, + db.span_suggestion_with_applicability( + input.span, "consider changing the type to", - slice_ty); + slice_ty, + Applicability::Unspecified, + ); for (span, suggestion) in clone_spans { - db.span_suggestion( + db.span_suggestion_with_applicability( span, &snippet_opt(cx, span) .map_or( "change the call to".into(), |x| Cow::from(format!("change `{}` to", x)), ), - suggestion.into() + suggestion.into(), + Applicability::Unspecified, ); } @@ -252,10 +257,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { if match_type(cx, ty, &paths::STRING) { if let Some(clone_spans) = get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) { - db.span_suggestion(input.span, "consider changing the type to", "&str".to_string()); + db.span_suggestion_with_applicability( + input.span, + "consider changing the type to", + "&str".to_string(), + Applicability::Unspecified, + ); for (span, suggestion) in clone_spans { - db.span_suggestion( + db.span_suggestion_with_applicability( span, &snippet_opt(cx, span) .map_or( @@ -263,6 +273,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { |x| Cow::from(format!("change `{}` to", x)) ), suggestion.into(), + Applicability::Unspecified, ); } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 1aefc84cb498..f8d872cb4e6d 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -12,6 +12,7 @@ use crate::syntax::source_map::Span; use crate::syntax_pos::MultiSpan; use crate::utils::{match_qpath, match_type, paths, snippet_opt, span_lint, span_lint_and_then, walk_ptrs_hir_ty}; use crate::utils::ptr::get_spans; +use crate::rustc_errors::Applicability; /// **What it does:** This lint checks for function arguments of type `&String` /// or `&Vec` unless the references are mutable. It will also suggest you @@ -181,16 +182,22 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id: with non-Vec-based slices.", |db| { if let Some(ref snippet) = ty_snippet { - db.span_suggestion(arg.span, "change this to", format!("&[{}]", snippet)); + db.span_suggestion_with_applicability( + arg.span, + "change this to", + format!("&[{}]", snippet), + Applicability::Unspecified, + ); } for (clonespan, suggestion) in spans { - db.span_suggestion( + db.span_suggestion_with_applicability( clonespan, &snippet_opt(cx, clonespan).map_or( "change the call to".into(), |x| Cow::Owned(format!("change `{}` to", x)), ), suggestion.into(), + Applicability::Unspecified, ); } }, @@ -204,15 +211,21 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id: arg.span, "writing `&String` instead of `&str` involves a new object where a slice will do.", |db| { - db.span_suggestion(arg.span, "change this to", "&str".into()); + db.span_suggestion_with_applicability( + arg.span, + "change this to", + "&str".into(), + Applicability::Unspecified, + ); for (clonespan, suggestion) in spans { - db.span_suggestion_short( + db.span_suggestion_short_with_applicability( clonespan, &snippet_opt(cx, clonespan).map_or( "change the call to".into(), |x| Cow::Owned(format!("change `{}` to", x)), ), suggestion.into(), + Applicability::Unspecified, ); } }, @@ -239,7 +252,12 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id: arg.span, "using a reference to `Cow` is not recommended.", |db| { - db.span_suggestion(arg.span, "change this to", "&".to_owned() + &r); + db.span_suggestion_with_applicability( + arg.span, + "change this to", + "&".to_owned() + &r, + Applicability::Unspecified, + ); }, ); } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 93ea00cec77d..f4920e52a710 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -8,6 +8,7 @@ use crate::syntax::ptr::P; use crate::utils::{match_def_path, match_type, span_lint_and_then}; use crate::utils::paths::*; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for expressions that could be replaced by the question mark operator /// @@ -70,10 +71,11 @@ impl QuestionMarkPass { |db| { let receiver_str = &Sugg::hir(cx, subject, ".."); - db.span_suggestion( + db.span_suggestion_with_applicability( expr.span, "replace_it_with", format!("{}?;", receiver_str), + Applicability::Unspecified, ); } ) diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 6292af92e260..8ca0750684e1 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -7,6 +7,7 @@ use crate::syntax::source_map::Spanned; use crate::utils::{is_integer_literal, paths, snippet, span_lint, span_lint_and_then, snippet_opt}; use crate::utils::{get_trait_def_id, higher, implements_trait, SpanlessEq}; use crate::utils::sugg::Sugg; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for calling `.step_by(0)` on iterators, /// which never terminates. @@ -150,13 +151,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let end = Sugg::hir(cx, y, "y"); if let Some(is_wrapped) = &snippet_opt(cx, expr.span) { if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') { - db.span_suggestion(expr.span, + db.span_suggestion_with_applicability(expr.span, "use", - format!("({}..={})", start, end)); + format!("({}..={})", start, end), + Applicability::Unspecified, + ); } else { - db.span_suggestion(expr.span, + db.span_suggestion_with_applicability(expr.span, "use", - format!("{}..={}", start, end)); + format!("{}..={}", start, end), + Applicability::Unspecified, + ); } } }, @@ -177,9 +182,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { |db| { let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string()); let end = Sugg::hir(cx, y, "y"); - db.span_suggestion(expr.span, + db.span_suggestion_with_applicability(expr.span, "use", - format!("{}..{}", start, end)); + format!("{}..{}", start, end), + Applicability::Unspecified, + ); }, ); } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 4aed77f43e1d..34b7614e4396 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -4,6 +4,7 @@ use if_chain::if_chain; use crate::syntax::ast; use crate::syntax::source_map::Span; use crate::syntax::visit::FnKind; +use crate::rustc_errors::Applicability; use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then, span_note_and_lint}; @@ -108,7 +109,12 @@ impl ReturnPass { } span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| { if let Some(snippet) = snippet_opt(cx, inner_span) { - db.span_suggestion(ret_span, "remove `return` as shown", snippet); + db.span_suggestion_with_applicability( + ret_span, + "remove `return` as shown", + snippet, + Applicability::Unspecified, + ); } }); } diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index cd3a7259aae3..8859d5451946 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -6,6 +6,7 @@ use if_chain::if_chain; use crate::rustc::ty; use crate::utils::{differing_macro_contexts, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty, SpanlessEq}; use crate::utils::sugg::Sugg; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for manual swapping. /// @@ -136,7 +137,12 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) { &format!("this looks like you are swapping{} manually", what), |db| { if !sugg.is_empty() { - db.span_suggestion(span, "try", sugg); + db.span_suggestion_with_applicability( + span, + "try", + sugg, + Applicability::Unspecified, + ); if replace { db.note("or maybe you should use `std::mem::replace`?"); @@ -180,8 +186,14 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) { &format!("this looks like you are trying to swap{}", what), |db| { if !what.is_empty() { - db.span_suggestion(span, "try", - format!("std::mem::swap({}, {})", lhs, rhs)); + db.span_suggestion_with_applicability( + span, + "try", + format!("std::mem::swap({}, {})", + lhs, + rhs), + Applicability::Unspecified, + ); db.note("or maybe you should use `std::mem::replace`?"); } }); diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 84726e5ded3f..cdd0260b4fee 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -7,6 +7,7 @@ use std::borrow::Cow; use crate::syntax::ast; use crate::utils::{last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_then}; use crate::utils::{opt_def_id, sugg}; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for transmutes that can't ever be correct on any /// architecture. @@ -245,7 +246,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty) }; - db.span_suggestion(e.span, "try", sugg.to_string()); + db.span_suggestion_with_applicability( + e.span, + "try", + sugg.to_string(), + Applicability::Unspecified, + ); }, ), (&ty::Int(_), &ty::RawPtr(_)) | (&ty::Uint(_), &ty::RawPtr(_)) => { @@ -255,7 +261,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { e.span, "transmute from an integer to a pointer", |db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - db.span_suggestion(e.span, "try", arg.as_ty(&to_ty.to_string()).to_string()); + db.span_suggestion_with_applicability( + e.span, + "try", + arg.as_ty(&to_ty.to_string()).to_string(), + Applicability::Unspecified, + ); }, ) }, @@ -312,7 +323,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty))) }; - db.span_suggestion(e.span, "try", sugg::make_unop(deref, arg).to_string()); + db.span_suggestion_with_applicability( + e.span, + "try", + sugg::make_unop(deref, arg).to_string(), + Applicability::Unspecified, + ); }, ), (&ty::Int(ast::IntTy::I32), &ty::Char) | @@ -328,10 +344,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { } else { arg }; - db.span_suggestion( + db.span_suggestion_with_applicability( e.span, "consider using", format!("std::char::from_u32({}).unwrap()", arg.to_string()), + Applicability::Unspecified, ); }, ), @@ -353,7 +370,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { e.span, &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), |db| { - db.span_suggestion( + db.span_suggestion_with_applicability( e.span, "consider using", format!( @@ -361,6 +378,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { postfix, snippet(cx, args[0].span, ".."), ), + Applicability::Unspecified, ); } ) @@ -380,7 +398,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { } else { sugg_paren.addr_deref() }; - db.span_suggestion(e.span, "try", sugg.to_string()); + db.span_suggestion_with_applicability( + e.span, + "try", + sugg.to_string(), + Applicability::Unspecified, + ); }, ) } @@ -394,7 +417,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { "transmute from a pointer to a pointer", |db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { let sugg = arg.as_ty(cx.tcx.mk_ptr(to_ty)); - db.span_suggestion(e.span, "try", sugg.to_string()); + db.span_suggestion_with_applicability( + e.span, + "try", + sugg.to_string(), + Applicability::Unspecified, + ); }, ), (&ty::Int(ast::IntTy::I8), &ty::Bool) | (&ty::Uint(ast::UintTy::U8), &ty::Bool) => { @@ -406,10 +434,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { |db| { let arg = sugg::Sugg::hir(cx, &args[0], ".."); let zero = sugg::Sugg::NonParen(Cow::from("0")); - db.span_suggestion( + db.span_suggestion_with_applicability( e.span, "consider using", sugg::make_binop(ast::BinOpKind::Ne, &arg, &zero).to_string(), + Applicability::Unspecified, ); }, ) @@ -432,10 +461,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { } else { arg }; - db.span_suggestion( + db.span_suggestion_with_applicability( e.span, "consider using", format!("{}::from_bits({})", to_ty, arg.to_string()), + Applicability::Unspecified, ); }, ) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index c113dd7e5a35..856fa80569f7 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -575,7 +575,7 @@ pub fn span_lint_and_sugg<'a, 'tcx: 'a, T: LintContext<'tcx>>( sugg: String, ) { span_lint_and_then(cx, lint, sp, msg, |db| { - db.span_suggestion(sp, help, sugg); + db.span_suggestion_with_applicability(sp, help, sugg, Applicability::Unspecified); }); } diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index f849cef093a6..f7d8c1fc1512 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -15,6 +15,7 @@ use crate::syntax::util::parser::AssocOp; use crate::syntax::ast; use crate::utils::{higher, snippet, snippet_opt}; use crate::syntax_pos::{BytePos, Pos}; +use crate::rustc_errors::Applicability; /// A helper type to build suggestion correctly handling parenthesis. pub enum Sugg<'a> { @@ -496,7 +497,12 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error if let Some(indent) = indentation(cx, item) { let span = item.with_hi(item.lo()); - self.span_suggestion(span, msg, format!("{}\n{}", attr, indent)); + self.span_suggestion_with_applicability( + span, + msg, + format!("{}\n{}", attr, indent), + Applicability::Unspecified, + ); } } @@ -517,7 +523,12 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error }) .collect::(); - self.span_suggestion(span, msg, format!("{}\n{}", new_item, indent)); + self.span_suggestion_with_applicability( + span, + msg, + format!("{}\n{}", new_item, indent), + Applicability::Unspecified, + ); } } @@ -534,6 +545,11 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error } } - self.span_suggestion(remove_span, msg, String::new()); + self.span_suggestion_with_applicability( + remove_span, + msg, + String::new(), + Applicability::Unspecified, + ); } } From d4c994e670dbf97b2f0858f54c5a75d64863f866 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Sat, 15 Sep 2018 19:28:51 +0300 Subject: [PATCH 2/8] Supplement DiagnosticBuilderExt with Applicability --- clippy_lints/src/inline_fn_without_body.rs | 3 ++- clippy_lints/src/new_without_default.rs | 10 +++++++++- clippy_lints/src/utils/sugg.rs | 18 +++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 29492cf8c436..cedcdec1062f 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -6,6 +6,7 @@ use crate::rustc::hir::*; use crate::syntax::ast::{Attribute, Name}; use crate::utils::span_lint_and_then; use crate::utils::sugg::DiagnosticBuilderExt; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for `#[inline]` on trait methods without bodies /// @@ -56,7 +57,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, name: Name, attrs: &[Attribute]) { attr.span, &format!("use of `#[inline]` on trait method `{}` which has no body", name), |db| { - db.suggest_remove_item(cx, attr.span, "remove"); + db.suggest_remove_item(cx, attr.span, "remove", Applicability::Unspecified); }, ); } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 131f73b7c617..0163849dd229 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -8,6 +8,7 @@ use crate::syntax::source_map::Span; use crate::utils::paths; use crate::utils::{get_trait_def_id, implements_trait, return_ty, same_tys, span_lint_and_then}; use crate::utils::sugg::DiagnosticBuilderExt; +use crate::rustc_errors::Applicability; /// **What it does:** Checks for types with a `fn new() -> Self` method and no /// implementation of @@ -129,7 +130,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { impl_item.span, &format!("you should consider deriving a `Default` implementation for `{}`", self_ty), |db| { - db.suggest_item_with_attr(cx, sp, "try this", "#[derive(Default)]"); + db.suggest_item_with_attr( + cx, + sp, + "try this", + "#[derive(Default)]", + Applicability::Unspecified, + ); }); } else { span_lint_and_then( @@ -143,6 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { item.span, "try this", &create_new_without_default_suggest_msg(self_ty), + Applicability::Unspecified, ); }, ); diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index f7d8c1fc1512..0cdfd623f45e 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -462,7 +462,7 @@ pub trait DiagnosticBuilderExt<'a, T: LintContext<'a>> { /// ```rust,ignore /// db.suggest_item_with_attr(cx, item, "#[derive(Default)]"); /// ``` - fn suggest_item_with_attr(&mut self, cx: &T, item: Span, msg: &str, attr: &D); + fn suggest_item_with_attr(&mut self, cx: &T, item: Span, msg: &str, attr: &D, applicability: Applicability); /// Suggest to add an item before another. /// @@ -476,7 +476,7 @@ pub trait DiagnosticBuilderExt<'a, T: LintContext<'a>> { /// bar(); /// }"); /// ``` - fn suggest_prepend_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str); + fn suggest_prepend_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str, applicability: Applicability); /// Suggest to completely remove an item. /// @@ -489,11 +489,11 @@ pub trait DiagnosticBuilderExt<'a, T: LintContext<'a>> { /// ```rust,ignore /// db.suggest_remove_item(cx, item, "remove this") /// ``` - fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str); + fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability); } impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_errors::DiagnosticBuilder<'b> { - fn suggest_item_with_attr(&mut self, cx: &T, item: Span, msg: &str, attr: &D) { + fn suggest_item_with_attr(&mut self, cx: &T, item: Span, msg: &str, attr: &D, applicability: Applicability) { if let Some(indent) = indentation(cx, item) { let span = item.with_hi(item.lo()); @@ -501,12 +501,12 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error span, msg, format!("{}\n{}", attr, indent), - Applicability::Unspecified, + applicability, ); } } - fn suggest_prepend_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str) { + fn suggest_prepend_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str, applicability: Applicability) { if let Some(indent) = indentation(cx, item) { let span = item.with_hi(item.lo()); @@ -527,12 +527,12 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error span, msg, format!("{}\n{}", new_item, indent), - Applicability::Unspecified, + applicability, ); } } - fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str) { + fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability) { let mut remove_span = item; let hi = cx.sess().source_map().next_point(remove_span).hi(); let fmpos = cx.sess().source_map().lookup_byte_offset(hi); @@ -549,7 +549,7 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error remove_span, msg, String::new(), - Applicability::Unspecified, + applicability, ); } } From 3e853a632e7f7b14feda78a076058d2058cfdbb5 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Sat, 15 Sep 2018 19:32:35 +0300 Subject: [PATCH 3/8] Add forgotten function: span_suggestion*s* to the previous refactoting --- clippy_lints/src/booleans.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 85f6eeb19ef9..c00256842b6c 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -418,7 +418,12 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { NONMINIMAL_BOOL, e.span, "this boolean expression can be simplified", - |db| { db.span_suggestions(e.span, "try", suggestions); }, + |db| { db.span_suggestions_with_applicability( + e.span, + "try", + suggestions, + Applicability::Unspecified, + ); }, ); }; if improvements.is_empty() { From 2781cac8397b5d814e9d2b703863c32d66ba31c3 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Sun, 16 Sep 2018 22:01:26 +0300 Subject: [PATCH 4/8] Apply subset of "cargo fmt". --- clippy_lints/src/assign_ops.rs | 6 +++--- clippy_lints/src/attrs.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 5cf714bed86a..89541dd7e334 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -93,11 +93,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { Applicability::Unspecified, ); db.span_suggestion_with_applicability( - expr.span, - "or", + expr.span, + "or", long, Applicability::Unspecified, - ); + ); } }, ); diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 197aa88cbbea..b04eaeaebc3a 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -209,7 +209,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass { "if you just forgot a `!`, use", sugg, Applicability::Unspecified, - ); + ); }, ); } From 3eccccb367de1bc68835465cf3a38bc1a0311df9 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Tue, 18 Sep 2018 18:07:54 +0300 Subject: [PATCH 5/8] Fix indents --- clippy_lints/src/bit_mask.rs | 2 +- clippy_lints/src/booleans.rs | 6 ++- clippy_lints/src/collapsible_if.rs | 17 +++++--- clippy_lints/src/const_static_lifetime.rs | 2 +- clippy_lints/src/entry.rs | 20 ++++----- clippy_lints/src/eq_op.rs | 33 +++++++------- clippy_lints/src/eta_reduction.rs | 10 ++--- clippy_lints/src/format.rs | 20 ++++----- clippy_lints/src/identity_conversion.rs | 30 ++++++------- clippy_lints/src/int_plus_one.rs | 10 ++--- clippy_lints/src/let_if_seq.rs | 10 ++--- clippy_lints/src/map_unit_fn.rs | 20 +++++---- clippy_lints/src/matches.rs | 10 ++--- clippy_lints/src/methods.rs | 32 +++++++------- clippy_lints/src/misc.rs | 45 ++++++++++--------- clippy_lints/src/misc_early.rs | 10 ++--- clippy_lints/src/needless_borrow.rs | 20 ++++----- clippy_lints/src/needless_borrowed_ref.rs | 10 ++--- clippy_lints/src/needless_pass_by_value.rs | 20 ++++----- clippy_lints/src/new_without_default.rs | 12 +++--- clippy_lints/src/ptr.rs | 20 ++++----- clippy_lints/src/ranges.rs | 33 +++++++------- clippy_lints/src/returns.rs | 10 ++--- clippy_lints/src/swap.rs | 26 +++++------ clippy_lints/src/transmute.rs | 50 +++++++++++----------- clippy_lints/src/utils/sugg.rs | 10 ++--- 26 files changed, 253 insertions(+), 235 deletions(-) diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 52c6d4c71dcf..d33bf670f6f5 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -144,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { "try", format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()), Applicability::Unspecified, - ); + ); }); } } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index c00256842b6c..604e27f56ee4 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -418,12 +418,14 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { NONMINIMAL_BOOL, e.span, "this boolean expression can be simplified", - |db| { db.span_suggestions_with_applicability( + |db| { + db.span_suggestions_with_applicability( e.span, "try", suggestions, Applicability::Unspecified, - ); }, + ); + }, ); }; if improvements.is_empty() { diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index c139b0f0c1f1..dcc0f65e3fc6 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -134,13 +134,16 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: & span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this if statement can be collapsed", |db| { let lhs = Sugg::ast(cx, check, ".."); let rhs = Sugg::ast(cx, check_inner, ".."); - db.span_suggestion_with_applicability(expr.span, - "try", - format!("if {} {}", - lhs.and(&rhs), - snippet_block(cx, content.span, "..")), - Applicability::Unspecified, - ); + db.span_suggestion_with_applicability( + expr.span, + "try", + format!( + "if {} {}", + lhs.and(&rhs), + snippet_block(cx, content.span, ".."), + ), + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/const_static_lifetime.rs b/clippy_lints/src/const_static_lifetime.rs index 92c609d9858d..4edc84c9d092 100644 --- a/clippy_lints/src/const_static_lifetime.rs +++ b/clippy_lints/src/const_static_lifetime.rs @@ -66,7 +66,7 @@ impl StaticConst { "consider removing `'static`", sugg, Applicability::Unspecified, - ); + ); }, ); } diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index be9af18c9112..71203a247bfe 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -141,11 +141,11 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { snippet(self.cx, params[2].span, "..")); db.span_suggestion_with_applicability( - self.span, - "consider using", - help, - Applicability::Unspecified, - ); + self.span, + "consider using", + help, + Applicability::Unspecified, + ); } else { let help = format!("{}.entry({})", @@ -153,11 +153,11 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { snippet(self.cx, params[1].span, "..")); db.span_suggestion_with_applicability( - self.span, - "consider using", - help, - Applicability::Unspecified, - ); + self.span, + "consider using", + help, + Applicability::Unspecified, + ); } }); } diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 2ad04cd6fbe2..f71472653bfa 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -115,11 +115,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| { let lsnip = snippet(cx, l.span, "...").to_string(); db.span_suggestion_with_applicability( - left.span, - "use the left value directly", - lsnip, - Applicability::Unspecified, - ); + left.span, + "use the left value directly", + lsnip, + Applicability::Unspecified, + ); }) } else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) { span_lint_and_then( @@ -133,7 +133,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { right.span, "use the right value directly", rsnip, - Applicability::Unspecified,); + Applicability::Unspecified, + ); }, ) } @@ -146,11 +147,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| { let lsnip = snippet(cx, l.span, "...").to_string(); db.span_suggestion_with_applicability( - left.span, - "use the left value directly", - lsnip, - Applicability::Unspecified, - ); + left.span, + "use the left value directly", + lsnip, + Applicability::Unspecified, + ); }) } }, @@ -162,11 +163,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| { let rsnip = snippet(cx, r.span, "...").to_string(); db.span_suggestion_with_applicability( - right.span, - "use the right value directly", - rsnip, - Applicability::Unspecified, - ); + right.span, + "use the right value directly", + rsnip, + Applicability::Unspecified, + ); }) } }, diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index b40ff8b51cd1..f18358121d65 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -98,11 +98,11 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| { if let Some(snippet) = snippet_opt(cx, caller.span) { db.span_suggestion_with_applicability( - expr.span, - "remove closure as shown", - snippet, - Applicability::Unspecified, - ); + expr.span, + "remove closure as shown", + snippet, + Applicability::Unspecified, + ); } }); } diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 868b7c19cef1..29dca4556a5d 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -62,11 +62,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let sugg = format!("{}.to_string()", snippet(cx, format_arg, "").into_owned()); span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| { db.span_suggestion_with_applicability( - expr.span, - "consider using .to_string()", - sugg, - Applicability::Unspecified, - ); + expr.span, + "consider using .to_string()", + sugg, + Applicability::Unspecified, + ); }); } } @@ -77,11 +77,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let sugg = format!("{}.to_string()", snippet(cx, expr.span, "").into_owned()); span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| { db.span_suggestion_with_applicability( - span, - "consider using .to_string()", - sugg, - Applicability::Unspecified, - ); + span, + "consider using .to_string()", + sugg, + Applicability::Unspecified, + ); }); } }, diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs index 2a764ad73d47..411d7511d882 100644 --- a/clippy_lints/src/identity_conversion.rs +++ b/clippy_lints/src/identity_conversion.rs @@ -65,11 +65,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { let sugg = snippet(cx, args[0].span, "").into_owned(); span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| { db.span_suggestion_with_applicability( - e.span, - "consider removing `.into()`", - sugg, - Applicability::Unspecified, - ); + e.span, + "consider removing `.into()`", + sugg, + Applicability::Unspecified, + ); }); } } @@ -80,11 +80,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { let sugg = snippet(cx, args[0].span, "").into_owned(); span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| { db.span_suggestion_with_applicability( - e.span, - "consider removing `.into_iter()`", - sugg, - Applicability::Unspecified, - ); + e.span, + "consider removing `.into_iter()`", + sugg, + Applicability::Unspecified, + ); }); } } @@ -100,11 +100,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { let sugg_msg = format!("consider removing `{}()`", snippet(cx, path.span, "From::from")); span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| { db.span_suggestion_with_applicability( - e.span, - &sugg_msg, - sugg, - Applicability::Unspecified, - ); + e.span, + &sugg_msg, + sugg, + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 4608ca696e1e..14566c4f02db 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -154,11 +154,11 @@ impl IntPlusOne { fn emit_warning(&self, cx: &EarlyContext<'_>, block: &Expr, recommendation: String) { span_lint_and_then(cx, INT_PLUS_ONE, block.span, "Unnecessary `>= y + 1` or `x - 1 >=`", |db| { db.span_suggestion_with_applicability( - block.span, - "change `>= y + 1` to `> y` as shown", - recommendation, - Applicability::Unspecified, - ); + block.span, + "change `>= y + 1` to `> y` as shown", + recommendation, + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 4947715e293d..bdeaeda7bc5d 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -122,11 +122,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { "`if _ { .. } else { .. }` is an expression", |db| { db.span_suggestion_with_applicability( - span, - "it is more idiomatic to write", - sug, - Applicability::Unspecified, - ); + span, + "it is more idiomatic to write", + sug, + Applicability::Unspecified, + ); if !mutability.is_empty() { db.note("you might not need `mut` at all"); } diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 5f592a722d1d..f4d48e3ad9ad 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -229,20 +229,22 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr snippet(cx, var_arg.span, "_"), snippet(cx, reduced_expr_span, "_")); db.span_suggestion_with_applicability( - stmt.span, - "try this", - suggestion, - Applicability::Unspecified, - ); + stmt.span, + "try this", + suggestion, + Applicability::Unspecified, + ); } else { let suggestion = format!("if let {0}({1}) = {2} {{ ... }}", variant, snippet(cx, binding.pat.span, "_"), snippet(cx, var_arg.span, "_")); - db.span_suggestion_with_applicability(stmt.span, - "try this", - suggestion, - Applicability::Unspecified); + db.span_suggestion_with_applicability( + stmt.span, + "try this", + suggestion, + Applicability::Unspecified, + ); } }); } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 7cc70cb0834b..d8e11d684795 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -341,11 +341,11 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex if let Some(sugg) = sugg { db.span_suggestion_with_applicability( - expr.span, - "consider using an if/else expression", - sugg, - Applicability::Unspecified, - ); + expr.span, + "consider using an if/else expression", + sugg, + Applicability::Unspecified, + ); } } } diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index f61995cf2650..5f8dc63ea573 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -1129,17 +1129,17 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp let derefs: String = iter::repeat('*').take(n).collect(); let explicit = format!("{}{}::clone({})", refs, ty, snip); db.span_suggestion_with_applicability( - expr.span, - "try dereferencing it", - format!("{}({}{}).clone()", refs, derefs, snip.deref()), - Applicability::Unspecified, - ); + expr.span, + "try dereferencing it", + format!("{}({}{}).clone()", refs, derefs, snip.deref()), + Applicability::Unspecified, + ); db.span_suggestion_with_applicability( - expr.span, - "or try being explicit about what type to clone", - explicit, - Applicability::Unspecified, - ); + expr.span, + "or try being explicit about what type to clone", + explicit, + Applicability::Unspecified, + ); }, ); return; // don't report clone_on_copy @@ -1185,7 +1185,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp text, snip, Applicability::Unspecified, - ); + ); } }); } @@ -1656,11 +1656,11 @@ fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, let hint = format!("{0}.and_then({1})", map_or_self_snippet, map_or_func_snippet); span_lint_and_then(cx, OPTION_MAP_OR_NONE, expr.span, msg, |db| { db.span_suggestion_with_applicability( - expr.span, - "try using and_then instead", - hint, - Applicability::Unspecified, - ); + expr.span, + "try using and_then instead", + hint, + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index ac4e93f633a2..0f0c86bfeb26 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -295,14 +295,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { l.pat.span, "`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead", |db| { - db.span_suggestion_with_applicability(s.span, - "try", - format!("let {name}{tyopt} = {initref};", - name=snippet(cx, i.span, "_"), - tyopt=tyopt, - initref=initref), - Applicability::Unspecified, - ); + db.span_suggestion_with_applicability( + s.span, + "try", + format!( + "let {name}{tyopt} = {initref};", + name=snippet(cx, i.span, "_"), + tyopt=tyopt, + initref=initref, + ), + Applicability::Unspecified, + ); } ); } @@ -321,13 +324,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { |db| { let sugg = if binop.node == BinOpKind::Or { !sugg } else { sugg }; db.span_suggestion_with_applicability( - s.span, - "replace it with", - format!("if {} {{ {}; }}", - sugg, - &snippet(cx, b.span, "..")), - Applicability::Unspecified, - ); + s.span, + "replace it with", + format!( + "if {} {{ {}; }}", + sugg, + &snippet(cx, b.span, ".."), + ), + Applicability::Unspecified, + ); }); } }; @@ -545,11 +550,11 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) { } } db.span_suggestion_with_applicability( - expr.span, - "try", - snip.to_string(), - Applicability::Unspecified, - ); + expr.span, + "try", + snip.to_string(), + Applicability::Unspecified, + ); }, ); } diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index c66fb5d6e47f..07c363d6f246 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -309,11 +309,11 @@ impl EarlyLintPass for MiscEarly { |db| if decl.inputs.is_empty() { let hint = snippet(cx, block.span, "..").into_owned(); db.span_suggestion_with_applicability( - expr.span, - "Try doing something like: ", - hint, - Applicability::Unspecified, - ); + expr.span, + "Try doing something like: ", + hint, + Applicability::Unspecified, + ); }, ); } diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 11e1a99fd7fc..1e0db1a0f9ae 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -77,11 +77,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { |db| { if let Some(snippet) = snippet_opt(cx, inner.span) { db.span_suggestion_with_applicability( - e.span, - "change this to", - snippet, - Applicability::Unspecified, - ); + e.span, + "change this to", + snippet, + Applicability::Unspecified, + ); } }, ); @@ -110,11 +110,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { |db| { if let Some(snippet) = snippet_opt(cx, name.span) { db.span_suggestion_with_applicability( - pat.span, - "change this to", - snippet, - Applicability::Unspecified, - ); + pat.span, + "change this to", + snippet, + Applicability::Unspecified, + ); } } ) diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index 08ce0de21c6f..fd275752506c 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -79,11 +79,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef { |db| { let hint = snippet(cx, spanned_name.span, "..").into_owned(); db.span_suggestion_with_applicability( - pat.span, - "try removing the `&ref` part and just keep", - hint, - Applicability::Unspecified, - ); + pat.span, + "try removing the `&ref` part and just keep", + hint, + Applicability::Unspecified, + ); }); } } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index aa644e4c3398..980e2c28a348 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -229,11 +229,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { then { let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_")); db.span_suggestion_with_applicability( - input.span, - "consider changing the type to", - slice_ty, - Applicability::Unspecified, - ); + input.span, + "consider changing the type to", + slice_ty, + Applicability::Unspecified, + ); for (span, suggestion) in clone_spans { db.span_suggestion_with_applicability( @@ -258,11 +258,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { if let Some(clone_spans) = get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) { db.span_suggestion_with_applicability( - input.span, - "consider changing the type to", - "&str".to_string(), - Applicability::Unspecified, - ); + input.span, + "consider changing the type to", + "&str".to_string(), + Applicability::Unspecified, + ); for (span, suggestion) in clone_spans { db.span_suggestion_with_applicability( diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 0163849dd229..bf5fbb8a7f5b 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -131,12 +131,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { &format!("you should consider deriving a `Default` implementation for `{}`", self_ty), |db| { db.suggest_item_with_attr( - cx, - sp, - "try this", - "#[derive(Default)]", - Applicability::Unspecified, - ); + cx, + sp, + "try this", + "#[derive(Default)]", + Applicability::Unspecified, + ); }); } else { span_lint_and_then( diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index f8d872cb4e6d..86cb89f2de12 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -212,11 +212,11 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id: "writing `&String` instead of `&str` involves a new object where a slice will do.", |db| { db.span_suggestion_with_applicability( - arg.span, - "change this to", - "&str".into(), - Applicability::Unspecified, - ); + arg.span, + "change this to", + "&str".into(), + Applicability::Unspecified, + ); for (clonespan, suggestion) in spans { db.span_suggestion_short_with_applicability( clonespan, @@ -253,11 +253,11 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id: "using a reference to `Cow` is not recommended.", |db| { db.span_suggestion_with_applicability( - arg.span, - "change this to", - "&".to_owned() + &r, - Applicability::Unspecified, - ); + arg.span, + "change this to", + "&".to_owned() + &r, + Applicability::Unspecified, + ); }, ); } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 8ca0750684e1..71b68d97e401 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -151,17 +151,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let end = Sugg::hir(cx, y, "y"); if let Some(is_wrapped) = &snippet_opt(cx, expr.span) { if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') { - db.span_suggestion_with_applicability(expr.span, - "use", - format!("({}..={})", start, end), - Applicability::Unspecified, - ); + db.span_suggestion_with_applicability( + expr.span, + "use", + format!("({}..={})", start, end), + Applicability::Unspecified, + ); } else { - db.span_suggestion_with_applicability(expr.span, - "use", - format!("{}..={}", start, end), - Applicability::Unspecified, - ); + db.span_suggestion_with_applicability( + expr.span, + "use", + format!("{}..={}", start, end), + Applicability::Unspecified, + ); } } }, @@ -182,11 +184,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { |db| { let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string()); let end = Sugg::hir(cx, y, "y"); - db.span_suggestion_with_applicability(expr.span, - "use", - format!("{}..{}", start, end), - Applicability::Unspecified, - ); + db.span_suggestion_with_applicability( + expr.span, + "use", + format!("{}..{}", start, end), + Applicability::Unspecified, + ); }, ); } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 34b7614e4396..f90d8659dbe8 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -110,11 +110,11 @@ impl ReturnPass { span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| { if let Some(snippet) = snippet_opt(cx, inner_span) { db.span_suggestion_with_applicability( - ret_span, - "remove `return` as shown", - snippet, - Applicability::Unspecified, - ); + ret_span, + "remove `return` as shown", + snippet, + Applicability::Unspecified, + ); } }); } diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 8859d5451946..5ca78957f08e 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -138,11 +138,11 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) { |db| { if !sugg.is_empty() { db.span_suggestion_with_applicability( - span, - "try", - sugg, - Applicability::Unspecified, - ); + span, + "try", + sugg, + Applicability::Unspecified, + ); if replace { db.note("or maybe you should use `std::mem::replace`?"); @@ -187,13 +187,15 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) { |db| { if !what.is_empty() { db.span_suggestion_with_applicability( - span, - "try", - format!("std::mem::swap({}, {})", - lhs, - rhs), - Applicability::Unspecified, - ); + span, + "try", + format!( + "std::mem::swap({}, {})", + lhs, + rhs, + ), + Applicability::Unspecified, + ); db.note("or maybe you should use `std::mem::replace`?"); } }); diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index cdd0260b4fee..69422056df5e 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -247,11 +247,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { }; db.span_suggestion_with_applicability( - e.span, - "try", - sugg.to_string(), - Applicability::Unspecified, - ); + e.span, + "try", + sugg.to_string(), + Applicability::Unspecified, + ); }, ), (&ty::Int(_), &ty::RawPtr(_)) | (&ty::Uint(_), &ty::RawPtr(_)) => { @@ -262,11 +262,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { "transmute from an integer to a pointer", |db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { db.span_suggestion_with_applicability( - e.span, - "try", - arg.as_ty(&to_ty.to_string()).to_string(), - Applicability::Unspecified, - ); + e.span, + "try", + arg.as_ty(&to_ty.to_string()).to_string(), + Applicability::Unspecified, + ); }, ) }, @@ -324,11 +324,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { }; db.span_suggestion_with_applicability( - e.span, - "try", - sugg::make_unop(deref, arg).to_string(), - Applicability::Unspecified, - ); + e.span, + "try", + sugg::make_unop(deref, arg).to_string(), + Applicability::Unspecified, + ); }, ), (&ty::Int(ast::IntTy::I32), &ty::Char) | @@ -399,11 +399,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { sugg_paren.addr_deref() }; db.span_suggestion_with_applicability( - e.span, - "try", - sugg.to_string(), - Applicability::Unspecified, - ); + e.span, + "try", + sugg.to_string(), + Applicability::Unspecified, + ); }, ) } @@ -418,11 +418,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { |db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { let sugg = arg.as_ty(cx.tcx.mk_ptr(to_ty)); db.span_suggestion_with_applicability( - e.span, - "try", - sugg.to_string(), - Applicability::Unspecified, - ); + e.span, + "try", + sugg.to_string(), + Applicability::Unspecified, + ); }, ), (&ty::Int(ast::IntTy::I8), &ty::Bool) | (&ty::Uint(ast::UintTy::U8), &ty::Bool) => { diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 0cdfd623f45e..076907e49452 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -546,10 +546,10 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error } self.span_suggestion_with_applicability( - remove_span, - msg, - String::new(), - applicability, - ); + remove_span, + msg, + String::new(), + applicability, + ); } } From 58729346bed9f7c15c461665202fab5b7ec628c8 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Tue, 18 Sep 2018 20:01:17 +0300 Subject: [PATCH 6/8] Fill in Applicability from review comments by @flip1995 --- clippy_lints/src/assign_ops.rs | 6 +++--- clippy_lints/src/attrs.rs | 2 +- clippy_lints/src/bit_mask.rs | 2 +- clippy_lints/src/booleans.rs | 4 ++++ clippy_lints/src/collapsible_if.rs | 2 +- clippy_lints/src/const_static_lifetime.rs | 2 +- clippy_lints/src/entry.rs | 4 ++-- clippy_lints/src/eq_op.rs | 8 ++++---- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/format.rs | 4 ++-- clippy_lints/src/identity_conversion.rs | 6 +++--- clippy_lints/src/if_let_redundant_pattern_matching.rs | 2 +- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/int_plus_one.rs | 2 +- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/loops.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/matches.rs | 2 +- clippy_lints/src/methods.rs | 6 +++--- clippy_lints/src/misc.rs | 8 ++++---- clippy_lints/src/misc_early.rs | 6 +++--- clippy_lints/src/needless_borrow.rs | 4 ++-- clippy_lints/src/needless_borrowed_ref.rs | 2 +- clippy_lints/src/new_without_default.rs | 4 ++-- clippy_lints/src/question_mark.rs | 2 +- clippy_lints/src/ranges.rs | 6 +++--- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/swap.rs | 2 +- 29 files changed, 52 insertions(+), 48 deletions(-) diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 89541dd7e334..a05a4d55010b 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -90,13 +90,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { long ), format!("{} {}= {}", snip_a, op.node.as_str(), snip_r), - Applicability::Unspecified, + Applicability::MachineApplicable, ); db.span_suggestion_with_applicability( expr.span, "or", long, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); } }, @@ -183,7 +183,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { expr.span, "replace it with", format!("{} {}= {}", snip_a, op.node.as_str(), snip_r), - Applicability::Unspecified, + Applicability::MachineApplicable, ); } }, diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index b04eaeaebc3a..e192c3f2093f 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -208,7 +208,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass { line_span, "if you just forgot a `!`, use", sugg, - Applicability::Unspecified, + Applicability::MachineApplicable, ); }, ); diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index d33bf670f6f5..7151e8db9aa5 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -143,7 +143,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { e.span, "try", format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); }); } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 604e27f56ee4..1201b4a0c649 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -395,6 +395,8 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { e.span, "it would look like the following", suggest(self.cx, suggestion, &h2q.terminals).0, + // nonminimal_bool can produce minimal but + // not human readable expressions (#3141) Applicability::Unspecified, ); }, @@ -423,6 +425,8 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { e.span, "try", suggestions, + // nonminimal_bool can produce minimal but + // not human readable expressions (#3141) Applicability::Unspecified, ); }, diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index dcc0f65e3fc6..b0fb058116f2 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -142,7 +142,7 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: & lhs.and(&rhs), snippet_block(cx, content.span, ".."), ), - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }); } diff --git a/clippy_lints/src/const_static_lifetime.rs b/clippy_lints/src/const_static_lifetime.rs index 4edc84c9d092..bb9829ad3c94 100644 --- a/clippy_lints/src/const_static_lifetime.rs +++ b/clippy_lints/src/const_static_lifetime.rs @@ -65,7 +65,7 @@ impl StaticConst { ty.span, "consider removing `'static`", sugg, - Applicability::Unspecified, + Applicability::MachineApplicable, //snippet ); }, ); diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 71203a247bfe..965d425b43d5 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -144,7 +144,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { self.span, "consider using", help, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); } else { @@ -156,7 +156,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { self.span, "consider using", help, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); } }); diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index f71472653bfa..7b9f2568da9a 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -118,7 +118,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { left.span, "use the left value directly", lsnip, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }) } else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) { @@ -133,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { right.span, "use the right value directly", rsnip, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }, ) @@ -150,7 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { left.span, "use the left value directly", lsnip, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }) } @@ -166,7 +166,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { right.span, "use the right value directly", rsnip, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }) } diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index f18358121d65..556f76af3a7b 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -101,7 +101,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { expr.span, "remove closure as shown", snippet, - Applicability::Unspecified, + Applicability::MachineApplicable, ); } }); diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 29dca4556a5d..2eb95ebffbf4 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { expr.span, "consider using .to_string()", sugg, - Applicability::Unspecified, + Applicability::MachineApplicable, ); }); } @@ -80,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { span, "consider using .to_string()", sugg, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }); } diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs index 411d7511d882..5b1bd0ada7be 100644 --- a/clippy_lints/src/identity_conversion.rs +++ b/clippy_lints/src/identity_conversion.rs @@ -68,7 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { e.span, "consider removing `.into()`", sugg, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }); } @@ -83,7 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { e.span, "consider removing `.into_iter()`", sugg, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }); } @@ -103,7 +103,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion { e.span, &sugg_msg, sugg, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }); } diff --git a/clippy_lints/src/if_let_redundant_pattern_matching.rs b/clippy_lints/src/if_let_redundant_pattern_matching.rs index 64d088d2a991..c9fbf1b0775d 100644 --- a/clippy_lints/src/if_let_redundant_pattern_matching.rs +++ b/clippy_lints/src/if_let_redundant_pattern_matching.rs @@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { span, "try this", format!("if {}.{}", snippet(cx, op.span, "_"), good_method), - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }, ); diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index cedcdec1062f..881bebc2f604 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -57,7 +57,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, name: Name, attrs: &[Attribute]) { attr.span, &format!("use of `#[inline]` on trait method `{}` which has no body", name), |db| { - db.suggest_remove_item(cx, attr.span, "remove", Applicability::Unspecified); + db.suggest_remove_item(cx, attr.span, "remove", Applicability::MachineApplicable); }, ); } diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 14566c4f02db..69a19e2fb01f 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -157,7 +157,7 @@ impl IntPlusOne { block.span, "change `>= y + 1` to `> y` as shown", recommendation, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }); } diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 8ff53e15c314..c346585250ad 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -102,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant { "consider boxing the large fields to reduce the total size of the \ enum", format!("Box<{}>", snip), - Applicability::Unspecified, + Applicability::MachineApplicable, ); return; } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index bdeaeda7bc5d..ede55ce3721d 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -125,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { span, "it is more idiomatic to write", sug, - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); if !mutability.is_empty() { db.note("you might not need `mut` at all"); diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 70608b9895fd..2c05d9a198fe 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1206,7 +1206,7 @@ fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx dots = dots, start = start_snippet ), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); }, ); diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index f4d48e3ad9ad..40b81e6fdb88 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -232,7 +232,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr stmt.span, "try this", suggestion, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); } else { let suggestion = format!("if let {0}({1}) = {2} {{ ... }}", diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index d8e11d684795..4c99aeae199d 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -344,7 +344,7 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex expr.span, "consider using an if/else expression", sugg, - Applicability::Unspecified, + Applicability::MaybeIncorrect, // not sure ); } } diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 5f8dc63ea573..03e3d2628e84 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -1132,13 +1132,13 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp expr.span, "try dereferencing it", format!("{}({}{}).clone()", refs, derefs, snip.deref()), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); db.span_suggestion_with_applicability( expr.span, "or try being explicit about what type to clone", explicit, - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); }, ); @@ -1659,7 +1659,7 @@ fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, expr.span, "try using and_then instead", hint, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }); } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 0f0c86bfeb26..0fa05de28410 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -304,7 +304,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { tyopt=tyopt, initref=initref, ), - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); } ); @@ -331,7 +331,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { sugg, &snippet(cx, b.span, ".."), ), - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }); } @@ -381,7 +381,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { expr.span, "consider comparing them within some error", format!("({}).abs() < error", lhs - rhs), - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); db.span_note(expr.span, "std::f32::EPSILON and std::f64::EPSILON are available."); }); @@ -553,7 +553,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) { expr.span, "try", snip.to_string(), - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }, ); diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 07c363d6f246..d3e1ca937842 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -312,7 +312,7 @@ impl EarlyLintPass for MiscEarly { expr.span, "Try doing something like: ", hint, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }, ); @@ -402,13 +402,13 @@ impl MiscEarly { lit.span, "if you mean to use a decimal constant, remove the `0` to remove confusion", src.trim_left_matches(|c| c == '_' || c == '0').to_string(), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); db.span_suggestion_with_applicability( lit.span, "if you mean to use an octal constant, use `0o`", format!("0o{}", src.trim_left_matches(|c| c == '_' || c == '0')), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); }); } diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 1e0db1a0f9ae..8a676be99ea8 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -80,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { e.span, "change this to", snippet, - Applicability::Unspecified, + Applicability::MachineApplicable, ); } }, @@ -113,7 +113,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { pat.span, "change this to", snippet, - Applicability::Unspecified, + Applicability::MachineApplicable, ); } } diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index fd275752506c..057a097f4b75 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef { pat.span, "try removing the `&ref` part and just keep", hint, - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }); } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index bf5fbb8a7f5b..e0b54620faf9 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { sp, "try this", "#[derive(Default)]", - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); }); } else { @@ -150,7 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { item.span, "try this", &create_new_without_default_suggest_msg(self_ty), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); }, ); diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index f4920e52a710..ced0fe3ef506 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -75,7 +75,7 @@ impl QuestionMarkPass { expr.span, "replace_it_with", format!("{}?;", receiver_str), - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); } ) diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 71b68d97e401..c60ed3842d4f 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -155,14 +155,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { expr.span, "use", format!("({}..={})", start, end), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); } else { db.span_suggestion_with_applicability( expr.span, "use", format!("{}..={}", start, end), - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); } } @@ -188,7 +188,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { expr.span, "use", format!("{}..{}", start, end), - Applicability::Unspecified, + Applicability::MachineApplicable, // snippet ); }, ); diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index f90d8659dbe8..9ab6b50ada6b 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -113,7 +113,7 @@ impl ReturnPass { ret_span, "remove `return` as shown", snippet, - Applicability::Unspecified, + Applicability::MachineApplicable, ); } }); diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 5ca78957f08e..5de2f0e54a90 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -194,7 +194,7 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) { lhs, rhs, ), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); db.note("or maybe you should use `std::mem::replace`?"); } From 52fb7d461ea231310de16e721e3b850747f5cf41 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Tue, 18 Sep 2018 22:43:52 +0300 Subject: [PATCH 7/8] Applicability adjustment per additional comments --- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/matches.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index c346585250ad..8ff53e15c314 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -102,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant { "consider boxing the large fields to reduce the total size of the \ enum", format!("Box<{}>", snip), - Applicability::MachineApplicable, + Applicability::Unspecified, ); return; } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index ede55ce3721d..53d13407be35 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -125,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { span, "it is more idiomatic to write", sug, - Applicability::MaybeIncorrect, + Applicability::HasPlaceholders, ); if !mutability.is_empty() { db.note("you might not need `mut` at all"); diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 4c99aeae199d..c1a65e756a9e 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -344,7 +344,7 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex expr.span, "consider using an if/else expression", sugg, - Applicability::MaybeIncorrect, // not sure + Applicability::HasPlaceholders, ); } } From 987b34d09018e8f7c1b880bcb26e8483e6843869 Mon Sep 17 00:00:00 2001 From: flip1995 <9744647+flip1995@users.noreply.github.com> Date: Thu, 20 Sep 2018 14:38:13 +0200 Subject: [PATCH 8/8] Another Applicability adjustment --- clippy_lints/src/large_enum_variant.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 8ff53e15c314..e8982d92b562 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -102,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant { "consider boxing the large fields to reduce the total size of the \ enum", format!("Box<{}>", snip), - Applicability::Unspecified, + Applicability::MaybeIncorrect, ); return; }