Skip to content

Commit ce5bca9

Browse files
committed
Add applicability to span_lint_and_sugg
1 parent 5ec0c47 commit ce5bca9

24 files changed

+91
-14
lines changed

clippy_lints/src/bytecount.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc::lint::*;
33
use rustc::{declare_lint, lint_array};
44
use if_chain::if_chain;
55
use rustc::ty;
6+
use rustc_errors::Applicability;
67
use syntax::ast::{Name, UintTy};
78
use crate::utils::{contains_name, get_pat_name, match_type, paths, single_segment_path, snippet, span_lint_and_sugg,
89
walk_ptrs_ty};
@@ -86,7 +87,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
8687
"Consider using the bytecount crate",
8788
format!("bytecount::count({}, {})",
8889
snippet(cx, haystack.span, ".."),
89-
snippet(cx, needle.span, "..")));
90+
snippet(cx, needle.span, "..")),
91+
Applicability::HasPlaceholders);
9092
}
9193
};
9294
}

clippy_lints/src/collapsible_if.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
use rustc::lint::*;
1616
use rustc::{declare_lint, lint_array};
17+
use rustc_errors::Applicability;
1718
use if_chain::if_chain;
1819
use syntax::ast;
1920

@@ -114,7 +115,9 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext, else_: &ast::Expr) {
114115
block.span,
115116
"this `else { if .. }` block can be collapsed",
116117
"try",
117-
snippet_block(cx, else_.span, "..").into_owned());
118+
snippet_block(cx, else_.span, "..").into_owned(),
119+
Applicability::HasPlaceholders,
120+
);
118121
}
119122
_ => (),
120123
}

clippy_lints/src/default_trait_access.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc::lint::*;
33
use rustc::{declare_lint, lint_array};
44
use if_chain::if_chain;
55
use rustc::ty::TypeVariants;
6+
use rustc_errors::Applicability;
67

78
use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_id, paths, span_lint_and_sugg};
89

@@ -59,7 +60,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
5960
expr.span,
6061
&format!("Calling {} is more clear than this expression", replacement),
6162
"try",
62-
replacement);
63+
replacement,
64+
Applicability::MaybeIncorrect);
6365
}
6466
},
6567
QPath::TypeRelative(..) => {},

clippy_lints/src/double_comparison.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use rustc::hir::*;
44
use rustc::lint::*;
55
use rustc::{declare_lint, lint_array};
6+
use rustc_errors::Applicability;
67
use syntax::codemap::Span;
78

89
use crate::utils::{snippet, span_lint_and_sugg, SpanlessEq};
@@ -64,7 +65,7 @@ impl<'a, 'tcx> DoubleComparisonPass {
6465
let sugg = format!("{} {} {}", lhs_str, stringify!($op), rhs_str);
6566
span_lint_and_sugg(cx, DOUBLE_COMPARISONS, span,
6667
"This binary expression can be simplified",
67-
"try", sugg);
68+
"try", sugg, Applicability::HasPlaceholders);
6869
}}
6970
}
7071
match (op, lkind, rkind) {

clippy_lints/src/duration_subsec.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 if_chain::if_chain;
56
use syntax::codemap::Spanned;
67

@@ -58,6 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
5859
&format!("Calling `{}()` is more concise than this calculation", suggested_fn),
5960
"try",
6061
format!("{}.{}()", snippet(cx, args[0].span, "_"), suggested_fn),
62+
Applicability::HasPlaceholders,
6163
);
6264
}
6365
}

clippy_lints/src/excessive_precision.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc::lint::*;
33
use rustc::{declare_lint, lint_array};
44
use if_chain::if_chain;
55
use rustc::ty::TypeVariants;
6+
use rustc_errors::Applicability;
67
use std::f32;
78
use std::f64;
89
use std::fmt;
@@ -58,6 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
5859
"float has excessive precision",
5960
"consider changing the type or truncating it to",
6061
sugg,
62+
Applicability::MachineApplicable,
6163
);
6264
}
6365
}

clippy_lints/src/infallible_destructuring_match.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::utils::{get_arg_name, match_var, remove_blocks, snippet, span_lint_an
22
use rustc::hir::*;
33
use rustc::lint::*;
44
use rustc::{declare_lint, lint_array};
5+
use rustc_errors::Applicability;
56
use if_chain::if_chain;
67

78
/// **What it does:** Checks for matches being used to destructure a single-variant enum
@@ -74,6 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
7475
snippet(cx, local.pat.span, ".."),
7576
snippet(cx, target.span, ".."),
7677
),
78+
Applicability::HasPlaceholders,
7779
);
7880
}
7981
}

clippy_lints/src/len_zero.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc::hir::*;
33
use rustc::lint::*;
44
use rustc::{declare_lint, lint_array};
55
use rustc::ty;
6+
use rustc_errors::Applicability;
67
use std::collections::HashSet;
78
use syntax::ast::{Lit, LitKind, Name};
89
use syntax::codemap::{Span, Spanned};
@@ -226,6 +227,7 @@ fn check_len(cx: &LateContext, span: Span, method_name: Name, args: &[Expr], lit
226227
&format!("length comparison to {}", if compare_to == 0 { "zero" } else { "one" }),
227228
"using `is_empty` is more concise",
228229
format!("{}{}.is_empty()", op, snippet(cx, args[0].span, "_")),
230+
Applicability::HasPlaceholders,
229231
);
230232
}
231233
}

clippy_lints/src/literal_representation.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
use rustc::lint::*;
55
use rustc::{declare_lint, lint_array};
6+
use rustc_errors::Applicability;
67
use if_chain::if_chain;
78
use syntax::ast::*;
89
use syntax_pos;
@@ -238,6 +239,7 @@ impl WarningType {
238239
"long literal lacking separators",
239240
"consider",
240241
grouping_hint.to_owned(),
242+
Applicability::MachineApplicable,
241243
),
242244
WarningType::LargeDigitGroups => span_lint_and_sugg(
243245
cx,
@@ -246,6 +248,7 @@ impl WarningType {
246248
"digit groups should be smaller",
247249
"consider",
248250
grouping_hint.to_owned(),
251+
Applicability::MachineApplicable,
249252
),
250253
WarningType::InconsistentDigitGrouping => span_lint_and_sugg(
251254
cx,
@@ -254,6 +257,7 @@ impl WarningType {
254257
"digits grouped inconsistently by underscores",
255258
"consider",
256259
grouping_hint.to_owned(),
260+
Applicability::MachineApplicable,
257261
),
258262
WarningType::DecimalRepresentation => span_lint_and_sugg(
259263
cx,
@@ -262,6 +266,7 @@ impl WarningType {
262266
"integer literal has a better hexadecimal representation",
263267
"consider",
264268
grouping_hint.to_owned(),
269+
Applicability::MachineApplicable,
265270
),
266271
};
267272
}

clippy_lints/src/loops.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc::middle::mem_categorization::Categorization;
1515
use rustc::middle::mem_categorization::cmt_;
1616
use rustc::ty::{self, Ty};
1717
use rustc::ty::subst::Subst;
18+
use rustc_errors::Applicability;
1819
use std::collections::{HashMap, HashSet};
1920
use std::iter::{once, Iterator};
2021
use syntax::ast;
@@ -470,6 +471,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
470471
snippet(cx, arms[0].pats[0].span, ".."),
471472
snippet(cx, matchexpr.span, "..")
472473
),
474+
Applicability::HasPlaceholders,
473475
);
474476
}
475477
},
@@ -501,6 +503,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
501503
"this loop could be written as a `for` loop",
502504
"try",
503505
format!("for {} in {} {{ .. }}", loop_var, iterator),
506+
Applicability::HasPlaceholders,
504507
);
505508
}
506509
}
@@ -965,6 +968,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
965968
"it looks like you're manually copying between slices",
966969
"try replacing the loop by",
967970
big_sugg,
971+
Applicability::MachineApplicable,
968972
);
969973
}
970974
}
@@ -1200,6 +1204,7 @@ fn lint_iter_method(cx: &LateContext, args: &[Expr], arg: &Expr, method_name: &s
12001204
iteration methods",
12011205
"to write this more concisely, try",
12021206
format!("&{}{}", muta, object),
1207+
Applicability::HasPlaceholders,
12031208
)
12041209
}
12051210

@@ -1238,6 +1243,7 @@ fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) {
12381243
iteration methods`",
12391244
"to write this more concisely, try",
12401245
object.to_string(),
1246+
Applicability::HasPlaceholders,
12411247
);
12421248
}
12431249
} else if method_name == "next" && match_trait_method(cx, arg, &paths::ITERATOR) {

0 commit comments

Comments
 (0)