From 3c1a6191c476f12c77671cef0231bbb9167f724f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 1 Dec 2024 01:45:20 -0500 Subject: [PATCH] Fix `cast_lossless` lint ``` cargo clippy --fix --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::cast_lossless ``` --- bindgen/clang.rs | 2 +- bindgen/codegen/mod.rs | 2 +- bindgen/ir/var.rs | 17 +++++++++-------- bindgen/time.rs | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 327ec137b0..037d526b1f 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1791,7 +1791,7 @@ impl Index { pub(crate) fn new(pch: bool, diag: bool) -> Index { unsafe { Index { - x: clang_createIndex(pch as c_int, diag as c_int), + x: clang_createIndex(c_int::from(pch), c_int::from(diag)), } } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index f60a75d23a..035cc9386f 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3329,7 +3329,7 @@ impl<'a> EnumBuilder<'a> { let is_rust_enum = self.is_rust_enum(); let expr = match variant.val() { EnumVariantValue::Boolean(v) if is_rust_enum => { - helpers::ast_ty::uint_expr(v as u64) + helpers::ast_ty::uint_expr(u64::from(v)) } EnumVariantValue::Boolean(v) => quote!(#v), EnumVariantValue::Signed(v) => helpers::ast_ty::int_expr(v), diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 8f9aa4441c..b84950aad6 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -125,23 +125,24 @@ fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { ctx.options().default_macro_constant_type == MacroTypeVariation::Signed { - if value < i32::MIN as i64 || value > i32::MAX as i64 { + if value < i64::from(i32::MIN) || value > i64::from(i32::MAX) { IntKind::I64 } else if !ctx.options().fit_macro_constants || - value < i16::MIN as i64 || - value > i16::MAX as i64 + value < i64::from(i16::MIN) || + value > i64::from(i16::MAX) { IntKind::I32 - } else if value < i8::MIN as i64 || value > i8::MAX as i64 { + } else if value < i64::from(i8::MIN) || value > i64::from(i8::MAX) { IntKind::I16 } else { IntKind::I8 } - } else if value > u32::MAX as i64 { + } else if value > i64::from(u32::MAX) { IntKind::U64 - } else if !ctx.options().fit_macro_constants || value > u16::MAX as i64 { + } else if !ctx.options().fit_macro_constants || value > i64::from(u16::MAX) + { IntKind::U32 - } else if value > u8::MAX as i64 { + } else if value > i64::from(u8::MAX) { IntKind::U16 } else { IntKind::U8 @@ -235,7 +236,7 @@ impl ClangSubItemParser for Var { c as u8 } CChar::Raw(c) => { - assert!(c <= u8::MAX as u64); + assert!(c <= u64::from(u8::MAX)); c as u8 } }; diff --git a/bindgen/time.rs b/bindgen/time.rs index 435890c42c..a220de7d9f 100644 --- a/bindgen/time.rs +++ b/bindgen/time.rs @@ -36,7 +36,7 @@ impl<'a> Timer<'a> { if self.output { let elapsed = self.elapsed(); let time = (elapsed.as_secs() as f64) * 1e3 + - (elapsed.subsec_nanos() as f64) / 1e6; + f64::from(elapsed.subsec_nanos()) / 1e6; let stderr = io::stderr(); // Arbitrary output format, subject to change. writeln!(stderr.lock(), " time: {time:>9.3} ms.\t{}", self.name)