Update for Rust v1.62.0

See https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
Test: run --rust
Tag:#compatibility

Bug: 236723597
Change-Id: Ideb3e7f1cfba76e7bbb12fe80555c733d286f16f
diff --git a/tools/pdl/src/generator.rs b/tools/pdl/src/generator.rs
index 1232c52..4d8008a 100644
--- a/tools/pdl/src/generator.rs
+++ b/tools/pdl/src/generator.rs
@@ -2,6 +2,7 @@
 use anyhow::{anyhow, bail, Context, Result};
 use quote::{format_ident, quote};
 use std::collections::HashMap;
+use std::fmt::Write;
 use std::path::Path;
 use syn::parse_quote;
 
@@ -22,50 +23,70 @@
         .file_name()
         .and_then(|path| path.to_str())
         .ok_or_else(|| anyhow!("could not find filename in {:?}", path))?;
-    code.push_str(&format!("// @generated rust packets from {filename}\n\n"));
+    let _ = write!(code, "// @generated rust packets from {filename}\n\n");
 
-    code.push_str(&quote_block! {
-        use bytes::{BufMut, Bytes, BytesMut};
-        use num_derive::{FromPrimitive, ToPrimitive};
-        use num_traits::{FromPrimitive, ToPrimitive};
-        use std::convert::{TryFrom, TryInto};
-        use std::fmt;
-        use std::sync::Arc;
-        use thiserror::Error;
-    });
-
-    code.push_str(&quote_block! {
-        type Result<T> = std::result::Result<T, Error>;
-    });
-
-    code.push_str(&quote_block! {
-        #[derive(Debug, Error)]
-        pub enum Error {
-            #[error("Packet parsing failed")]
-            InvalidPacketError,
-            #[error("{field} was {value:x}, which is not known")]
-            ConstraintOutOfBounds { field: String, value: u64 },
-            #[error("when parsing {obj}.{field} needed length of {wanted} but got {got}")]
-            InvalidLengthError { obj: String, field: String, wanted: usize, got: usize },
-            #[error("Due to size restrictions a struct could not be parsed.")]
-            ImpossibleStructError,
-            #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")]
-            InvalidEnumValueError { obj: String, field: String, value: u64, type_: String },
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            use bytes::{BufMut, Bytes, BytesMut};
+            use num_derive::{FromPrimitive, ToPrimitive};
+            use num_traits::{FromPrimitive, ToPrimitive};
+            use std::convert::{TryFrom, TryInto};
+            use std::fmt;
+            use std::sync::Arc;
+            use thiserror::Error;
         }
-    });
+    );
 
-    code.push_str(&quote_block! {
-        #[derive(Debug, Error)]
-        #[error("{0}")]
-        pub struct TryFromError(&'static str);
-    });
-
-    code.push_str(&quote_block! {
-        pub trait Packet {
-            fn to_bytes(self) -> Bytes;
-            fn to_vec(self) -> Vec<u8>;
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            type Result<T> = std::result::Result<T, Error>;
         }
-    });
+    );
+
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            #[derive(Debug, Error)]
+            pub enum Error {
+                #[error("Packet parsing failed")]
+                InvalidPacketError,
+                #[error("{field} was {value:x}, which is not known")]
+                ConstraintOutOfBounds { field: String, value: u64 },
+                #[error("when parsing {obj}.{field} needed length of {wanted} but got {got}")]
+                InvalidLengthError { obj: String, field: String, wanted: usize, got: usize },
+                #[error("Due to size restrictions a struct could not be parsed.")]
+                ImpossibleStructError,
+                #[error("when parsing field {obj}.{field}, {value} is not a valid {type_} value")]
+                InvalidEnumValueError { obj: String, field: String, value: u64, type_: String },
+            }
+        }
+    );
+
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            #[derive(Debug, Error)]
+            #[error("{0}")]
+            pub struct TryFromError(&'static str);
+        }
+    );
+
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            pub trait Packet {
+                fn to_bytes(self) -> Bytes;
+                fn to_vec(self) -> Vec<u8>;
+            }
+        }
+    );
 
     Ok(code)
 }
@@ -226,29 +247,33 @@
     let child_name = format_ident!("{id}Child");
     if has_children {
         let child_data_idents = child_idents.iter().map(|ident| format_ident!("{ident}Data"));
-        code.push_str(&quote_block! {
-            #[derive(Debug)]
-            enum #data_child_ident {
-                #(#child_idents(Arc<#child_data_idents>),)*
-                None,
-            }
+        let _ = write!(
+            code,
+            "{}",
+            &quote_block! {
+                #[derive(Debug)]
+                enum #data_child_ident {
+                    #(#child_idents(Arc<#child_data_idents>),)*
+                    None,
+                }
 
-            impl #data_child_ident {
-                fn get_total_size(&self) -> usize {
-                    // TODO(mgeisler): use Self instad of #data_child_ident.
-                    match self {
-                        #(#data_child_ident::#child_idents(value) => value.get_total_size(),)*
-                        #data_child_ident::None => 0,
+                impl #data_child_ident {
+                    fn get_total_size(&self) -> usize {
+                        // TODO(mgeisler): use Self instad of #data_child_ident.
+                        match self {
+                            #(#data_child_ident::#child_idents(value) => value.get_total_size(),)*
+                            #data_child_ident::None => 0,
+                        }
                     }
                 }
-            }
 
-            #[derive(Debug)]
-            pub enum #child_name {
-                #(#child_idents(#child_decl_packet_name),)*
-                None,
+                #[derive(Debug)]
+                pub enum #child_name {
+                    #(#child_idents(#child_decl_packet_name),)*
+                    None,
+                }
             }
-        });
+        );
     }
 
     let data_name = format_ident!("{id}Data");
@@ -261,13 +286,17 @@
         .iter()
         .map(|field| generate_field(field, parse_quote!()))
         .collect::<Result<Vec<_>>>()?;
-    code.push_str(&quote_block! {
-        #[derive(Debug)]
-        struct #data_name {
-            #(#plain_fields,)*
-            #child_field
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            #[derive(Debug)]
+            struct #data_name {
+                #(#plain_fields,)*
+                #child_field
+            }
         }
-    });
+    );
 
     let parent = parent_id.as_ref().map(|parent_id| match packets.get(parent_id.as_str()) {
         Some(ast::Decl::Packet { id, .. }) => {
@@ -281,25 +310,33 @@
     });
 
     let packet_name = format_ident!("{id}Packet");
-    code.push_str(&quote_block! {
-        #[derive(Debug, Clone)]
-        pub struct #packet_name {
-            #parent
-            #ident: Arc<#data_name>,
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            #[derive(Debug, Clone)]
+            pub struct #packet_name {
+                #parent
+                #ident: Arc<#data_name>,
+            }
         }
-    });
+    );
 
     let builder_name = format_ident!("{id}Builder");
     let pub_fields = fields
         .iter()
         .map(|field| generate_field(field, parse_quote!(pub)))
         .collect::<Result<Vec<_>>>()?;
-    code.push_str(&quote_block! {
-        #[derive(Debug)]
-        pub struct #builder_name {
-            #(#pub_fields,)*
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            #[derive(Debug)]
+            pub struct #builder_name {
+                #(#pub_fields,)*
+            }
         }
-    });
+    );
 
     // TODO(mgeisler): use the `Buf` trait instead of tracking
     // the offset manually.
@@ -336,61 +373,69 @@
         })
     });
 
-    code.push_str(&quote_block! {
-        impl #data_name {
-            fn conforms(bytes: &[u8]) -> bool {
-                // TODO(mgeisler): return Boolean expression directly.
-                // TODO(mgeisler): skip when total_field_size == 0.
-                if bytes.len() < #total_field_size {
-                    return false;
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            impl #data_name {
+                fn conforms(bytes: &[u8]) -> bool {
+                    // TODO(mgeisler): return Boolean expression directly.
+                    // TODO(mgeisler): skip when total_field_size == 0.
+                    if bytes.len() < #total_field_size {
+                        return false;
+                    }
+                    true
                 }
-                true
-            }
 
-            fn parse(bytes: &[u8]) -> Result<Self> {
-                #(#field_parsers)*
-                Ok(Self { #(#field_names),* })
-            }
+                fn parse(bytes: &[u8]) -> Result<Self> {
+                    #(#field_parsers)*
+                    Ok(Self { #(#field_names),* })
+                }
 
-            fn write_to(&self, buffer: &mut BytesMut) {
-                #(#field_writers)*
-            }
+                fn write_to(&self, buffer: &mut BytesMut) {
+                    #(#field_writers)*
+                }
 
-            fn get_total_size(&self) -> usize {
-                self.get_size()
-            }
+                fn get_total_size(&self) -> usize {
+                    self.get_size()
+                }
 
-            fn get_size(&self) -> usize {
-                let ret = 0;
-                #get_size_adjustment
-                ret
+                fn get_size(&self) -> usize {
+                    let ret = 0;
+                    #get_size_adjustment
+                    ret
+                }
             }
         }
-    });
+    );
 
-    code.push_str(&quote_block! {
-        impl Packet for #packet_name {
-            fn to_bytes(self) -> Bytes {
-                let mut buffer = BytesMut::new();
-                buffer.resize(self.#ident.get_total_size(), 0);
-                self.#ident.write_to(&mut buffer);
-                buffer.freeze()
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            impl Packet for #packet_name {
+                fn to_bytes(self) -> Bytes {
+                    let mut buffer = BytesMut::new();
+                    buffer.resize(self.#ident.get_total_size(), 0);
+                    self.#ident.write_to(&mut buffer);
+                    buffer.freeze()
+                }
+                fn to_vec(self) -> Vec<u8> {
+                    self.to_bytes().to_vec()
+                }
             }
-            fn to_vec(self) -> Vec<u8> {
-                self.to_bytes().to_vec()
+            impl From<#packet_name> for Bytes {
+                fn from(packet: #packet_name) -> Self {
+                    packet.to_bytes()
+                }
+            }
+            impl From<#packet_name> for Vec<u8> {
+                fn from(packet: #packet_name) -> Self {
+                    packet.to_vec()
+                }
             }
         }
-        impl From<#packet_name> for Bytes {
-            fn from(packet: #packet_name) -> Self {
-                packet.to_bytes()
-            }
-        }
-        impl From<#packet_name> for Vec<u8> {
-            fn from(packet: #packet_name) -> Self {
-                packet.to_vec()
-            }
-        }
-    });
+    );
 
     let specialize = has_children.then(|| {
         quote! {
@@ -408,39 +453,47 @@
         .iter()
         .map(|field| generate_field_getter(&ident, field))
         .collect::<Result<Vec<_>>>()?;
-    code.push_str(&quote_block! {
-        impl #packet_name {
-            pub fn parse(bytes: &[u8]) -> Result<Self> {
-                Ok(Self::new(Arc::new(#data_name::parse(bytes)?)).unwrap())
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            impl #packet_name {
+                pub fn parse(bytes: &[u8]) -> Result<Self> {
+                    Ok(Self::new(Arc::new(#data_name::parse(bytes)?)).unwrap())
+                }
+
+                #specialize
+
+                fn new(root: Arc<#data_name>) -> std::result::Result<Self, &'static str> {
+                    let #ident = root;
+                    Ok(Self { #ident })
+                }
+
+                #(#field_getters)*
             }
-
-            #specialize
-
-            fn new(root: Arc<#data_name>) -> std::result::Result<Self, &'static str> {
-                let #ident = root;
-                Ok(Self { #ident })
-            }
-
-            #(#field_getters)*
         }
-    });
+    );
 
     let child = has_children.then(|| {
         quote! {
             child: #data_child_ident::None,
         }
     });
-    code.push_str(&quote_block! {
-        impl #builder_name {
-            pub fn build(self) -> #packet_name {
-                let #ident = Arc::new(#data_name {
-                    #(#field_names: self.#field_names,)*
-                    #child
-                });
-                #packet_name::new(#ident).unwrap()
+    let _ = write!(
+        code,
+        "{}",
+        &quote_block! {
+            impl #builder_name {
+                pub fn build(self) -> #packet_name {
+                    let #ident = Arc::new(#data_name {
+                        #(#field_names: self.#field_names,)*
+                        #child
+                    });
+                    #packet_name::new(#ident).unwrap()
+                }
             }
         }
-    });
+    );
 
     Ok(code)
 }
diff --git a/tools/rootcanal/lmp/src/procedure/secure_simple_pairing.rs b/tools/rootcanal/lmp/src/procedure/secure_simple_pairing.rs
index acb6529..945cbbf 100644
--- a/tools/rootcanal/lmp/src/procedure/secure_simple_pairing.rs
+++ b/tools/rootcanal/lmp/src/procedure/secure_simple_pairing.rs
@@ -375,12 +375,12 @@
             AuthenticationMethod::NumericComparaison => {
                 send_commitment(ctx, true).await;
 
-                let _user_confirmation = user_confirmation_request(ctx).await?;
+                user_confirmation_request(ctx).await?;
                 Ok(())
             }
             AuthenticationMethod::PasskeyEntry => {
                 if initiator.io_capability == hci::IoCapability::KeyboardOnly {
-                    let _user_passkey = user_passkey_request(ctx).await?;
+                    user_passkey_request(ctx).await?;
                 } else {
                     ctx.send_hci_event(
                         hci::UserPasskeyNotificationBuilder {
@@ -397,7 +397,7 @@
             }
             AuthenticationMethod::OutOfBand => {
                 if initiator.oob_data_present != hci::OobDataPresent::NotPresent {
-                    let _remote_oob_data = remote_oob_data_request(ctx).await?;
+                    remote_oob_data_request(ctx).await?;
                 }
 
                 send_commitment(ctx, false).await;