Skip to content

Commit 10b8650

Browse files
committed
Chore: Clippy and GitHub CI fixes.
1 parent 31ae86c commit 10b8650

File tree

8 files changed

+20
-38
lines changed

8 files changed

+20
-38
lines changed

.github/workflows/cargo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
shell: bash
5353
continue-on-error: true
5454

55-
- uses: actions/upload-artifact@v3
55+
- uses: actions/upload-artifact@v4
5656
with:
5757
name: clippy-sarif
5858
path: clippy.sarif
@@ -65,7 +65,7 @@ jobs:
6565
security-events: write
6666
steps:
6767
- uses: actions/checkout@v3
68-
- uses: actions/download-artifact@v3
68+
- uses: actions/download-artifact@v4
6969
with:
7070
name: clippy-sarif
7171
- uses: github/codeql-action/upload-sarif@v2

perf-event/src/builder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ impl<'a> Builder<'a> {
284284
pub fn build_group(&self) -> io::Result<Group> {
285285
let read_format = ReadFormat::from_bits_retain(self.attrs.read_format);
286286
if !read_format.contains(ReadFormat::GROUP) {
287-
return Err(io::Error::new(
288-
ErrorKind::Other,
287+
return Err(io::Error::other(
289288
"groups must be created with the GROUP flag enabled",
290289
));
291290
}

perf-event/src/events/dynamic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl std::error::Error for MissingParameterError {}
665665

666666
impl From<DynamicBuilderError> for io::Error {
667667
fn from(value: DynamicBuilderError) -> Self {
668-
io::Error::new(io::ErrorKind::Other, value)
668+
io::Error::other(value)
669669
}
670670
}
671671

@@ -677,7 +677,7 @@ impl From<MissingParameterError> for DynamicBuilderError {
677677

678678
impl From<MissingParameterError> for io::Error {
679679
fn from(value: MissingParameterError) -> Self {
680-
io::Error::new(io::ErrorKind::Other, value)
680+
io::Error::other(value)
681681
}
682682
}
683683

perf-event/src/events/tracepoint.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ impl Tracepoint {
6464
let id = std::fs::read_to_string(&path)?
6565
.trim_end()
6666
.parse()
67-
.map_err(move |e| {
68-
io::Error::new(io::ErrorKind::Other, UnparseableIdFile::new(path, e))
69-
})?;
67+
.map_err(move |e| io::Error::other(UnparseableIdFile::new(path, e)))?;
7068

7169
Ok(Self::with_id(id))
7270
}

perf-event/src/events/util.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ impl CachedPmuType {
5858
.trim_end()
5959
.parse()
6060
.map_err(|e| {
61-
io::Error::new(
62-
io::ErrorKind::Other,
63-
ParsePmuTypeError {
64-
name: self.name,
65-
error: e,
66-
},
67-
)
61+
io::Error::other(ParsePmuTypeError {
62+
name: self.name,
63+
error: e,
64+
})
6865
})?;
6966

7067
self.value.store(ty, Ordering::Relaxed);

perf-event/src/group_data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ impl GroupData {
164164
/// }
165165
/// # std::io::Result::Ok(())
166166
/// ```
167-
pub fn iter(&self) -> GroupIter {
167+
pub fn iter(&self) -> GroupIter<'_> {
168168
let mut iter = self.iter_with_group();
169169
if self.should_skip {
170170
let _ = iter.next();
171171
}
172172
iter
173173
}
174174

175-
fn iter_with_group(&self) -> GroupIter {
175+
fn iter_with_group(&self) -> GroupIter<'_> {
176176
GroupIter(self.data.entries())
177177
}
178178

perf-event/src/lib.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -633,21 +633,11 @@ impl Counter {
633633
count: data.count(),
634634
time_enabled: data
635635
.time_enabled()
636-
.ok_or_else(|| {
637-
io::Error::new(
638-
io::ErrorKind::Other,
639-
"time_enabled was not enabled within read_format",
640-
)
641-
})?
636+
.ok_or_else(|| io::Error::other("time_enabled was not enabled within read_format"))?
642637
.as_nanos() as _,
643638
time_running: data
644639
.time_running()
645-
.ok_or_else(|| {
646-
io::Error::new(
647-
io::ErrorKind::Other,
648-
"time_running was not enabled within read_format",
649-
)
650-
})?
640+
.ok_or_else(|| io::Error::other("time_running was not enabled within read_format"))?
651641
.as_nanos() as _,
652642
})
653643
}
@@ -676,9 +666,7 @@ impl Counter {
676666
}
677667

678668
let mut parser = crate::data::parse::Parser::new(&data[..len], self.config.clone());
679-
let value: crate::data::ReadValue = parser
680-
.parse()
681-
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
669+
let value: crate::data::ReadValue = parser.parse().map_err(io::Error::other)?;
682670

683671
Ok(CounterData(value))
684672
}
@@ -741,7 +729,7 @@ impl Counter {
741729
let mut parser = crate::data::parse::Parser::new(data.as_slice(), self.config.clone());
742730
let data: ReadGroup = parser
743731
.parse::<ReadGroup>()
744-
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?
732+
.map_err(io::Error::other)?
745733
.into_owned();
746734

747735
let data = GroupData::new(data);

perf-event/src/sampler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Sampler {
9191
///
9292
/// [`next_blocking`]: Self::next_blocking
9393
/// [man]: https://www.mankier.com/2/perf_event_open
94-
pub fn next_record(&mut self) -> Option<Record> {
94+
pub fn next_record(&mut self) -> Option<Record<'_>> {
9595
use std::{mem, ptr, slice};
9696

9797
let page = self.page();
@@ -163,7 +163,7 @@ impl Sampler {
163163
/// `libc::poll`. There are only two cases where this can happen:
164164
/// - the current process has run out of file descriptors, or,
165165
/// - the kernel couldn't allocate memory for internal poll datastructures.
166-
pub fn next_blocking(&mut self, timeout: Option<Duration>) -> Option<Record> {
166+
pub fn next_blocking(&mut self, timeout: Option<Duration>) -> Option<Record<'_>> {
167167
let deadline = timeout.map(|timeout| Instant::now() + timeout);
168168

169169
loop {
@@ -587,7 +587,7 @@ impl<'s> Record<'s> {
587587
///
588588
/// For most records this is effectively free but if the record wraps
589589
/// around the end of the ringbuffer then it will be copied to a vector.
590-
pub fn to_contiguous(&self) -> Cow<[u8]> {
590+
pub fn to_contiguous(&self) -> Cow<'_, [u8]> {
591591
match self.data {
592592
ByteBuffer::Single(data) => Cow::Borrowed(data),
593593
ByteBuffer::Split([a, b]) => {
@@ -600,7 +600,7 @@ impl<'s> Record<'s> {
600600
}
601601

602602
/// Parse the data in this record to a [`data::Record`] enum.
603-
pub fn parse_record(&self) -> ParseResult<data::Record> {
603+
pub fn parse_record(&self) -> ParseResult<data::Record<'_>> {
604604
let mut parser = Parser::new(self.data, self.sampler.config().clone());
605605
data::Record::parse_with_header(&mut parser, self.header)
606606
}

0 commit comments

Comments
 (0)