diff --git a/.github/workflows/cargo.yml b/.github/workflows/cargo.yml index 665e1db..1119bff 100644 --- a/.github/workflows/cargo.yml +++ b/.github/workflows/cargo.yml @@ -52,7 +52,7 @@ jobs: shell: bash continue-on-error: true - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: clippy-sarif path: clippy.sarif @@ -65,7 +65,7 @@ jobs: security-events: write steps: - uses: actions/checkout@v3 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: clippy-sarif - uses: github/codeql-action/upload-sarif@v2 diff --git a/perf-event/src/builder.rs b/perf-event/src/builder.rs index cb3b3d7..fbb1fef 100644 --- a/perf-event/src/builder.rs +++ b/perf-event/src/builder.rs @@ -284,8 +284,7 @@ impl<'a> Builder<'a> { pub fn build_group(&self) -> io::Result { let read_format = ReadFormat::from_bits_retain(self.attrs.read_format); if !read_format.contains(ReadFormat::GROUP) { - return Err(io::Error::new( - ErrorKind::Other, + return Err(io::Error::other( "groups must be created with the GROUP flag enabled", )); } diff --git a/perf-event/src/events/dynamic.rs b/perf-event/src/events/dynamic.rs index 7961ee3..721b060 100644 --- a/perf-event/src/events/dynamic.rs +++ b/perf-event/src/events/dynamic.rs @@ -665,7 +665,7 @@ impl std::error::Error for MissingParameterError {} impl From for io::Error { fn from(value: DynamicBuilderError) -> Self { - io::Error::new(io::ErrorKind::Other, value) + io::Error::other(value) } } @@ -677,7 +677,7 @@ impl From for DynamicBuilderError { impl From for io::Error { fn from(value: MissingParameterError) -> Self { - io::Error::new(io::ErrorKind::Other, value) + io::Error::other(value) } } diff --git a/perf-event/src/events/tracepoint.rs b/perf-event/src/events/tracepoint.rs index 2f992c9..1e2f2ee 100644 --- a/perf-event/src/events/tracepoint.rs +++ b/perf-event/src/events/tracepoint.rs @@ -64,9 +64,7 @@ impl Tracepoint { let id = std::fs::read_to_string(&path)? .trim_end() .parse() - .map_err(move |e| { - io::Error::new(io::ErrorKind::Other, UnparseableIdFile::new(path, e)) - })?; + .map_err(move |e| io::Error::other(UnparseableIdFile::new(path, e)))?; Ok(Self::with_id(id)) } diff --git a/perf-event/src/events/util.rs b/perf-event/src/events/util.rs index 8656040..da0d2a5 100644 --- a/perf-event/src/events/util.rs +++ b/perf-event/src/events/util.rs @@ -58,13 +58,10 @@ impl CachedPmuType { .trim_end() .parse() .map_err(|e| { - io::Error::new( - io::ErrorKind::Other, - ParsePmuTypeError { - name: self.name, - error: e, - }, - ) + io::Error::other(ParsePmuTypeError { + name: self.name, + error: e, + }) })?; self.value.store(ty, Ordering::Relaxed); diff --git a/perf-event/src/group_data.rs b/perf-event/src/group_data.rs index 1234a96..c201440 100644 --- a/perf-event/src/group_data.rs +++ b/perf-event/src/group_data.rs @@ -164,7 +164,7 @@ impl GroupData { /// } /// # std::io::Result::Ok(()) /// ``` - pub fn iter(&self) -> GroupIter { + pub fn iter(&self) -> GroupIter<'_> { let mut iter = self.iter_with_group(); if self.should_skip { let _ = iter.next(); @@ -172,7 +172,7 @@ impl GroupData { iter } - fn iter_with_group(&self) -> GroupIter { + fn iter_with_group(&self) -> GroupIter<'_> { GroupIter(self.data.entries()) } diff --git a/perf-event/src/lib.rs b/perf-event/src/lib.rs index 1c34854..742b90b 100644 --- a/perf-event/src/lib.rs +++ b/perf-event/src/lib.rs @@ -633,21 +633,11 @@ impl Counter { count: data.count(), time_enabled: data .time_enabled() - .ok_or_else(|| { - io::Error::new( - io::ErrorKind::Other, - "time_enabled was not enabled within read_format", - ) - })? + .ok_or_else(|| io::Error::other("time_enabled was not enabled within read_format"))? .as_nanos() as _, time_running: data .time_running() - .ok_or_else(|| { - io::Error::new( - io::ErrorKind::Other, - "time_running was not enabled within read_format", - ) - })? + .ok_or_else(|| io::Error::other("time_running was not enabled within read_format"))? .as_nanos() as _, }) } @@ -676,9 +666,7 @@ impl Counter { } let mut parser = crate::data::parse::Parser::new(&data[..len], self.config.clone()); - let value: crate::data::ReadValue = parser - .parse() - .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + let value: crate::data::ReadValue = parser.parse().map_err(io::Error::other)?; Ok(CounterData(value)) } @@ -741,7 +729,7 @@ impl Counter { let mut parser = crate::data::parse::Parser::new(data.as_slice(), self.config.clone()); let data: ReadGroup = parser .parse::() - .map_err(|e| io::Error::new(io::ErrorKind::Other, e))? + .map_err(io::Error::other)? .into_owned(); let data = GroupData::new(data); diff --git a/perf-event/src/sampler.rs b/perf-event/src/sampler.rs index 809e3aa..f99ee8e 100644 --- a/perf-event/src/sampler.rs +++ b/perf-event/src/sampler.rs @@ -91,7 +91,7 @@ impl Sampler { /// /// [`next_blocking`]: Self::next_blocking /// [man]: https://www.mankier.com/2/perf_event_open - pub fn next_record(&mut self) -> Option { + pub fn next_record(&mut self) -> Option> { use std::{mem, ptr, slice}; let page = self.page(); @@ -163,7 +163,7 @@ impl Sampler { /// `libc::poll`. There are only two cases where this can happen: /// - the current process has run out of file descriptors, or, /// - the kernel couldn't allocate memory for internal poll datastructures. - pub fn next_blocking(&mut self, timeout: Option) -> Option { + pub fn next_blocking(&mut self, timeout: Option) -> Option> { let deadline = timeout.map(|timeout| Instant::now() + timeout); loop { @@ -587,7 +587,7 @@ impl<'s> Record<'s> { /// /// For most records this is effectively free but if the record wraps /// around the end of the ringbuffer then it will be copied to a vector. - pub fn to_contiguous(&self) -> Cow<[u8]> { + pub fn to_contiguous(&self) -> Cow<'_, [u8]> { match self.data { ByteBuffer::Single(data) => Cow::Borrowed(data), ByteBuffer::Split([a, b]) => { @@ -600,7 +600,7 @@ impl<'s> Record<'s> { } /// Parse the data in this record to a [`data::Record`] enum. - pub fn parse_record(&self) -> ParseResult { + pub fn parse_record(&self) -> ParseResult> { let mut parser = Parser::new(self.data, self.sampler.config().clone()); data::Record::parse_with_header(&mut parser, self.header) }