Skip to content

Commit

Permalink
Fix cast_lossless lint
Browse files Browse the repository at this point in the history
```
cargo clippy --fix --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::cast_lossless
```
  • Loading branch information
nyurik authored and pvdrz committed Dec 1, 2024
1 parent 76a1134 commit 3c1a619
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
17 changes: 9 additions & 8 deletions bindgen/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
};
Expand Down
2 changes: 1 addition & 1 deletion bindgen/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3c1a619

Please sign in to comment.