Skip to content

Commit 72836e5

Browse files
committed
Clippy --fix (I'm lame)
1 parent e30cc36 commit 72836e5

File tree

17 files changed

+82
-46
lines changed

17 files changed

+82
-46
lines changed

src/block/decoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mod test {
5959
///
6060
/// * `T` - The Callback Closure Type in the Config
6161
pub struct BlockDecoder<'a, T>(&'a mut pt_block_decoder, PhantomData<T>);
62-
impl<'a, T> BlockDecoder<'a, T> {
62+
impl<T> BlockDecoder<'_, T> {
6363
/// Allocate an Intel PT block decoder.
6464
///
6565
/// The decoder will work on the buffer defined in @config,
@@ -217,7 +217,7 @@ impl<'a, T> BlockDecoder<'a, T> {
217217
}
218218
}
219219

220-
impl<'a, T> Iterator for BlockDecoder<'a, T> {
220+
impl<T> Iterator for BlockDecoder<'_, T> {
221221
type Item = Result<(Block, Status), PtError>;
222222

223223
fn next(&mut self) -> Option<Result<(Block, Status), PtError>> {
@@ -229,7 +229,7 @@ impl<'a, T> Iterator for BlockDecoder<'a, T> {
229229
}
230230
}
231231

232-
impl<'a, T> Drop for BlockDecoder<'a, T> {
232+
impl<T> Drop for BlockDecoder<'_, T> {
233233
fn drop(&mut self) {
234234
unsafe { pt_blk_free_decoder(self.0) }
235235
}

src/config/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ impl<'a, T> ConfigBuilder<'a, T> {
196196
where F: FnMut(&Config<T>, &[u8]) -> (Unknown<T>, u32),
197197
F: 'a {
198198
// yeah.. libipt doesnt handle this -_-
199-
if buf.len() < 1 { return Err(
199+
if buf.is_empty() { return Err(
200200
PtError::new(PtErrorCode::Invalid, "buffer cant be empty!")
201201
)}
202202
let mut cfg: pt_config = unsafe { mem::zeroed() };
203203
cfg.size = mem::size_of::<pt_config>();
204204
cfg.begin = buf.as_mut_ptr();
205-
cfg.end = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
205+
cfg.end = unsafe { buf.as_mut_ptr().add(buf.len()) };
206206
cfg.decode.callback = Some(decode_callback::<F, T>);
207207
cfg.decode.context = &mut cb as *mut _ as *mut c_void;
208208
Ok(ConfigBuilder::<T>(cfg, PhantomData))
@@ -252,13 +252,13 @@ impl<'a> ConfigBuilder<'a, ()> {
252252
/// use the `with_callback` function
253253
/// returns `Invalid` when buf is empty
254254
pub fn new(buf: &'a mut [u8]) -> Result<ConfigBuilder<'a, ()>, PtError> {
255-
if buf.len() < 1 { return Err(
255+
if buf.is_empty() { return Err(
256256
PtError::new(PtErrorCode::Invalid, "buffer cant be empty!")
257257
)}
258258
let mut cfg: pt_config = unsafe { mem::zeroed() };
259259
cfg.size = mem::size_of::<pt_config>();
260260
cfg.begin = buf.as_mut_ptr();
261-
cfg.end = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
261+
cfg.end = unsafe { buf.as_mut_ptr().add(buf.len()) };
262262
Ok(ConfigBuilder::<()>(cfg, PhantomData))
263263
}
264264
}

src/config/filter.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ impl AddrFilter {
115115
}
116116

117117
pub struct AddrFilterBuilder (pub(super) pt_conf_addr_filter);
118+
impl Default for AddrFilterBuilder {
119+
fn default() -> Self {
120+
Self::new()
121+
}
122+
}
123+
118124
impl AddrFilterBuilder {
119125
pub fn new() -> Self { unsafe { mem::zeroed() }}
120126

src/event/qry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub enum CondBranch {
7777
/// it shall contain raw trace data and remain valid for the lifetime of the decoder.
7878
/// The decoder needs to be synchronized before it can be used.
7979
pub struct QueryDecoder<'a, T>(&'a mut pt_query_decoder, PhantomData<T>);
80-
impl<'a, T> QueryDecoder<'a, T> {
80+
impl<T> QueryDecoder<'_, T> {
8181
/// Allocate an Intel PT query decoder.
8282
///
8383
/// The decoder will work on the buffer defined in @config,
@@ -246,7 +246,7 @@ impl<'a, T> QueryDecoder<'a, T> {
246246
}
247247
}
248248

249-
impl<'a, T> Iterator for QueryDecoder<'a, T> {
249+
impl<T> Iterator for QueryDecoder<'_, T> {
250250
type Item = Result<(Event, Status), PtError>;
251251

252252
fn next(&mut self) -> Option<Result<(Event, Status), PtError>> {
@@ -258,6 +258,6 @@ impl<'a, T> Iterator for QueryDecoder<'a, T> {
258258
}
259259
}
260260

261-
impl<'a, T> Drop for QueryDecoder<'a, T> {
261+
impl<T> Drop for QueryDecoder<'_, T> {
262262
fn drop(&mut self) { unsafe { pt_qry_free_decoder(self.0) }}
263263
}

src/flags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ bitflags! {
99
/// Status flags for various IntelPT actions
1010
pub struct Status: u32 {
1111
/// There is no more trace data available.
12-
const EOS = pt_status_flag_pts_eos as u32;
12+
const EOS = pt_status_flag_pts_eos;
1313
/// There is an event pending.
14-
const EVENT_PENDING = pt_status_flag_pts_event_pending as u32;
14+
const EVENT_PENDING = pt_status_flag_pts_event_pending;
1515
/// The address has been suppressed.
16-
const IP_SUPRESSED = pt_status_flag_pts_ip_suppressed as u32;
16+
const IP_SUPRESSED = pt_status_flag_pts_ip_suppressed;
1717
}
1818
}
1919

src/image/image.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub struct Image<'a> {
237237
callback: Option<BoxedCallback>,
238238
}
239239

240-
impl<'a> Image<'a> {
240+
impl Image<'_> {
241241
/// Allocate a traced memory image.
242242
/// An optional @name may be given to the image.
243243
/// The name string is copied.
@@ -398,7 +398,7 @@ impl<'a> From<&'a mut pt_image> for Image<'a> {
398398
}
399399
}
400400

401-
impl<'a> Drop for Image<'a> {
401+
impl Drop for Image<'_> {
402402
fn drop(&mut self) {
403403
if self.dealloc {
404404
unsafe { pt_image_free(self.inner) }

src/image/iscache.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ mod test {
8383
/// A cache of traced image sections.
8484
#[derive(Debug)]
8585
pub struct SectionCache<'a>(pub(crate) &'a mut pt_image_section_cache);
86-
impl<'a> SectionCache<'a> {
86+
impl SectionCache<'_> {
8787
/// Allocate a traced memory image section cache.
8888
///
8989
/// An optional @name may be given to the cache.
@@ -97,7 +97,7 @@ impl<'a> SectionCache<'a> {
9797
PtErrorCode::Invalid,
9898
"invalid @name string: contains null bytes")
9999
)?.as_ptr())
100-
}}).map(|s| SectionCache(s))
100+
}}).map(SectionCache)
101101
}
102102

103103
/// Get the image section cache name.
@@ -146,8 +146,8 @@ impl<'a> SectionCache<'a> {
146146
/// Returns number of bytes read on success.
147147
/// Returns Nomap if @vaddr is not contained in section @isid.
148148
/// Returns BadImage if @iscache does not contain @isid.
149-
pub fn read<'b>(&mut self,
150-
buffer: &'b mut [u8],
149+
pub fn read(&mut self,
150+
buffer: &mut [u8],
151151
isid: u32,
152152
vaddr: u64) -> Result<u32, PtError> {
153153
extract_pterr(unsafe {
@@ -169,7 +169,7 @@ impl<'a> SectionCache<'a> {
169169
}
170170
}
171171

172-
impl<'a> Drop for SectionCache<'a> {
172+
impl Drop for SectionCache<'_> {
173173
fn drop(&mut self) {
174174
unsafe { pt_iscache_free(self.0) }
175175
}

src/insn/decoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mod test {
7979
/// it shall contain raw trace data and remain valid for the lifetime of the decoder.
8080
/// The decoder needs to be synchronized before it can be used.
8181
pub struct InsnDecoder<'a, T>(&'a mut pt_insn_decoder, PhantomData<T>);
82-
impl<'a, T> InsnDecoder<'a, T> {
82+
impl<T> InsnDecoder<'_, T> {
8383
/// Allocate an Intel PT instruction flow decoder.
8484
///
8585
/// The decoder will work on the buffer defined in @config,
@@ -253,7 +253,7 @@ impl<'a, T> InsnDecoder<'a, T> {
253253
}
254254
}
255255

256-
impl<'a, T> Iterator for InsnDecoder<'a, T> {
256+
impl<T> Iterator for InsnDecoder<'_, T> {
257257
type Item = Result<(Insn, Status), PtError>;
258258

259259
fn next(&mut self) -> Option<Result<(Insn, Status), PtError>> {
@@ -265,6 +265,6 @@ impl<'a, T> Iterator for InsnDecoder<'a, T> {
265265
}
266266
}
267267

268-
impl<'a, T> Drop for InsnDecoder<'a, T> {
268+
impl<T> Drop for InsnDecoder<'_, T> {
269269
fn drop(&mut self) { unsafe { pt_insn_free_decoder(self.0) } }
270270
}

src/packet/decoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ mod test {
5555
}
5656

5757
pub struct PacketDecoder<'a, T>(&'a mut pt_packet_decoder, PhantomData<T>);
58-
impl<'a, T> PacketDecoder<'a, T> {
58+
impl<T> PacketDecoder<'_, T> {
5959
/// Allocate an Intel PT packet decoder.
6060
///
6161
/// The decoder will work on the buffer defined in @config,
@@ -131,7 +131,7 @@ impl<'a, T> PacketDecoder<'a, T> {
131131
}
132132
}
133133

134-
impl<'a, T> Iterator for PacketDecoder<'a, T> {
134+
impl<T> Iterator for PacketDecoder<'_, T> {
135135
type Item = Result<Packet<T>, PtError>;
136136

137137
fn next(&mut self) -> Option<Result<Packet<T>, PtError>> {
@@ -143,6 +143,6 @@ impl<'a, T> Iterator for PacketDecoder<'a, T> {
143143
}
144144
}
145145

146-
impl<'a, T> Drop for PacketDecoder<'a, T> {
146+
impl<T> Drop for PacketDecoder<'_, T> {
147147
fn drop(&mut self) { unsafe { pt_pkt_free_decoder(self.0) }}
148148
}

src/packet/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod tests {
4848
}
4949

5050
pub struct Encoder<'a, T>(&'a mut pt_encoder, PhantomData<T>);
51-
impl<'a, T> Encoder<'a, T> {
51+
impl<T> Encoder<'_, T> {
5252
/// Allocate an Intel PT packet encoder.
5353
///
5454
/// The encoder will work on the buffer defined in @config, it shall contain raw trace data and remain valid for the lifetime of the encoder.
@@ -97,6 +97,6 @@ impl<'a, T> Encoder<'a, T> {
9797
}
9898
}
9999

100-
impl<'a, T> Drop for Encoder<'a, T> {
100+
impl<T> Drop for Encoder<'_, T> {
101101
fn drop(&mut self) { unsafe { pt_free_encoder(self.0) } }
102102
}

0 commit comments

Comments
 (0)