Skip to content

Commit 3c1a619

Browse files
nyurikpvdrz
authored andcommitted
Fix cast_lossless lint
``` cargo clippy --fix --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::cast_lossless ```
1 parent 76a1134 commit 3c1a619

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

bindgen/clang.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,7 @@ impl Index {
17911791
pub(crate) fn new(pch: bool, diag: bool) -> Index {
17921792
unsafe {
17931793
Index {
1794-
x: clang_createIndex(pch as c_int, diag as c_int),
1794+
x: clang_createIndex(c_int::from(pch), c_int::from(diag)),
17951795
}
17961796
}
17971797
}

bindgen/codegen/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3329,7 +3329,7 @@ impl<'a> EnumBuilder<'a> {
33293329
let is_rust_enum = self.is_rust_enum();
33303330
let expr = match variant.val() {
33313331
EnumVariantValue::Boolean(v) if is_rust_enum => {
3332-
helpers::ast_ty::uint_expr(v as u64)
3332+
helpers::ast_ty::uint_expr(u64::from(v))
33333333
}
33343334
EnumVariantValue::Boolean(v) => quote!(#v),
33353335
EnumVariantValue::Signed(v) => helpers::ast_ty::int_expr(v),

bindgen/ir/var.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,24 @@ fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind {
125125
ctx.options().default_macro_constant_type ==
126126
MacroTypeVariation::Signed
127127
{
128-
if value < i32::MIN as i64 || value > i32::MAX as i64 {
128+
if value < i64::from(i32::MIN) || value > i64::from(i32::MAX) {
129129
IntKind::I64
130130
} else if !ctx.options().fit_macro_constants ||
131-
value < i16::MIN as i64 ||
132-
value > i16::MAX as i64
131+
value < i64::from(i16::MIN) ||
132+
value > i64::from(i16::MAX)
133133
{
134134
IntKind::I32
135-
} else if value < i8::MIN as i64 || value > i8::MAX as i64 {
135+
} else if value < i64::from(i8::MIN) || value > i64::from(i8::MAX) {
136136
IntKind::I16
137137
} else {
138138
IntKind::I8
139139
}
140-
} else if value > u32::MAX as i64 {
140+
} else if value > i64::from(u32::MAX) {
141141
IntKind::U64
142-
} else if !ctx.options().fit_macro_constants || value > u16::MAX as i64 {
142+
} else if !ctx.options().fit_macro_constants || value > i64::from(u16::MAX)
143+
{
143144
IntKind::U32
144-
} else if value > u8::MAX as i64 {
145+
} else if value > i64::from(u8::MAX) {
145146
IntKind::U16
146147
} else {
147148
IntKind::U8
@@ -235,7 +236,7 @@ impl ClangSubItemParser for Var {
235236
c as u8
236237
}
237238
CChar::Raw(c) => {
238-
assert!(c <= u8::MAX as u64);
239+
assert!(c <= u64::from(u8::MAX));
239240
c as u8
240241
}
241242
};

bindgen/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a> Timer<'a> {
3636
if self.output {
3737
let elapsed = self.elapsed();
3838
let time = (elapsed.as_secs() as f64) * 1e3 +
39-
(elapsed.subsec_nanos() as f64) / 1e6;
39+
f64::from(elapsed.subsec_nanos()) / 1e6;
4040
let stderr = io::stderr();
4141
// Arbitrary output format, subject to change.
4242
writeln!(stderr.lock(), " time: {time:>9.3} ms.\t{}", self.name)

0 commit comments

Comments
 (0)