Skip to content

Commit d7f1a1e

Browse files
committed
Change note_span argument for span_lint_and_note.
1 parent cf4e353 commit d7f1a1e

13 files changed

+47
-35
lines changed

clippy_lints/src/copies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) {
183183
IF_SAME_THEN_ELSE,
184184
j.span,
185185
"this `if` has identical blocks",
186-
i.span,
186+
Some(i.span),
187187
"same as this",
188188
);
189189
}
@@ -206,7 +206,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
206206
IFS_SAME_COND,
207207
j.span,
208208
"this `if` has the same condition as a previous `if`",
209-
i.span,
209+
Some(i.span),
210210
"same as this",
211211
);
212212
}
@@ -234,7 +234,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
234234
SAME_FUNCTIONS_IN_IF_CONDITION,
235235
j.span,
236236
"this `if` has the same function call as a previous `if`",
237-
i.span,
237+
Some(i.span),
238238
"same as this",
239239
);
240240
}

clippy_lints/src/copy_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
4646
COPY_ITERATOR,
4747
item.span,
4848
"you are implementing `Iterator` on a `Copy` type",
49-
item.span,
49+
None,
5050
"consider implementing `IntoIterator` instead",
5151
);
5252
}

clippy_lints/src/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait
168168
EXPL_IMPL_CLONE_ON_COPY,
169169
item.span,
170170
"you are implementing `Clone` explicitly on a `Copy` type",
171-
item.span,
171+
Some(item.span),
172172
"consider deriving `Clone` or removing `Copy`",
173173
);
174174
}

clippy_lints/src/drop_forget_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
135135
lint,
136136
expr.span,
137137
&msg,
138-
arg.span,
138+
Some(arg.span),
139139
&format!("argument has type `{}`", arg_ty));
140140
} else if is_copy(cx, arg_ty) {
141141
if match_def_path(cx, def_id, &paths::DROP) {
@@ -151,7 +151,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
151151
lint,
152152
expr.span,
153153
&msg,
154-
arg.span,
154+
Some(arg.span),
155155
&format!("argument has type {}", arg_ty));
156156
}
157157
}

clippy_lints/src/eval_order_dependence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
310310
EVAL_ORDER_DEPENDENCE,
311311
expr.span,
312312
"unsequenced read of a variable",
313-
self.write_expr.span,
313+
Some(self.write_expr.span),
314314
"whether read occurs before this write depends on evaluation order"
315315
);
316316
}

clippy_lints/src/formatting.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) {
149149
really are doing `.. = ({op} ..)`",
150150
op = op
151151
),
152-
eqop_span,
152+
None,
153153
&format!("to remove this lint, use either `{op}=` or `= {op}`", op = op),
154154
);
155155
}
@@ -227,7 +227,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
227227
SUSPICIOUS_ELSE_FORMATTING,
228228
else_span,
229229
&format!("this is an `else {}` but the formatting might hide it", else_desc),
230-
else_span,
230+
None,
231231
&format!(
232232
"to remove this lint, remove the `else` or remove the new line between \
233233
`else` and `{}`",
@@ -266,7 +266,7 @@ fn check_array(cx: &EarlyContext<'_>, expr: &Expr) {
266266
POSSIBLE_MISSING_COMMA,
267267
lint_span,
268268
"possibly missing a comma here",
269-
lint_span,
269+
None,
270270
"to remove this lint, add a comma or write the expr in a single line",
271271
);
272272
}
@@ -297,7 +297,7 @@ fn check_missing_else(cx: &EarlyContext<'_>, first: &Expr, second: &Expr) {
297297
SUSPICIOUS_ELSE_FORMATTING,
298298
else_span,
299299
&format!("this looks like {} but the `else` is missing", looks_like),
300-
else_span,
300+
None,
301301
&format!(
302302
"to remove this lint, add the missing `else` or add a new line before {}",
303303
next_thing,

clippy_lints/src/matches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<'
637637
MATCH_OVERLAPPING_ARM,
638638
start.span,
639639
"some ranges overlap",
640-
end.span,
640+
Some(end.span),
641641
"overlaps with this",
642642
);
643643
}
@@ -675,7 +675,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>])
675675
MATCH_WILD_ERR_ARM,
676676
arm.pat.span,
677677
&format!("`Err({})` matches all errors", &ident_bind_name),
678-
arm.pat.span,
678+
None,
679679
"match each error separately or use the error output",
680680
);
681681
}

clippy_lints/src/methods/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
25772577
},
25782578
expr.span,
25792579
msg,
2580-
expr.span,
2580+
None,
25812581
&format!(
25822582
"replace `map({0}).unwrap_or_else({1})` with `map_or_else({1}, {0})`",
25832583
map_snippet, unwrap_snippet,
@@ -2757,7 +2757,7 @@ fn lint_filter_next<'a, 'tcx>(
27572757
FILTER_NEXT,
27582758
expr.span,
27592759
msg,
2760-
expr.span,
2760+
None,
27612761
&format!("replace `filter({0}).next()` with `find({0})`", filter_snippet),
27622762
);
27632763
} else {
@@ -2816,7 +2816,7 @@ fn lint_filter_map_next<'a, 'tcx>(
28162816
FILTER_MAP_NEXT,
28172817
expr.span,
28182818
msg,
2819-
expr.span,
2819+
None,
28202820
&format!("replace `filter_map({0}).next()` with `find_map({0})`", filter_snippet),
28212821
);
28222822
} else {

clippy_lints/src/utils/diagnostics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ pub fn span_lint_and_note<'a, T: LintContext>(
108108
lint: &'static Lint,
109109
span: Span,
110110
msg: &str,
111-
note_span: Span,
111+
note_span: Option<Span>,
112112
note: &str,
113113
) {
114-
cx.struct_span_lint(lint, span, |diag| {
115-
let mut diag = diag.build(msg);
116-
if note_span == span {
117-
diag.note(note);
114+
cx.struct_span_lint(lint, span, |ldb| {
115+
let mut db = ldb.build(msg);
116+
if let Some(note_span) = note_span {
117+
db.span_note(note_span, note);
118118
} else {
119-
diag.span_note(note_span, note);
119+
db.note(note);
120120
}
121121
docs_link(&mut diag, lint);
122122
diag.emit();

clippy_lints/src/utils/internal_lints.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ declare_clippy_lint! {
198198
/// );
199199
/// span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg);
200200
/// span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg);
201-
/// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
202-
/// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
201+
/// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg);
202+
/// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg);
203203
/// ```
204204
pub COLLAPSIBLE_SPAN_LINT_CALLS,
205205
internal,
@@ -486,15 +486,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CollapsibleCalls {
486486
},
487487
"span_note" if sle.eq_expr(&and_then_args[2], &span_call_args[1]) => {
488488
let note_snippet = snippet(cx, span_call_args[2].span, r#""...""#);
489-
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow());
489+
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), true);
490490
},
491491
"help" => {
492492
let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
493493
suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), false);
494494
}
495495
"note" => {
496496
let note_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
497-
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow());
497+
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), false);
498498
}
499499
_ => (),
500500
}
@@ -606,7 +606,19 @@ fn suggest_help(
606606
);
607607
}
608608

609-
fn suggest_note(cx: &LateContext<'_, '_>, expr: &Expr<'_>, and_then_snippets: &AndThenSnippets<'_>, note: &str) {
609+
fn suggest_note(
610+
cx: &LateContext<'_, '_>,
611+
expr: &Expr<'_>,
612+
and_then_snippets: &AndThenSnippets<'_>,
613+
note: &str,
614+
with_span: bool,
615+
) {
616+
let note_span = if with_span {
617+
format!("Some({})", and_then_snippets.span)
618+
} else {
619+
"None".to_string()
620+
};
621+
610622
span_lint_and_sugg(
611623
cx,
612624
COLLAPSIBLE_SPAN_LINT_CALLS,
@@ -619,7 +631,7 @@ fn suggest_note(cx: &LateContext<'_, '_>, expr: &Expr<'_>, and_then_snippets: &A
619631
and_then_snippets.lint,
620632
and_then_snippets.span,
621633
and_then_snippets.msg,
622-
and_then_snippets.span,
634+
note_span,
623635
note
624636
),
625637
Applicability::MachineApplicable,

tests/ui/collapsible_span_lint_calls.fixed

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn span_lint_and_note<'a, T: LintContext>(
3838
lint: &'static Lint,
3939
span: Span,
4040
msg: &str,
41-
note_span: Span,
41+
note_span: Option<Span>,
4242
note: &str,
4343
) {
4444
}
@@ -75,8 +75,8 @@ impl EarlyLintPass for Pass {
7575
span_lint_and_sugg(cx, TEST_LINT, expr.span, lint_msg, help_msg, sugg.to_string(), Applicability::MachineApplicable);
7676
span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg);
7777
span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg);
78-
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
79-
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
78+
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg);
79+
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg);
8080

8181
// This expr shouldn't trigger this lint.
8282
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {

tests/ui/collapsible_span_lint_calls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn span_lint_and_note<'a, T: LintContext>(
3838
lint: &'static Lint,
3939
span: Span,
4040
msg: &str,
41-
note_span: Span,
41+
note_span: Option<Span>,
4242
note: &str,
4343
) {
4444
}

tests/ui/collapsible_span_lint_calls.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ error: this call is collspible
3535
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
3636
LL | | db.span_note(expr.span, note_msg);
3737
LL | | });
38-
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg)`
38+
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg)`
3939

4040
error: this call is collspible
4141
--> $DIR/collapsible_span_lint_calls.rs:87:9
4242
|
4343
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
4444
LL | | db.note(note_msg);
4545
LL | | });
46-
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg)`
46+
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg)`
4747

4848
error: aborting due to 5 previous errors
4949

0 commit comments

Comments
 (0)