Browse Source

Merge pull request #390 from dave-tucker/clippy-up

clippy: Fix latest nightly lints
Michal Rostecki 2 years ago
parent
commit
367ab20
3 changed files with 8 additions and 7 deletions
  1. 5 4
      aya-log/src/lib.rs
  2. 1 1
      xtask/src/build_ebpf.rs
  3. 2 2
      xtask/src/docs/mod.rs

+ 5 - 4
aya-log/src/lib.rs

@@ -53,7 +53,7 @@ use std::{
     fmt::{LowerHex, UpperHex},
     io, mem,
     net::{Ipv4Addr, Ipv6Addr},
-    ptr, slice, str,
+    ptr, str,
     sync::Arc,
 };
 
@@ -412,10 +412,11 @@ fn log_buf(mut buf: &[u8], logger: &dyn Log) -> Result<(), ()> {
                 full_log_msg.push_str(&value.format(last_hint.take())?);
             }
             Argument::ArrU16Len8 => {
-                let ptr = attr.value.as_ptr().cast::<u16>();
-                let slice = unsafe { slice::from_raw_parts(ptr, 8) };
+                let data: [u8; 16] = attr.value.try_into().map_err(|_| ())?;
                 let mut value: [u16; 8] = Default::default();
-                value.copy_from_slice(slice);
+                for (i, s) in data.chunks_exact(2).enumerate() {
+                    value[i] = ((s[1] as u16) << 8) | s[0] as u16;
+                }
                 full_log_msg.push_str(&value.format(last_hint.take())?);
             }
             Argument::Str => match str::from_utf8(attr.value) {

+ 1 - 1
xtask/src/build_ebpf.rs

@@ -81,7 +81,7 @@ fn build_rust_ebpf(opts: &Options) -> anyhow::Result<()> {
 
 fn get_libbpf_headers<P: AsRef<Path>>(libbpf_dir: P, include_path: P) -> anyhow::Result<()> {
     let dir = include_path.as_ref();
-    fs::create_dir_all(&dir)?;
+    fs::create_dir_all(dir)?;
     let status = Command::new("make")
         .current_dir(libbpf_dir.as_ref().join("src"))
         .arg(format!("INCLUDEDIR={}", dir.as_os_str().to_string_lossy()))

+ 2 - 2
xtask/src/docs/mod.rs

@@ -55,7 +55,7 @@ pub fn docs() -> Result<(), anyhow::Error> {
 
 fn build_docs(working_dir: &PathBuf, abs_header_path: &Path) -> Result<(), anyhow::Error> {
     let replace = Command::new("sed")
-        .current_dir(&working_dir)
+        .current_dir(working_dir)
         .args(vec!["-i.bak", "s/crabby.svg/crabby_dev.svg/", "src/lib.rs"])
         .status()
         .expect("failed to replace logo");
@@ -64,7 +64,7 @@ fn build_docs(working_dir: &PathBuf, abs_header_path: &Path) -> Result<(), anyho
     let args = vec!["+nightly", "doc", "--no-deps", "--all-features"];
 
     let status = Command::new("cargo")
-        .current_dir(&working_dir)
+        .current_dir(working_dir)
         .env(
             "RUSTDOCFLAGS",
             format!("--html-in-header {}", abs_header_path.to_str().unwrap()),