Skip to content

Commit 560bef0

Browse files
committed
fix clippy hints
1 parent 5329f29 commit 560bef0

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

src/commands.rs

+22-21
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ impl VersionTag {
3939
}
4040
}
4141

42-
impl Into<u32> for VersionTag {
43-
fn into(self) -> u32 {
44-
self.0
42+
impl From<VersionTag> for u32 {
43+
fn from(v: VersionTag) -> Self {
44+
v.0
4545
}
4646
}
4747

@@ -85,20 +85,20 @@ impl fmt::Display for VersionTag {
8585
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
8686
pub struct SourceVersionTag(u64);
8787

88-
impl Into<u64> for SourceVersionTag {
89-
fn into(self) -> u64 {
90-
self.0
88+
impl From<SourceVersionTag> for u64 {
89+
fn from(v: SourceVersionTag) -> Self {
90+
v.0
9191
}
9292
}
9393

94-
impl Into<(u32, u32, u32, u32, u32)> for SourceVersionTag {
95-
fn into(self) -> (u32, u32, u32, u32, u32) {
94+
impl From<SourceVersionTag> for (u32, u32, u32, u32, u32) {
95+
fn from(v: SourceVersionTag) -> (u32, u32, u32, u32, u32) {
9696
(
97-
((self.0 >> 40) & 0xFFF) as u32,
98-
((self.0 >> 30) & 0x3FF) as u32,
99-
((self.0 >> 20) & 0x3FF) as u32,
100-
((self.0 >> 10) & 0x3FF) as u32,
101-
(self.0 & 0x3FF) as u32,
97+
((v.0 >> 40) & 0xFFF) as u32,
98+
((v.0 >> 30) & 0x3FF) as u32,
99+
((v.0 >> 20) & 0x3FF) as u32,
100+
((v.0 >> 10) & 0x3FF) as u32,
101+
(v.0 & 0x3FF) as u32,
102102
)
103103
}
104104
}
@@ -140,10 +140,9 @@ impl From<u32> for BuildTarget {
140140
}
141141
}
142142
}
143-
144-
impl Into<u32> for BuildTarget {
145-
fn into(self) -> u32 {
146-
match self {
143+
impl From<BuildTarget> for u32 {
144+
fn from(t: BuildTarget) -> u32 {
145+
match t {
147146
BuildTarget::MacOsX => LC_VERSION_MIN_MACOSX,
148147
BuildTarget::IPhoneOs => LC_VERSION_MIN_IPHONEOS,
149148
BuildTarget::WatchOs => LC_VERSION_MIN_WATCHOS,
@@ -1439,7 +1438,9 @@ impl LoadCommand {
14391438

14401439
if cmdsize < read {
14411440
return Err(BufferOverflow(cmdsize));
1442-
} else if cmdsize > read {
1441+
}
1442+
1443+
if cmdsize > read {
14431444
// skip the reserved or padding bytes
14441445
buf.consume(cmdsize - read);
14451446
}
@@ -1676,9 +1677,9 @@ impl SectionFlags {
16761677
}
16771678
}
16781679

1679-
impl Into<u32> for SectionFlags {
1680-
fn into(self) -> u32 {
1681-
self.0
1680+
impl From<SectionFlags> for u32 {
1681+
fn from(f: SectionFlags) -> u32 {
1682+
f.0
16821683
}
16831684
}
16841685

src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub type off_t = u32;
1414
/// mask for architecture bits
1515
pub const CPU_ARCH_MASK: cpu_type_t = 0xff00_0000u32 as cpu_type_t;
1616
/// 64 bit ABI
17-
pub const CPU_ARCH_ABI64: cpu_type_t = 0x0100_0000 as cpu_type_t;
17+
pub const CPU_ARCH_ABI64: cpu_type_t = 0x0100_0000i32;
1818

1919
// Machine types known by all.
2020
//

src/export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a> Iterator for ExportSymbols<'a> {
155155

156156
if let Some((kind, ref symbol)) = node.symbol {
157157
return Some(ExportSymbol {
158-
name: prefix.clone(),
158+
name: prefix,
159159
kind,
160160
symbol: symbol.clone(),
161161
});

src/loader.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl ArHeader {
205205

206206
for c in s.as_bytes() {
207207
if *c < b'0' || b'7' < *c {
208-
return Err(ParseOctalError(String::from(s)).into());
208+
return Err(ParseOctalError(String::from(s)));
209209
}
210210

211211
v = v * 8 + (c - b'0') as usize;
@@ -278,15 +278,15 @@ impl OFile {
278278
buf.seek(SeekFrom::Current(-4))?;
279279

280280
if buf.get_ref().as_ref().len() < ar_magic.len() {
281-
return Err(UnknownMagic(magic).into());
281+
return Err(UnknownMagic(magic));
282282
}
283283

284284
buf.read_exact(&mut ar_magic)?;
285285

286286
if ar_magic == ARMAG {
287287
Self::parse_ar_file::<NativeEndian, T>(buf)
288288
} else {
289-
Err(UnknownMagic(magic).into())
289+
Err(UnknownMagic(magic))
290290
}
291291
}
292292
}
@@ -346,7 +346,7 @@ impl OFile {
346346

347347
for arch in archs {
348348
if u64::from(arch.offset) < start {
349-
return Err(BufferOverflow(arch.offset as usize).into());
349+
return Err(BufferOverflow(arch.offset as usize));
350350
}
351351

352352
let content = payload.checked_slice(arch.offset as usize, arch.size as usize)?;
@@ -374,10 +374,10 @@ impl OFile {
374374
let mut end = buf
375375
.position()
376376
.checked_add(header.ar_size as u64)
377-
.ok_or_else(|| BufferOverflow(header.ar_size as usize))?;
377+
.ok_or(BufferOverflow(header.ar_size as usize))?;
378378

379379
if let Some(size) = header.extended_format_size() {
380-
end = end.checked_sub(size as u64).ok_or_else(|| BufferOverflow(size))?;
380+
end = end.checked_sub(size as u64).ok_or(BufferOverflow(size))?;
381381
}
382382

383383
if header.name() == SYMDEF || header.name() == SYMDEF_SORTED {
@@ -436,12 +436,12 @@ pub trait CheckedSlice<T>: AsRef<[T]> {
436436
fn checked_slice(&self, off: usize, len: usize) -> Result<&[T]> {
437437
let s = self.as_ref();
438438
let start = off as usize;
439-
let end = off.checked_add(len).ok_or_else(|| BufferOverflow(len))? as usize;
439+
let end = off.checked_add(len).ok_or(BufferOverflow(len))? as usize;
440440

441441
if start >= s.len() || start >= end {
442-
Err(BufferOverflow(start).into())
442+
Err(BufferOverflow(start))
443443
} else if end > s.len() {
444-
Err(BufferOverflow(end).into())
444+
Err(BufferOverflow(end))
445445
} else {
446446
Ok(&s[start..end])
447447
}

0 commit comments

Comments
 (0)