Skip to content

Commit cf4e353

Browse files
committed
Add an Option<Span> argument to span_lint_and_help.
1 parent d03d3bd commit cf4e353

39 files changed

+138
-37
lines changed

clippy_lints/src/as_conversions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl EarlyLintPass for AsConversions {
5050
AS_CONVERSIONS,
5151
expr.span,
5252
"using a potentially dangerous silent `as` conversion",
53+
None,
5354
"consider using a safe wrapper for this conversion",
5455
);
5556
}

clippy_lints/src/assertions_on_constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
4141
} else {
4242
"`assert!(true)` will be optimized out by the compiler"
4343
},
44+
None,
4445
"remove it",
4546
);
4647
};
@@ -50,6 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
5051
ASSERTIONS_ON_CONSTANTS,
5152
e.span,
5253
"`assert!(false)` should probably be replaced",
54+
None,
5355
"use `panic!()` or `unreachable!()`",
5456
);
5557
};
@@ -59,6 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
5961
ASSERTIONS_ON_CONSTANTS,
6062
e.span,
6163
&format!("`assert!(false, {})` should probably be replaced", panic_message),
64+
None,
6265
&format!("use `panic!({})` or `unreachable!({})`", panic_message, panic_message),
6366
)
6467
};

clippy_lints/src/atomic_ordering.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
8585
INVALID_ATOMIC_ORDERING,
8686
ordering_arg.span,
8787
"atomic loads cannot have `Release` and `AcqRel` ordering",
88+
None,
8889
"consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`"
8990
);
9091
} else if method == "store" &&
@@ -94,6 +95,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
9495
INVALID_ATOMIC_ORDERING,
9596
ordering_arg.span,
9697
"atomic stores cannot have `Acquire` and `AcqRel` ordering",
98+
None,
9799
"consider using ordering modes `Release`, `SeqCst` or `Relaxed`"
98100
);
99101
}
@@ -118,6 +120,7 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
118120
INVALID_ATOMIC_ORDERING,
119121
args[0].span,
120122
"memory fences cannot have `Relaxed` ordering",
123+
None,
121124
"consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`"
122125
);
123126
}

clippy_lints/src/cognitive_complexity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl CognitiveComplexity {
105105
rust_cc,
106106
self.limit.limit()
107107
),
108+
None,
108109
"you could split it up into multiple smaller functions",
109110
);
110111
}

clippy_lints/src/comparison_chain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain {
104104
COMPARISON_CHAIN,
105105
expr.span,
106106
"`if` chain can be rewritten with `match`",
107+
None,
107108
"Consider rewriting the `if` chain to use `cmp` and `match`.",
108109
)
109110
}

clippy_lints/src/dbg_macro.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl EarlyLintPass for DbgMacro {
4848
DBG_MACRO,
4949
mac.span(),
5050
"`dbg!` macro is intended as a debugging tool",
51+
None,
5152
"ensure to avoid having uses of it in version control",
5253
);
5354
}

clippy_lints/src/else_if_without_else.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl EarlyLintPass for ElseIfWithoutElse {
6161
ELSE_IF_WITHOUT_ELSE,
6262
els.span,
6363
"`if` expression with an `else if`, but without a final `else`",
64+
None,
6465
"add an `else` block here",
6566
);
6667
}

clippy_lints/src/empty_enum.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
4545
let ty = cx.tcx.type_of(did);
4646
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
4747
if adt.variants.is_empty() {
48-
span_lint_and_then(
48+
span_lint_and_help(
4949
cx,
5050
EMPTY_ENUM,
5151
item.span,
5252
"enum with no variants",
53-
"consider using the uninhabited type `!` (never type) or a wrapper around it \
54-
to introduce a type which can't be instantiated",
53+
Some(item.span),
54+
"consider using the uninhabited type `!` (never type) or a wrapper \
55+
around it to introduce a type which can't be instantiated",
5556
);
5657
}
5758
}

clippy_lints/src/enum_variants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ fn check_variant(
206206
lint,
207207
span,
208208
&format!("All variants have the same {}fix: `{}`", what, value),
209+
None,
209210
&format!(
210211
"remove the {}fixes and use full paths to \
211212
the variants instead of glob imports",

clippy_lints/src/excessive_bools.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl ExcessiveBools {
114114
FN_PARAMS_EXCESSIVE_BOOLS,
115115
span,
116116
&format!("more than {} bools in function parameters", self.max_fn_params_bools),
117+
None,
117118
"consider refactoring bools into two-variant enums",
118119
);
119120
}
@@ -153,6 +154,7 @@ impl EarlyLintPass for ExcessiveBools {
153154
STRUCT_EXCESSIVE_BOOLS,
154155
item.span,
155156
&format!("more than {} bools in a struct", self.max_struct_bools),
157+
None,
156158
"consider using a state machine or refactoring bools into two-variant enums",
157159
);
158160
}

clippy_lints/src/formatting.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ fn check_unop(cx: &EarlyContext<'_>, expr: &Expr) {
188188
binop = binop_str,
189189
unop = unop_str
190190
),
191+
None,
191192
&format!(
192193
"put a space between `{binop}` and `{unop}` and remove the space after `{unop}`",
193194
binop = binop_str,

clippy_lints/src/functions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ fn check_needless_must_use(
431431
DOUBLE_MUST_USE,
432432
fn_header_span,
433433
"this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]`",
434+
None,
434435
"either add some descriptive text or remove the attribute",
435436
);
436437
}

clippy_lints/src/if_not_else.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl EarlyLintPass for IfNotElse {
6161
IF_NOT_ELSE,
6262
item.span,
6363
"Unnecessary boolean `not` operation",
64+
None,
6465
"remove the `!` and swap the blocks of the `if`/`else`",
6566
);
6667
},
@@ -70,6 +71,7 @@ impl EarlyLintPass for IfNotElse {
7071
IF_NOT_ELSE,
7172
item.span,
7273
"Unnecessary `!=` operation",
74+
None,
7375
"change to `==` and swap the blocks of the `if`/`else`",
7476
);
7577
},

clippy_lints/src/indexing_slicing.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
138138
(None, None) => return, // [..] is ok.
139139
};
140140

141-
span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
141+
span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", None, help_msg);
142142
} else {
143143
// Catchall non-range index, i.e., [n] or [n << m]
144144
if let ty::Array(..) = ty.kind {
@@ -154,6 +154,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
154154
INDEXING_SLICING,
155155
expr.span,
156156
"indexing may panic.",
157+
None,
157158
"Consider using `.get(n)` or `.get_mut(n)` instead",
158159
);
159160
}

clippy_lints/src/inherent_to_string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ fn show_lint(cx: &LateContext<'_, '_>, item: &ImplItem<'_>) {
137137
"type `{}` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`",
138138
self_type.to_string()
139139
),
140+
None,
140141
&format!("remove the inherent method from type `{}`", self_type.to_string())
141142
);
142143
} else {
@@ -148,6 +149,7 @@ fn show_lint(cx: &LateContext<'_, '_>, item: &ImplItem<'_>) {
148149
"implementation of inherent method `to_string(&self) -> String` for type `{}`",
149150
self_type.to_string()
150151
),
152+
None,
151153
&format!("implement trait `Display` for type `{}` instead", self_type.to_string()),
152154
);
153155
}

clippy_lints/src/integer_division.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision {
3535
INTEGER_DIVISION,
3636
expr.span,
3737
"integer division",
38+
None,
3839
"division of integers may cause loss of precision. consider using floats.",
3940
);
4041
}

clippy_lints/src/large_stack_arrays.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays {
5757
"allocating a local array larger than {} bytes",
5858
self.maximum_allowed_size
5959
),
60+
None,
6061
&format!(
6162
"consider allocating on the heap with `vec!{}.into_boxed_slice()`",
6263
snippet(cx, expr.span, "[...]")

clippy_lints/src/let_underscore.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
9090
LET_UNDERSCORE_LOCK,
9191
local.span,
9292
"non-binding let on a synchronization lock",
93+
None,
9394
"consider using an underscore-prefixed named \
9495
binding or dropping explicitly with `std::mem::drop`"
9596
)
@@ -99,6 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
99100
LET_UNDERSCORE_MUST_USE,
100101
local.span,
101102
"non-binding let on an expression with `#[must_use]` type",
103+
None,
102104
"consider explicitly using expression value"
103105
)
104106
} else if is_must_use_func_call(cx, init) {
@@ -107,6 +109,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
107109
LET_UNDERSCORE_MUST_USE,
108110
local.span,
109111
"non-binding let on a result of a `#[must_use]` function",
112+
None,
110113
"consider explicitly using function result"
111114
)
112115
}

clippy_lints/src/loops.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) {
14021402
`if let` statement.",
14031403
snippet(cx, arg.span, "_")
14041404
),
1405+
None,
14051406
&format!(
14061407
"consider replacing `for {0} in {1}` with `if let Some({0}) = {1}`",
14071408
snippet(cx, pat.span, "_"),
@@ -1418,6 +1419,7 @@ fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) {
14181419
`if let` statement.",
14191420
snippet(cx, arg.span, "_")
14201421
),
1422+
None,
14211423
&format!(
14221424
"consider replacing `for {0} in {1}` with `if let Ok({0}) = {1}`",
14231425
snippet(cx, pat.span, "_"),

clippy_lints/src/main_recursion.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl LateLintPass<'_, '_> for MainRecursion {
5353
MAIN_RECURSION,
5454
func.span,
5555
&format!("recursing into entrypoint `{}`", snippet(cx, func.span, "main")),
56+
None,
5657
"consider using another function for this recursion"
5758
)
5859
}

clippy_lints/src/matches.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
441441
REST_PAT_IN_FULLY_BOUND_STRUCTS,
442442
pat.span,
443443
"unnecessary use of `..` pattern in struct binding. All fields were already bound",
444+
None,
444445
"consider removing `..` from this binding",
445446
);
446447
}
@@ -887,6 +888,7 @@ fn check_wild_in_or_pats(cx: &LateContext<'_, '_>, arms: &[Arm<'_>]) {
887888
WILDCARD_IN_OR_PATTERNS,
888889
arm.pat.span,
889890
"wildcard pattern covers any other pattern as it will match anyway.",
891+
None,
890892
"Consider handling `_` separately.",
891893
);
892894
}

clippy_lints/src/mem_replace.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, expr_span
148148
MEM_REPLACE_WITH_UNINIT,
149149
expr_span,
150150
"replacing with `mem::uninitialized()`",
151+
None,
151152
"consider using the `take_mut` crate instead",
152153
);
153154
} else if cx.tcx.is_diagnostic_item(sym::mem_zeroed, repl_def_id) &&
@@ -157,6 +158,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, expr_span
157158
MEM_REPLACE_WITH_UNINIT,
158159
expr_span,
159160
"replacing with `mem::zeroed()`",
161+
None,
160162
"consider using a default value or the `take_mut` crate instead",
161163
);
162164
}

0 commit comments

Comments
 (0)