manually fix the overlong lines
This commit is contained in:
parent
47eead5ada
commit
009c6d95d7
7 changed files with 77 additions and 35 deletions
|
@ -126,7 +126,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
||||||
return; // implements_trait does not work with generics
|
return; // implements_trait does not work with generics
|
||||||
}
|
}
|
||||||
macro_rules! ops {
|
macro_rules! ops {
|
||||||
($op:expr, $cx:expr, $ty:expr, $rty:expr, $($trait_name:ident:$full_trait_name:ident),+) => {
|
($op:expr,
|
||||||
|
$cx:expr,
|
||||||
|
$ty:expr,
|
||||||
|
$rty:expr,
|
||||||
|
$($trait_name:ident:$full_trait_name:ident),+) => {
|
||||||
match $op {
|
match $op {
|
||||||
$(hir::$full_trait_name => {
|
$(hir::$full_trait_name => {
|
||||||
let [krate, module] = ::utils::paths::OPS_MODULE;
|
let [krate, module] = ::utils::paths::OPS_MODULE;
|
||||||
|
@ -140,15 +144,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
||||||
let parent_fn = cx.tcx.map.get_parent(e.id);
|
let parent_fn = cx.tcx.map.get_parent(e.id);
|
||||||
let parent_impl = cx.tcx.map.get_parent(parent_fn);
|
let parent_impl = cx.tcx.map.get_parent(parent_fn);
|
||||||
// the crate node is the only one that is not in the map
|
// the crate node is the only one that is not in the map
|
||||||
if parent_impl != ast::CRATE_NODE_ID {
|
if_let_chain!{[
|
||||||
if let hir::map::Node::NodeItem(item) = cx.tcx.map.get(parent_impl) {
|
parent_impl != ast::CRATE_NODE_ID,
|
||||||
if let hir::Item_::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node {
|
let hir::map::Node::NodeItem(item) = cx.tcx.map.get(parent_impl),
|
||||||
if trait_ref.path.def.def_id() == trait_id {
|
let hir::Item_::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node,
|
||||||
return;
|
trait_ref.path.def.def_id() == trait_id
|
||||||
}
|
], { return; }}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
implements_trait($cx, $ty, trait_id, vec![$rty])
|
implements_trait($cx, $ty, trait_id, vec![$rty])
|
||||||
},)*
|
},)*
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -175,8 +175,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
|
||||||
let mut store = reg.sess.lint_store.borrow_mut();
|
let mut store = reg.sess.lint_store.borrow_mut();
|
||||||
store.register_removed("unstable_as_slice", "`Vec::as_slice` has been stabilized in 1.7");
|
store.register_removed("unstable_as_slice", "`Vec::as_slice` has been stabilized in 1.7");
|
||||||
store.register_removed("unstable_as_mut_slice", "`Vec::as_mut_slice` has been stabilized in 1.7");
|
store.register_removed("unstable_as_mut_slice", "`Vec::as_mut_slice` has been stabilized in 1.7");
|
||||||
store.register_removed("str_to_string", "using `str::to_string` is common even today and specialization will likely happen soon");
|
store.register_removed("str_to_string",
|
||||||
store.register_removed("string_to_string", "using `string::to_string` is common even today and specialization will likely happen soon");
|
"using `str::to_string` is common even today and specialization will likely happen soon");
|
||||||
|
store.register_removed("string_to_string",
|
||||||
|
"using `string::to_string` is common even today and specialization will likely happen soon");
|
||||||
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
|
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
|
||||||
|
|
||||||
reg.register_late_lint_pass(box serde::Serde);
|
reg.register_late_lint_pass(box serde::Serde);
|
||||||
|
@ -229,7 +231,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
|
||||||
reg.register_late_lint_pass(box map_clone::Pass);
|
reg.register_late_lint_pass(box map_clone::Pass);
|
||||||
reg.register_late_lint_pass(box temporary_assignment::Pass);
|
reg.register_late_lint_pass(box temporary_assignment::Pass);
|
||||||
reg.register_late_lint_pass(box transmute::Transmute);
|
reg.register_late_lint_pass(box transmute::Transmute);
|
||||||
reg.register_late_lint_pass(box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold));
|
reg.register_late_lint_pass(
|
||||||
|
box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold)
|
||||||
|
);
|
||||||
reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
|
reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
|
||||||
reg.register_early_lint_pass(box misc_early::MiscEarly);
|
reg.register_early_lint_pass(box misc_early::MiscEarly);
|
||||||
reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
|
reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
|
||||||
|
|
|
@ -333,8 +333,16 @@ impl EarlyLintPass for MiscEarly {
|
||||||
lit.span,
|
lit.span,
|
||||||
"this is a decimal constant",
|
"this is a decimal constant",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion(lit.span, "if you mean to use a decimal constant, remove the `0` to remove confusion:", src[1..].to_string());
|
db.span_suggestion(
|
||||||
db.span_suggestion(lit.span, "if you mean to use an octal constant, use `0o`:", format!("0o{}", &src[1..]));
|
lit.span,
|
||||||
|
"if you mean to use a decimal constant, remove the `0` to remove confusion:",
|
||||||
|
src[1..].to_string(),
|
||||||
|
);
|
||||||
|
db.span_suggestion(
|
||||||
|
lit.span,
|
||||||
|
"if you mean to use an octal constant, use `0o`:",
|
||||||
|
format!("0o{}", &src[1..]),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -374,7 +382,12 @@ impl EarlyLintPass for MiscEarly {
|
||||||
let ExprKind::Path(_, ref path) = closure.node
|
let ExprKind::Path(_, ref path) = closure.node
|
||||||
], {
|
], {
|
||||||
if sp_ident.node == (&path.segments[0]).identifier {
|
if sp_ident.node == (&path.segments[0]).identifier {
|
||||||
span_lint(cx, REDUNDANT_CLOSURE_CALL, second.span, "Closure called just once immediately after it was declared");
|
span_lint(
|
||||||
|
cx,
|
||||||
|
REDUNDANT_CLOSURE_CALL,
|
||||||
|
second.span,
|
||||||
|
"Closure called just once immediately after it was declared",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,11 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
|
||||||
SpanlessEq::new(cx).ignore_fn().eq_expr(tmp_init, lhs1),
|
SpanlessEq::new(cx).ignore_fn().eq_expr(tmp_init, lhs1),
|
||||||
SpanlessEq::new(cx).ignore_fn().eq_expr(rhs1, lhs2)
|
SpanlessEq::new(cx).ignore_fn().eq_expr(rhs1, lhs2)
|
||||||
], {
|
], {
|
||||||
fn check_for_slice<'a>(cx: &LateContext, lhs1: &'a Expr, lhs2: &'a Expr) -> Option<(&'a Expr, &'a Expr, &'a Expr)> {
|
fn check_for_slice<'a>(
|
||||||
|
cx: &LateContext,
|
||||||
|
lhs1: &'a Expr,
|
||||||
|
lhs2: &'a Expr,
|
||||||
|
) -> Option<(&'a Expr, &'a Expr, &'a Expr)> {
|
||||||
if let ExprIndex(ref lhs1, ref idx1) = lhs1.node {
|
if let ExprIndex(ref lhs1, ref idx1) = lhs1.node {
|
||||||
if let ExprIndex(ref lhs2, ref idx2) = lhs2.node {
|
if let ExprIndex(ref lhs2, ref idx2) = lhs2.node {
|
||||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) {
|
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) {
|
||||||
|
@ -104,7 +108,10 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
|
||||||
if let Some(slice) = Sugg::hir_opt(cx, slice) {
|
if let Some(slice) = Sugg::hir_opt(cx, slice) {
|
||||||
(false,
|
(false,
|
||||||
format!(" elements of `{}`", slice),
|
format!(" elements of `{}`", slice),
|
||||||
format!("{}.swap({}, {})", slice.maybe_par(), snippet(cx, idx1.span, ".."), snippet(cx, idx2.span, "..")))
|
format!("{}.swap({}, {})",
|
||||||
|
slice.maybe_par(),
|
||||||
|
snippet(cx, idx1.span, ".."),
|
||||||
|
snippet(cx, idx2.span, "..")))
|
||||||
} else {
|
} else {
|
||||||
(false, "".to_owned(), "".to_owned())
|
(false, "".to_owned(), "".to_owned())
|
||||||
}
|
}
|
||||||
|
@ -148,7 +155,9 @@ fn check_suspicious_swap(cx: &LateContext, block: &Block) {
|
||||||
SpanlessEq::new(cx).ignore_fn().eq_expr(lhs0, rhs1),
|
SpanlessEq::new(cx).ignore_fn().eq_expr(lhs0, rhs1),
|
||||||
SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, rhs0)
|
SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, rhs0)
|
||||||
], {
|
], {
|
||||||
let (what, lhs, rhs) = if let (Some(first), Some(second)) = (Sugg::hir_opt(cx, lhs0), Sugg::hir_opt(cx, rhs0)) {
|
let lhs0 = Sugg::hir_opt(cx, lhs0);
|
||||||
|
let rhs0 = Sugg::hir_opt(cx, rhs0);
|
||||||
|
let (what, lhs, rhs) = if let (Some(first), Some(second)) = (lhs0, rhs0) {
|
||||||
(format!(" `{}` and `{}`", first, second), first.mut_addr().to_string(), second.mut_addr().to_string())
|
(format!(" `{}` and `{}`", first, second), first.mut_addr().to_string(), second.mut_addr().to_string())
|
||||||
} else {
|
} else {
|
||||||
("".to_owned(), "".to_owned(), "".to_owned())
|
("".to_owned(), "".to_owned(), "".to_owned())
|
||||||
|
|
|
@ -131,7 +131,12 @@ macro_rules! define_Conf {
|
||||||
|
|
||||||
// how to read the value?
|
// how to read the value?
|
||||||
(CONV i64, $value: expr) => { $value.as_integer() };
|
(CONV i64, $value: expr) => { $value.as_integer() };
|
||||||
(CONV u64, $value: expr) => { $value.as_integer().iter().filter_map(|&i| if i >= 0 { Some(i as u64) } else { None }).next() };
|
(CONV u64, $value: expr) => {
|
||||||
|
$value.as_integer()
|
||||||
|
.iter()
|
||||||
|
.filter_map(|&i| if i >= 0 { Some(i as u64) } else { None })
|
||||||
|
.next()
|
||||||
|
};
|
||||||
(CONV String, $value: expr) => { $value.as_str().map(Into::into) };
|
(CONV String, $value: expr) => { $value.as_str().map(Into::into) };
|
||||||
(CONV Vec<String>, $value: expr) => {{
|
(CONV Vec<String>, $value: expr) => {{
|
||||||
let slice = $value.as_slice();
|
let slice = $value.as_slice();
|
||||||
|
@ -139,12 +144,10 @@ macro_rules! define_Conf {
|
||||||
if let Some(slice) = slice {
|
if let Some(slice) = slice {
|
||||||
if slice.iter().any(|v| v.as_str().is_none()) {
|
if slice.iter().any(|v| v.as_str().is_none()) {
|
||||||
None
|
None
|
||||||
|
} else {
|
||||||
|
Some(slice.iter().map(|v| v.as_str().expect("already checked").to_owned()).collect())
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
Some(slice.iter().map(|v| v.as_str().unwrap_or_else(|| unreachable!()).to_owned()).collect())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
|
@ -160,7 +163,19 @@ define_Conf! {
|
||||||
/// Lint: CYCLOMATIC_COMPLEXITY. The maximum cyclomatic complexity a function can have
|
/// Lint: CYCLOMATIC_COMPLEXITY. The maximum cyclomatic complexity a function can have
|
||||||
("cyclomatic-complexity-threshold", cyclomatic_complexity_threshold, 25 => u64),
|
("cyclomatic-complexity-threshold", cyclomatic_complexity_threshold, 25 => u64),
|
||||||
/// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks
|
/// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks
|
||||||
("doc-valid-idents", doc_valid_idents, ["MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "GPLv2", "GPLv3", "GitHub", "IPv4", "IPv6", "JavaScript", "NaN", "OAuth", "OpenGL", "TrueType", "iOS", "macOS"] => Vec<String>),
|
("doc-valid-idents", doc_valid_idents, [
|
||||||
|
"MiB", "GiB", "TiB", "PiB", "EiB",
|
||||||
|
"DirectX",
|
||||||
|
"GPLv2", "GPLv3",
|
||||||
|
"GitHub",
|
||||||
|
"IPv4", "IPv6",
|
||||||
|
"JavaScript",
|
||||||
|
"NaN",
|
||||||
|
"OAuth",
|
||||||
|
"OpenGL",
|
||||||
|
"TrueType",
|
||||||
|
"iOS", "macOS",
|
||||||
|
] => Vec<String>),
|
||||||
/// Lint: TOO_MANY_ARGUMENTS. The maximum number of argument a function or method can have
|
/// Lint: TOO_MANY_ARGUMENTS. The maximum number of argument a function or method can have
|
||||||
("too-many-arguments-threshold", too_many_arguments_threshold, 7 => u64),
|
("too-many-arguments-threshold", too_many_arguments_threshold, 7 => u64),
|
||||||
/// Lint: TYPE_COMPLEXITY. The maximum complexity a type can have
|
/// Lint: TYPE_COMPLEXITY. The maximum complexity a type can have
|
||||||
|
|
|
@ -9,7 +9,7 @@ fn main() {
|
||||||
let u: u32 = 42;
|
let u: u32 = 42;
|
||||||
|
|
||||||
u <= 0;
|
u <= 0;
|
||||||
//~^ ERROR this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
//~^ ERROR this comparison involving the minimum or maximum element for this type contains a
|
||||||
//~| HELP using u == 0 instead
|
//~| HELP using u == 0 instead
|
||||||
u <= Z;
|
u <= Z;
|
||||||
//~^ ERROR this comparison involving
|
//~^ ERROR this comparison involving
|
||||||
|
@ -41,10 +41,10 @@ fn main() {
|
||||||
//~| HELP because 1-1 is the minimum value for this type, this comparison is always false
|
//~| HELP because 1-1 is the minimum value for this type, this comparison is always false
|
||||||
u >= !0;
|
u >= !0;
|
||||||
//~^ ERROR this comparison involving
|
//~^ ERROR this comparison involving
|
||||||
//~| HELP because !0 is the maximum value for this type, the case where the two sides are not equal never occurs, consider using u == !0 instead
|
//~| HELP consider using u == !0 instead
|
||||||
u <= 12 - 2*6;
|
u <= 12 - 2*6;
|
||||||
//~^ ERROR this comparison involving
|
//~^ ERROR this comparison involving
|
||||||
//~| HELP because 12 - 2*6 is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == 12 - 2*6 instead
|
//~| HELP consider using u == 12 - 2*6 instead
|
||||||
|
|
||||||
let i: i8 = 0;
|
let i: i8 = 0;
|
||||||
i < -127 - 1;
|
i < -127 - 1;
|
||||||
|
|
|
@ -27,7 +27,7 @@ fn macro_if() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn condition_has_block() -> i32 {
|
fn condition_has_block() -> i32 {
|
||||||
if { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let'
|
if { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks;
|
||||||
let x = 3;
|
let x = 3;
|
||||||
x == 3
|
x == 3
|
||||||
} {
|
} {
|
||||||
|
@ -55,12 +55,12 @@ fn pred_test() {
|
||||||
// this is a sneaky case, where the block isn't directly in the condition, but is actually
|
// this is a sneaky case, where the block isn't directly in the condition, but is actually
|
||||||
// inside a closure that the condition is using. same principle applies. add some extra
|
// inside a closure that the condition is using. same principle applies. add some extra
|
||||||
// expressions to make sure linter isn't confused by them.
|
// expressions to make sure linter isn't confused by them.
|
||||||
if v == 3 && sky == "blue" && predicate(|x| { let target = 3; x == target }, v) { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let'
|
if v == 3 && sky == "blue" && predicate(|x| { let target = 3; x == target }, v) {
|
||||||
|
//~^ERROR in an 'if' condition, avoid complex blocks or closures with blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
if predicate(|x| { let target = 3; x == target }, v) { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let'
|
if predicate(|x| { let target = 3; x == target }, v) {
|
||||||
|
//~^ERROR in an 'if' condition, avoid complex blocks or closures with blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue