Change note_span argument for span_lint_and_note.
This commit is contained in:
parent
cf4e35339b
commit
d7f1a1ed2b
13 changed files with 47 additions and 35 deletions
|
@ -183,7 +183,7 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) {
|
|||
IF_SAME_THEN_ELSE,
|
||||
j.span,
|
||||
"this `if` has identical blocks",
|
||||
i.span,
|
||||
Some(i.span),
|
||||
"same as this",
|
||||
);
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
|
|||
IFS_SAME_COND,
|
||||
j.span,
|
||||
"this `if` has the same condition as a previous `if`",
|
||||
i.span,
|
||||
Some(i.span),
|
||||
"same as this",
|
||||
);
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
|
|||
SAME_FUNCTIONS_IN_IF_CONDITION,
|
||||
j.span,
|
||||
"this `if` has the same function call as a previous `if`",
|
||||
i.span,
|
||||
Some(i.span),
|
||||
"same as this",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
|
|||
COPY_ITERATOR,
|
||||
item.span,
|
||||
"you are implementing `Iterator` on a `Copy` type",
|
||||
item.span,
|
||||
None,
|
||||
"consider implementing `IntoIterator` instead",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait
|
|||
EXPL_IMPL_CLONE_ON_COPY,
|
||||
item.span,
|
||||
"you are implementing `Clone` explicitly on a `Copy` type",
|
||||
item.span,
|
||||
Some(item.span),
|
||||
"consider deriving `Clone` or removing `Copy`",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
|
|||
lint,
|
||||
expr.span,
|
||||
&msg,
|
||||
arg.span,
|
||||
Some(arg.span),
|
||||
&format!("argument has type `{}`", arg_ty));
|
||||
} else if is_copy(cx, arg_ty) {
|
||||
if match_def_path(cx, def_id, &paths::DROP) {
|
||||
|
@ -151,7 +151,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
|
|||
lint,
|
||||
expr.span,
|
||||
&msg,
|
||||
arg.span,
|
||||
Some(arg.span),
|
||||
&format!("argument has type {}", arg_ty));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -310,7 +310,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
|
|||
EVAL_ORDER_DEPENDENCE,
|
||||
expr.span,
|
||||
"unsequenced read of a variable",
|
||||
self.write_expr.span,
|
||||
Some(self.write_expr.span),
|
||||
"whether read occurs before this write depends on evaluation order"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) {
|
|||
really are doing `.. = ({op} ..)`",
|
||||
op = op
|
||||
),
|
||||
eqop_span,
|
||||
None,
|
||||
&format!("to remove this lint, use either `{op}=` or `= {op}`", op = op),
|
||||
);
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
|
|||
SUSPICIOUS_ELSE_FORMATTING,
|
||||
else_span,
|
||||
&format!("this is an `else {}` but the formatting might hide it", else_desc),
|
||||
else_span,
|
||||
None,
|
||||
&format!(
|
||||
"to remove this lint, remove the `else` or remove the new line between \
|
||||
`else` and `{}`",
|
||||
|
@ -266,7 +266,7 @@ fn check_array(cx: &EarlyContext<'_>, expr: &Expr) {
|
|||
POSSIBLE_MISSING_COMMA,
|
||||
lint_span,
|
||||
"possibly missing a comma here",
|
||||
lint_span,
|
||||
None,
|
||||
"to remove this lint, add a comma or write the expr in a single line",
|
||||
);
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ fn check_missing_else(cx: &EarlyContext<'_>, first: &Expr, second: &Expr) {
|
|||
SUSPICIOUS_ELSE_FORMATTING,
|
||||
else_span,
|
||||
&format!("this looks like {} but the `else` is missing", looks_like),
|
||||
else_span,
|
||||
None,
|
||||
&format!(
|
||||
"to remove this lint, add the missing `else` or add a new line before {}",
|
||||
next_thing,
|
||||
|
|
|
@ -637,7 +637,7 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<'
|
|||
MATCH_OVERLAPPING_ARM,
|
||||
start.span,
|
||||
"some ranges overlap",
|
||||
end.span,
|
||||
Some(end.span),
|
||||
"overlaps with this",
|
||||
);
|
||||
}
|
||||
|
@ -675,7 +675,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>])
|
|||
MATCH_WILD_ERR_ARM,
|
||||
arm.pat.span,
|
||||
&format!("`Err({})` matches all errors", &ident_bind_name),
|
||||
arm.pat.span,
|
||||
None,
|
||||
"match each error separately or use the error output",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2577,7 +2577,7 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
|
|||
},
|
||||
expr.span,
|
||||
msg,
|
||||
expr.span,
|
||||
None,
|
||||
&format!(
|
||||
"replace `map({0}).unwrap_or_else({1})` with `map_or_else({1}, {0})`",
|
||||
map_snippet, unwrap_snippet,
|
||||
|
@ -2757,7 +2757,7 @@ fn lint_filter_next<'a, 'tcx>(
|
|||
FILTER_NEXT,
|
||||
expr.span,
|
||||
msg,
|
||||
expr.span,
|
||||
None,
|
||||
&format!("replace `filter({0}).next()` with `find({0})`", filter_snippet),
|
||||
);
|
||||
} else {
|
||||
|
@ -2816,7 +2816,7 @@ fn lint_filter_map_next<'a, 'tcx>(
|
|||
FILTER_MAP_NEXT,
|
||||
expr.span,
|
||||
msg,
|
||||
expr.span,
|
||||
None,
|
||||
&format!("replace `filter_map({0}).next()` with `find_map({0})`", filter_snippet),
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -108,15 +108,15 @@ pub fn span_lint_and_note<'a, T: LintContext>(
|
|||
lint: &'static Lint,
|
||||
span: Span,
|
||||
msg: &str,
|
||||
note_span: Span,
|
||||
note_span: Option<Span>,
|
||||
note: &str,
|
||||
) {
|
||||
cx.struct_span_lint(lint, span, |diag| {
|
||||
let mut diag = diag.build(msg);
|
||||
if note_span == span {
|
||||
diag.note(note);
|
||||
cx.struct_span_lint(lint, span, |ldb| {
|
||||
let mut db = ldb.build(msg);
|
||||
if let Some(note_span) = note_span {
|
||||
db.span_note(note_span, note);
|
||||
} else {
|
||||
diag.span_note(note_span, note);
|
||||
db.note(note);
|
||||
}
|
||||
docs_link(&mut diag, lint);
|
||||
diag.emit();
|
||||
|
|
|
@ -198,8 +198,8 @@ declare_clippy_lint! {
|
|||
/// );
|
||||
/// span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg);
|
||||
/// span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg);
|
||||
/// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
|
||||
/// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
|
||||
/// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg);
|
||||
/// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg);
|
||||
/// ```
|
||||
pub COLLAPSIBLE_SPAN_LINT_CALLS,
|
||||
internal,
|
||||
|
@ -486,7 +486,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CollapsibleCalls {
|
|||
},
|
||||
"span_note" if sle.eq_expr(&and_then_args[2], &span_call_args[1]) => {
|
||||
let note_snippet = snippet(cx, span_call_args[2].span, r#""...""#);
|
||||
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow());
|
||||
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), true);
|
||||
},
|
||||
"help" => {
|
||||
let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
|
||||
|
@ -494,7 +494,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CollapsibleCalls {
|
|||
}
|
||||
"note" => {
|
||||
let note_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
|
||||
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow());
|
||||
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), false);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
@ -606,7 +606,19 @@ fn suggest_help(
|
|||
);
|
||||
}
|
||||
|
||||
fn suggest_note(cx: &LateContext<'_, '_>, expr: &Expr<'_>, and_then_snippets: &AndThenSnippets<'_>, note: &str) {
|
||||
fn suggest_note(
|
||||
cx: &LateContext<'_, '_>,
|
||||
expr: &Expr<'_>,
|
||||
and_then_snippets: &AndThenSnippets<'_>,
|
||||
note: &str,
|
||||
with_span: bool,
|
||||
) {
|
||||
let note_span = if with_span {
|
||||
format!("Some({})", and_then_snippets.span)
|
||||
} else {
|
||||
"None".to_string()
|
||||
};
|
||||
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
COLLAPSIBLE_SPAN_LINT_CALLS,
|
||||
|
@ -619,7 +631,7 @@ fn suggest_note(cx: &LateContext<'_, '_>, expr: &Expr<'_>, and_then_snippets: &A
|
|||
and_then_snippets.lint,
|
||||
and_then_snippets.span,
|
||||
and_then_snippets.msg,
|
||||
and_then_snippets.span,
|
||||
note_span,
|
||||
note
|
||||
),
|
||||
Applicability::MachineApplicable,
|
||||
|
|
|
@ -38,7 +38,7 @@ fn span_lint_and_note<'a, T: LintContext>(
|
|||
lint: &'static Lint,
|
||||
span: Span,
|
||||
msg: &str,
|
||||
note_span: Span,
|
||||
note_span: Option<Span>,
|
||||
note: &str,
|
||||
) {
|
||||
}
|
||||
|
@ -75,8 +75,8 @@ impl EarlyLintPass for Pass {
|
|||
span_lint_and_sugg(cx, TEST_LINT, expr.span, lint_msg, help_msg, sugg.to_string(), Applicability::MachineApplicable);
|
||||
span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg);
|
||||
span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg);
|
||||
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
|
||||
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
|
||||
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg);
|
||||
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg);
|
||||
|
||||
// This expr shouldn't trigger this lint.
|
||||
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
|
||||
|
|
|
@ -38,7 +38,7 @@ fn span_lint_and_note<'a, T: LintContext>(
|
|||
lint: &'static Lint,
|
||||
span: Span,
|
||||
msg: &str,
|
||||
note_span: Span,
|
||||
note_span: Option<Span>,
|
||||
note: &str,
|
||||
) {
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ error: this call is collspible
|
|||
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
|
||||
LL | | db.span_note(expr.span, note_msg);
|
||||
LL | | });
|
||||
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg)`
|
||||
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg)`
|
||||
|
||||
error: this call is collspible
|
||||
--> $DIR/collapsible_span_lint_calls.rs:87:9
|
||||
|
@ -43,7 +43,7 @@ error: this call is collspible
|
|||
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
|
||||
LL | | db.note(note_msg);
|
||||
LL | | });
|
||||
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg)`
|
||||
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg)`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue