Skip to content

Commit ad605f3

Browse files
committed
Add applicability to multispan_sugg
1 parent ce5bca9 commit ad605f3

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

clippy_lints/src/eq_op.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc::hir::*;
22
use rustc::lint::*;
33
use rustc::{declare_lint, lint_array};
4+
use rustc_errors::Applicability;
45
use crate::utils::{in_macro, implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};
56

67
/// **What it does:** Checks for equal operands to comparison, logical and
@@ -107,6 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
107108
db,
108109
"use the values directly".to_string(),
109110
vec![(left.span, lsnip), (right.span, rsnip)],
111+
Applicability::HasPlaceholders,
110112
);
111113
},
112114
)

clippy_lints/src/loops.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ fn check_for_loop_range<'a, 'tcx>(
10731073
(pat.span, format!("({}, <item>)", ident.name)),
10741074
(arg.span, format!("{}.{}().enumerate(){}{}", indexed, method, take, skip)),
10751075
],
1076+
Applicability::HasPlaceholders,
10761077
);
10771078
},
10781079
);
@@ -1093,6 +1094,7 @@ fn check_for_loop_range<'a, 'tcx>(
10931094
db,
10941095
"consider using an iterator".to_string(),
10951096
vec![(pat.span, "<item>".to_string()), (arg.span, repl)],
1097+
Applicability::HasPlaceholders,
10961098
);
10971099
},
10981100
);
@@ -1404,6 +1406,7 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
14041406
(pat_span, snippet(cx, new_pat_span, kind).into_owned()),
14051407
(arg_span, format!("{}.{}s{}()", map.maybe_par(), kind, mutbl)),
14061408
],
1409+
Applicability::HasPlaceholders,
14071410
);
14081411
},
14091412
);

clippy_lints/src/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ fn check_match_ref_pats(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr)
433433
}));
434434

435435
span_lint_and_then(cx, MATCH_REF_PATS, expr.span, title, |db| {
436-
multispan_sugg(db, msg.to_owned(), suggs);
436+
multispan_sugg(db, msg.to_owned(), suggs, Applicability::HasPlaceholders);
437437
});
438438
}
439439
}

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc::ty::{self, RegionKind, TypeFoldable};
99
use rustc::traits;
1010
use rustc::middle::expr_use_visitor as euv;
1111
use rustc::middle::mem_categorization as mc;
12+
use rustc_errors::Applicability;
1213
use rustc_target::spec::abi::Abi;
1314
use syntax::ast::NodeId;
1415
use syntax_pos::Span;
@@ -284,7 +285,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
284285
);
285286
spans.sort_by_key(|&(span, _)| span);
286287
}
287-
multispan_sugg(db, "consider taking a reference instead".to_string(), spans);
288+
multispan_sugg(db,
289+
"consider taking a reference instead".to_string(),
290+
spans,
291+
Applicability::HasPlaceholders,
292+
);
288293
};
289294

290295
span_lint_and_then(

clippy_lints/src/types.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,10 +1793,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
17931793
format!("{}<{}, S>", target.type_name(), target.type_arguments(),),
17941794
),
17951795
],
1796+
Applicability::HasPlaceholders,
17961797
);
17971798

17981799
if !vis.suggestions.is_empty() {
1799-
multispan_sugg(db, "...and use generic constructor".into(), vis.suggestions);
1800+
multispan_sugg(db,
1801+
"...and use generic constructor".into(),
1802+
vis.suggestions,
1803+
Applicability::HasPlaceholders,
1804+
);
18001805
}
18011806
}
18021807

clippy_lints/src/utils/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,12 @@ pub fn span_lint_and_sugg<'a, 'tcx: 'a, T: LintContext<'tcx>>(
643643
/// appear once per
644644
/// replacement. In human-readable format though, it only appears once before
645645
/// the whole suggestion.
646-
pub fn multispan_sugg<I>(db: &mut DiagnosticBuilder, help_msg: String, sugg: I)
647-
where
646+
pub fn multispan_sugg<I>(
647+
db: &mut DiagnosticBuilder,
648+
help_msg: String,
649+
sugg: I,
650+
applicability: Applicability,
651+
) where
648652
I: IntoIterator<Item = (Span, String)>,
649653
{
650654
let sugg = CodeSuggestion {
@@ -662,7 +666,7 @@ where
662666
],
663667
msg: help_msg,
664668
show_code_when_inline: true,
665-
applicability: Applicability::Unspecified,
669+
applicability,
666670
};
667671
db.suggestions.push(sugg);
668672
}

0 commit comments

Comments
 (0)