Skip to content

Commit

Permalink
Auto merge of rust-lang#8907 - kyoto7250:fix_8898, r=giraffate
Browse files Browse the repository at this point in the history
fix(lint): check const context

close: rust-lang/rust-clippy#8898

This PR fixes a bug in checked_conversions.

Thank you in advance.

changelog: check const context in checked_conversions.
  • Loading branch information
bors committed Jun 9, 2022
2 parents 50541b9 + 6fd2c6d commit 919cf50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/checked_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/checked_conversions.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
5 changes: 5 additions & 0 deletions tests/ui/checked_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

0 comments on commit 919cf50

Please sign in to comment.