diff options
| author | bors <bors@rust-lang.org> | 2022-06-09 00:04:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-09 00:04:09 +0000 |
| commit | 919cf5083bde1583e2ad6581e0756e51b75b0d27 (patch) | |
| tree | e8d85a1af2a7397c0158f92fa9ffd00a01de4086 | |
| parent | 50541b90e98d7c9e420f7a60f58da9caf48fd487 (diff) | |
| parent | 6fd2c6de90423ff6096da4005229df3b2110629d (diff) | |
| download | rust-919cf5083bde1583e2ad6581e0756e51b75b0d27.tar.gz rust-919cf5083bde1583e2ad6581e0756e51b75b0d27.zip | |
Auto merge of #8907 - kyoto7250:fix_8898, r=giraffate
fix(lint): check const context close: https://github.com/rust-lang/rust-clippy/issues/8898 This PR fixes a bug in checked_conversions. Thank you in advance. changelog: check const context in checked_conversions.
| -rw-r--r-- | clippy_lints/src/checked_conversions.rs | 3 | ||||
| -rw-r--r-- | tests/ui/checked_conversions.fixed | 5 | ||||
| -rw-r--r-- | tests/ui/checked_conversions.rs | 5 |
3 files changed, 12 insertions, 1 deletions
diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 1010340c712..69988d8a45a 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::{meets_msrv, msrvs, SpanlessEq}; +use clippy_utils::{in_constant, meets_msrv, msrvs, SpanlessEq}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; @@ -61,6 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for CheckedConversions { } let result = if_chain! { + if !in_constant(cx, item.hir_id); if !in_external_macro(cx.sess(), item.span); if let ExprKind::Binary(op, left, right) = &item.kind; diff --git a/tests/ui/checked_conversions.fixed b/tests/ui/checked_conversions.fixed index 0983d393b56..cb7100bc9ef 100644 --- a/tests/ui/checked_conversions.fixed +++ b/tests/ui/checked_conversions.fixed @@ -71,4 +71,9 @@ pub fn i8_to_u8(value: i8) { let _ = value >= 0; } +// Do not lint +pub const fn issue_8898(i: u32) -> bool { + i <= i32::MAX as u32 +} + fn main() {} diff --git a/tests/ui/checked_conversions.rs b/tests/ui/checked_conversions.rs index 7d26ace47fd..ed4e0692388 100644 --- a/tests/ui/checked_conversions.rs +++ b/tests/ui/checked_conversions.rs @@ -71,4 +71,9 @@ pub fn i8_to_u8(value: i8) { let _ = value >= 0; } +// Do not lint +pub const fn issue_8898(i: u32) -> bool { + i <= i32::MAX as u32 +} + fn main() {} |
