Skip to content

Commit 919cf50

Browse files
committed
Auto merge of #8907 - kyoto7250:fix_8898, r=giraffate
fix(lint): check const context close: #8898 This PR fixes a bug in checked_conversions. Thank you in advance. changelog: check const context in checked_conversions.
2 parents 50541b9 + 6fd2c6d commit 919cf50

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

clippy_lints/src/checked_conversions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use clippy_utils::diagnostics::span_lint_and_sugg;
44
use clippy_utils::source::snippet_with_applicability;
5-
use clippy_utils::{meets_msrv, msrvs, SpanlessEq};
5+
use clippy_utils::{in_constant, meets_msrv, msrvs, SpanlessEq};
66
use if_chain::if_chain;
77
use rustc_ast::ast::LitKind;
88
use rustc_errors::Applicability;
@@ -61,6 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
6161
}
6262

6363
let result = if_chain! {
64+
if !in_constant(cx, item.hir_id);
6465
if !in_external_macro(cx.sess(), item.span);
6566
if let ExprKind::Binary(op, left, right) = &item.kind;
6667

tests/ui/checked_conversions.fixed

+5
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ pub fn i8_to_u8(value: i8) {
7171
let _ = value >= 0;
7272
}
7373

74+
// Do not lint
75+
pub const fn issue_8898(i: u32) -> bool {
76+
i <= i32::MAX as u32
77+
}
78+
7479
fn main() {}

tests/ui/checked_conversions.rs

+5
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ pub fn i8_to_u8(value: i8) {
7171
let _ = value >= 0;
7272
}
7373

74+
// Do not lint
75+
pub const fn issue_8898(i: u32) -> bool {
76+
i <= i32::MAX as u32
77+
}
78+
7479
fn main() {}

0 commit comments

Comments
 (0)