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
}

0 commit comments

Comments
 (0)