Ver Fonte

Avoid shadowing `buf`

Tamir Duberstein há 6 dias atrás
pai
commit
90c2165231
1 ficheiros alterados com 9 adições e 7 exclusões
  1. 9 7
      aya-log-ebpf-macros/src/expand.rs

+ 9 - 7
aya-log-ebpf-macros/src/expand.rs

@@ -141,17 +141,17 @@ pub(crate) fn log(args: LogArgs, level: Option<TokenStream>) -> Result<TokenStre
 
     let num_args = values.len();
     let values_iter = values.iter();
+    let buf = Ident::new("buf", Span::mixed_site());
     let size = Ident::new("size", Span::mixed_site());
     let len = Ident::new("len", Span::mixed_site());
-    let slice = Ident::new("slice", Span::mixed_site());
     let record = Ident::new("record", Span::mixed_site());
     Ok(quote! {
         match ::aya_log_ebpf::AYA_LOG_BUF.get_ptr_mut(0).and_then(|ptr| unsafe { ptr.as_mut() }) {
             None => {},
-            Some(::aya_log_ebpf::LogBuf { buf }) => {
+            Some(::aya_log_ebpf::LogBuf { buf: #buf }) => {
                 let _: Option<()> = (|| {
                     let #size = ::aya_log_ebpf::write_record_header(
-                        buf,
+                        #buf,
                         #target,
                         #lvl,
                         module_path!(),
@@ -161,11 +161,13 @@ pub(crate) fn log(args: LogArgs, level: Option<TokenStream>) -> Result<TokenStre
                     )?;
                     let mut #size = #size.get();
                     #(
-                        let #slice = buf.get_mut(#size..)?;
-                        let #len = ::aya_log_ebpf::WriteToBuf::write(#values_iter, #slice)?;
-                        #size += #len.get();
+                        {
+                            let #buf = #buf.get_mut(#size..)?;
+                            let #len = ::aya_log_ebpf::WriteToBuf::write(#values_iter, #buf)?;
+                            #size += #len.get();
+                        }
                     )*
-                    let #record = buf.get(..#size)?;
+                    let #record = #buf.get(..#size)?;
                     ::aya_log_ebpf::AYA_LOGS.output(#ctx, #record, 0);
                     Some(())
                 })();