Add an Option<Span> argument to span_lint_and_help.

This commit is contained in:
xiongmao86 2020-04-18 18:28:29 +08:00
parent d03d3bd95b
commit cf4e35339b
39 changed files with 138 additions and 37 deletions

View file

@ -2255,6 +2255,7 @@ fn lint_iter_nth<'a, 'tcx>(
ITER_NTH,
expr.span,
&format!("called `.iter{0}().nth()` on a {1}", mut_str, caller_type),
None,
&format!("calling `.get{}()` is both faster and more readable", mut_str),
);
}
@ -2364,6 +2365,7 @@ fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) {
ITER_SKIP_NEXT,
expr.span,
"called `skip(x).next()` on an iterator",
None,
"this is more succinctly expressed by calling `nth(x)`",
);
}
@ -2431,6 +2433,7 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
lint,
expr.span,
&format!("used `unwrap()` on `{}` value", kind,),
None,
&format!(
"if you don't want to handle the `{}` case gracefully, consider \
using `expect()` to provide a better panic message",
@ -2458,6 +2461,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi
lint,
expr.span,
&format!("used `expect()` on `{}` value", kind,),
None,
&format!("if this value is an `{}`, it will panic", none_value,),
);
}
@ -2478,6 +2482,7 @@ fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir
OK_EXPECT,
expr.span,
"called `ok().expect()` on a `Result` value",
None,
"you can call `expect()` directly on the `Result`",
);
}
@ -2774,6 +2779,7 @@ fn lint_skip_while_next<'a, 'tcx>(
SKIP_WHILE_NEXT,
expr.span,
"called `skip_while(p).next()` on an `Iterator`",
None,
"this is more succinctly expressed by calling `.find(!p)` instead",
);
}
@ -2790,7 +2796,7 @@ fn lint_filter_map<'a, 'tcx>(
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter(p).map(q)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.filter_map(..)` instead";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
}
}
@ -2830,7 +2836,7 @@ fn lint_find_map<'a, 'tcx>(
if match_trait_method(cx, &map_args[0], &paths::ITERATOR) {
let msg = "called `find(p).map(q)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.find_map(..)` instead";
span_lint_and_help(cx, FIND_MAP, expr.span, msg, hint);
span_lint_and_help(cx, FIND_MAP, expr.span, msg, None, hint);
}
}
@ -2845,7 +2851,7 @@ fn lint_filter_map_map<'a, 'tcx>(
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter_map(p).map(q)` on an `Iterator`";
let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
}
}
@ -2861,7 +2867,7 @@ fn lint_filter_flat_map<'a, 'tcx>(
let msg = "called `filter(p).flat_map(q)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
and filtering by returning `iter::empty()`";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
}
}
@ -2877,7 +2883,7 @@ fn lint_filter_map_flat_map<'a, 'tcx>(
let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
and filtering by returning `iter::empty()`";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint);
}
}
@ -3260,6 +3266,7 @@ fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) {
SUSPICIOUS_MAP,
expr.span,
"this call to `map()` won't have an effect on the call to `count()`",
None,
"make sure you did not confuse `map` with `filter` or `for_each`",
);
}
@ -3640,7 +3647,7 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &
}
let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb);
let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary);
span_lint_and_help(cx, FILETYPE_IS_FILE, span, &lint_msg, &help_msg);
span_lint_and_help(cx, FILETYPE_IS_FILE, span, &lint_msg, None, &help_msg);
}
fn fn_header_equals(expected: hir::FnHeader, actual: hir::FnHeader) -> bool {