Skip to content

Commit 81061a4

Browse files
committed
enable clippy::cast_possible_{truncation,wrap}
1 parent 86db51d commit 81061a4

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ all = "warn"
9292
as_ptr_cast_mut = "warn"
9393
as_underscore = "warn"
9494
cast_lossless = "warn"
95-
#cast_possible_truncation = "warn"
96-
#cast_possible_wrap = "warn"
95+
cast_possible_truncation = "warn"
96+
cast_possible_wrap = "warn"
9797
cast_precision_loss = "warn"
9898
cast_sign_loss = "warn"
9999
char_lit_as_u8 = "warn"

src/llvm/di.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'ctx> DISanitizer<'ctx> {
238238
self.visit_item(Item::Operand(Operand {
239239
parent: value_ref,
240240
value: operand,
241-
index: index as u32,
241+
index: index.try_into().unwrap(),
242242
}))
243243
}
244244
}
@@ -411,12 +411,17 @@ struct Operand {
411411

412412
impl Operand {
413413
fn replace(&mut self, value: LLVMValueRef) {
414+
let Self {
415+
parent,
416+
value: _,
417+
index,
418+
} = self;
414419
unsafe {
415-
if !LLVMIsAMDNode(self.parent).is_null() {
420+
if !LLVMIsAMDNode(*parent).is_null() {
416421
let value = LLVMValueAsMetadata(value);
417-
LLVMReplaceMDNodeOperandWith(self.parent, self.index, value);
418-
} else if !LLVMIsAUser(self.parent).is_null() {
419-
LLVMSetOperand(self.parent, self.index, value);
422+
LLVMReplaceMDNodeOperandWith(*parent, *index, value);
423+
} else if !LLVMIsAUser(*parent).is_null() {
424+
LLVMSetOperand(*parent, *index, value);
420425
}
421426
}
422427
}

src/llvm/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ pub(crate) fn init(args: &[Cow<'_, CStr>], overview: &CStr) {
6262
}
6363

6464
let c_ptrs = args.iter().map(|s| s.as_ptr()).collect::<Vec<_>>();
65-
unsafe { LLVMParseCommandLineOptions(c_ptrs.len() as i32, c_ptrs.as_ptr(), overview.as_ptr()) };
65+
unsafe {
66+
LLVMParseCommandLineOptions(
67+
c_ptrs.len().try_into().unwrap(),
68+
c_ptrs.as_ptr(),
69+
overview.as_ptr(),
70+
)
71+
};
6672
}
6773

6874
pub(crate) fn find_embedded_bitcode(
@@ -93,7 +99,7 @@ pub(crate) fn find_embedded_bitcode(
9399
let name = unsafe { CStr::from_ptr(name) };
94100
if name == c".llvmbc" {
95101
let buf = unsafe { LLVMGetSectionContents(iter) };
96-
let size = unsafe { LLVMGetSectionSize(iter) } as usize;
102+
let size = unsafe { LLVMGetSectionSize(iter) }.try_into().unwrap();
97103
ret = Some(unsafe { slice::from_raw_parts(buf.cast(), size).to_vec() });
98104
break;
99105
}

src/llvm/types/di.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ impl DIType<'_> {
135135

136136
/// Returns the offset of the type in bits. This offset is used in case the
137137
/// type is a member of a composite type.
138-
pub(crate) fn offset_in_bits(&self) -> usize {
139-
unsafe { LLVMDITypeGetOffsetInBits(self.metadata_ref) as usize }
138+
pub(crate) fn offset_in_bits(&self) -> u64 {
139+
unsafe { LLVMDITypeGetOffsetInBits(self.metadata_ref) }
140140
}
141141
}
142142

src/llvm/types/ir.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl MDNode<'_> {
253253

254254
pub(crate) struct MetadataEntries {
255255
entries: *mut LLVMValueMetadataEntry,
256-
count: usize,
256+
count: u32,
257257
}
258258

259259
impl MetadataEntries {
@@ -268,14 +268,18 @@ impl MetadataEntries {
268268
return None;
269269
}
270270

271-
Some(Self { entries, count })
271+
Some(Self {
272+
entries,
273+
count: count.try_into().unwrap(),
274+
})
272275
}
273276

274277
pub(crate) fn iter(&self) -> impl Iterator<Item = (LLVMMetadataRef, u32)> + '_ {
275-
(0..self.count).map(move |index| unsafe {
278+
let Self { entries, count } = self;
279+
(0..*count).map(|index| unsafe {
276280
(
277-
LLVMValueMetadataEntriesGetMetadata(self.entries, index as u32),
278-
LLVMValueMetadataEntriesGetKind(self.entries, index as u32),
281+
LLVMValueMetadataEntriesGetMetadata(*entries, index),
282+
LLVMValueMetadataEntriesGetKind(*entries, index),
279283
)
280284
})
281285
}

0 commit comments

Comments
 (0)