Skip to content

Commit 3157b96

Browse files
committed
Provide fallback code snippets, if the snippet is not available
1 parent 0e064d5 commit 3157b96

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

clippy_lints/src/operators/const_comparisons.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ pub(super) fn check<'tcx>(
8282

8383
then {
8484
if left_cmp_op.direction() == right_cmp_op.direction() {
85-
let lhs_str = snippet(cx, left_cond.span, "");
86-
let rhs_str = snippet(cx, right_cond.span, "");
85+
let lhs_str = snippet(cx, left_cond.span, "<lhs>");
86+
let rhs_str = snippet(cx, right_cond.span, "<rhs>");
8787
// We already know that either side of `&&` has no effect,
8888
// but emit a different error message depending on which side it is
8989
if left_side_is_useless(left_cmp_op, ordering) {
@@ -109,9 +109,9 @@ pub(super) fn check<'tcx>(
109109
// because code triggering this lint probably not behaving correctly in the first place
110110
}
111111
else if !comparison_is_possible(left_cmp_op.direction(), ordering) {
112-
let expr_str = snippet(cx, left_expr.span, "");
113-
let lhs_str = snippet(cx, left_const_expr.span, "");
114-
let rhs_str = snippet(cx, right_const_expr.span, "");
112+
let expr_str = snippet(cx, left_expr.span, "..");
113+
let lhs_str = snippet(cx, left_const_expr.span, "<lhs>");
114+
let rhs_str = snippet(cx, right_const_expr.span, "<rhs>");
115115
let note = match ordering {
116116
Ordering::Less => format!("since `{lhs_str}` < `{rhs_str}`, the expression evaluates to false for any value of `{expr_str}`"),
117117
Ordering::Equal => format!("`{expr_str}` cannot simultaneously be greater than and less than `{lhs_str}`"),

0 commit comments

Comments
 (0)