Jelajahi Sumber

suppress erroneous lints related to nested deprecation blocks (#8899)

Trent Nelson 2 minggu lalu
induk
melakukan
3377d34db0

+ 16 - 4
clap-v3-utils/src/input_validators.rs

@@ -33,6 +33,7 @@ where
     T: FromStr,
     T::Err: Display,
 {
+    #[allow(deprecated)]
     is_parsable_generic::<T, &str>(string)
 }
 
@@ -66,6 +67,7 @@ where
     note = "please use `clap::value_parser!(Pubkey)` instead"
 )]
 pub fn is_pubkey(string: &str) -> Result<(), String> {
+    #[allow(deprecated)]
     is_parsable_generic::<Pubkey, _>(string)
 }
 
@@ -78,6 +80,7 @@ pub fn is_hash<T>(string: T) -> Result<(), String>
 where
     T: AsRef<str> + Display,
 {
+    #[allow(deprecated)]
     is_parsable_generic::<Hash, _>(string)
 }
 
@@ -106,6 +109,7 @@ pub fn is_keypair_or_ask_keyword<T>(string: T) -> Result<(), String>
 where
     T: AsRef<str> + Display,
 {
+    #[allow(deprecated)]
     if string.as_ref() == ASK_KEYWORD {
         return Ok(());
     }
@@ -121,13 +125,16 @@ where
             `SignerSourceParserBuilder::default().allow_prompt().allow_legacy().build()` instead"
 )]
 pub fn is_prompt_signer_source(string: &str) -> Result<(), String> {
+    #[allow(deprecated)]
     if string == ASK_KEYWORD {
         return Ok(());
     }
-    match SignerSource::parse(string)
+    #[allow(deprecated)]
+    let signer_source_kind = SignerSource::parse(string)
         .map_err(|err| format!("{err}"))?
-        .kind
-    {
+        .kind;
+    match signer_source_kind {
+        #[allow(deprecated)]
         SignerSourceKind::Prompt => Ok(()),
         _ => Err(format!(
             "Unable to parse input as `prompt:` URI scheme or `ASK` keyword: {string}"
@@ -243,7 +250,9 @@ pub fn is_url_or_moniker<T>(string: T) -> Result<(), String>
 where
     T: AsRef<str> + Display,
 {
-    match url::Url::parse(&normalize_to_url_if_moniker(string.as_ref())) {
+    #[allow(deprecated)]
+    let normalized = normalize_to_url_if_moniker(string.as_ref());
+    match url::Url::parse(&normalized) {
         Ok(url) => {
             if url.has_host() {
                 Ok(())
@@ -274,6 +283,7 @@ pub fn is_epoch<T>(epoch: T) -> Result<(), String>
 where
     T: AsRef<str> + Display,
 {
+    #[allow(deprecated)]
     is_parsable_generic::<Epoch, _>(epoch)
 }
 
@@ -285,6 +295,7 @@ pub fn is_slot<T>(slot: T) -> Result<(), String>
 where
     T: AsRef<str> + Display,
 {
+    #[allow(deprecated)]
     is_parsable_generic::<Slot, _>(slot)
 }
 
@@ -313,6 +324,7 @@ pub fn is_port<T>(port: T) -> Result<(), String>
 where
     T: AsRef<str> + Display,
 {
+    #[allow(deprecated)]
     is_parsable_generic::<u16, _>(port)
 }
 

+ 3 - 5
clap-v3-utils/src/keygen/mnemonic.rs

@@ -81,11 +81,9 @@ pub fn no_passphrase_arg<'a>() -> Arg<'a> {
 
 #[deprecated(since = "2.0.0", note = "Please use `try_get_language` instead")]
 pub fn acquire_language(matches: &ArgMatches) -> Language {
-    match matches
-        .get_one::<String>(LANGUAGE_ARG.name)
-        .unwrap()
-        .as_str()
-    {
+    #[allow(deprecated)]
+    let language_name = LANGUAGE_ARG.name;
+    match matches.get_one::<String>(language_name).unwrap().as_str() {
         "english" => Language::English,
         "chinese-simplified" => Language::ChineseSimplified,
         "chinese-traditional" => Language::ChineseTraditional,

+ 24 - 15
faucet/src/bin/faucet.rs

@@ -1,11 +1,12 @@
+#[allow(deprecated)]
+use solana_faucet::{
+    faucet::{run_faucet, Faucet, FAUCET_PORT},
+    socketaddr,
+};
 use {
     clap::{crate_description, crate_name, values_t, App, Arg},
     log::*,
     solana_clap_utils::input_parsers::{lamports_of_sol, value_of},
-    solana_faucet::{
-        faucet::{run_faucet, Faucet, FAUCET_PORT},
-        socketaddr,
-    },
     solana_keypair::read_keypair_file,
     std::{
         collections::HashSet,
@@ -81,23 +82,31 @@ async fn main() {
         .into_iter()
         .collect();
 
+    #[allow(deprecated)]
     let faucet_addr = socketaddr!(Ipv4Addr::UNSPECIFIED, FAUCET_PORT);
 
-    let faucet = Arc::new(Mutex::new(Faucet::new_with_allowed_ips(
-        faucet_keypair,
-        time_slice,
-        per_time_cap,
-        per_request_cap,
-        allowed_ips,
-    )));
+    let faucet = Arc::new(Mutex::new(
+        #[allow(deprecated)]
+        Faucet::new_with_allowed_ips(
+            faucet_keypair,
+            time_slice,
+            per_time_cap,
+            per_request_cap,
+            allowed_ips,
+        ),
+    ));
 
     let faucet1 = faucet.clone();
     thread::spawn(move || loop {
-        let time = faucet1.lock().unwrap().time_slice;
-        thread::sleep(time);
-        debug!("clearing ip cache");
-        faucet1.lock().unwrap().clear_caches();
+        #[allow(deprecated)]
+        {
+            let time = faucet1.lock().unwrap().time_slice;
+            thread::sleep(time);
+            debug!("clearing ip cache");
+            faucet1.lock().unwrap().clear_caches();
+        }
     });
 
+    #[allow(deprecated)]
     run_faucet(faucet, faucet_addr, None).await;
 }

+ 11 - 8
faucet/src/faucet.rs

@@ -327,14 +327,17 @@ pub fn run_local_faucet_with_port(
 ) {
     thread::spawn(move || {
         let faucet_addr = socketaddr!(Ipv4Addr::UNSPECIFIED, port);
-        let faucet = Arc::new(Mutex::new(Faucet::new(
-            faucet_keypair,
-            time_input,
-            per_time_cap,
-            per_request_cap,
-        )));
-        let runtime = Runtime::new().unwrap();
-        runtime.block_on(run_faucet(faucet, faucet_addr, Some(sender)));
+        #[allow(deprecated)]
+        {
+            let faucet = Arc::new(Mutex::new(Faucet::new(
+                faucet_keypair,
+                time_input,
+                per_time_cap,
+                per_request_cap,
+            )));
+            let runtime = Runtime::new().unwrap();
+            runtime.block_on(run_faucet(faucet, faucet_addr, Some(sender)));
+        }
     });
 }
 

+ 28 - 7
gossip/src/main.rs

@@ -1,5 +1,6 @@
 //! A command-line executable for monitoring a cluster's gossip plane.
-
+#[allow(deprecated)]
+use solana_gossip::{contact_info::ContactInfo, gossip_service::discover};
 use {
     clap::{
         crate_description, crate_name, value_t, value_t_or_exit, App, AppSettings, Arg, ArgMatches,
@@ -11,7 +12,6 @@ use {
         input_parsers::{keypair_of, pubkeys_of},
         input_validators::{is_keypair_or_ask_keyword, is_port, is_pubkey},
     },
-    solana_gossip::{contact_info::ContactInfo, gossip_service::discover},
     solana_pubkey::Pubkey,
     solana_streamer::socket::SocketAddrSpace,
     std::{
@@ -192,6 +192,16 @@ fn parse_bind_address(matches: &ArgMatches, entrypoint_addr: Option<SocketAddr>)
     }
 }
 
+// allow deprecations here to workaround limitations with dependency specification in
+// multi-target crates and agave-unstable-api. `ContactInfo` is deprecated here, but we
+// cannot specify deprecation allowances on function arguments. since this function is
+// private, we apply the allowance to the entire body as a refactor that would limit it
+// to a wrapper is going to be too invasive
+//
+// this mitigation can be removed once the solana-gossip binary target is moved to its
+// own crate and we can correctly depend on the solana-gossip lib crate with
+// `agave-unstable-api` enabled
+#[allow(deprecated)]
 fn process_spy_results(
     timeout: Option<u64>,
     validators: Vec<ContactInfo>,
@@ -213,7 +223,11 @@ fn process_spy_results(
         }
         if let Some(nodes) = pubkeys {
             for node in nodes {
-                if !validators.iter().any(|x| x.pubkey() == node) {
+                if !validators.iter().any(|x| {
+                    #[allow(deprecated)]
+                    let pubkey = x.pubkey();
+                    pubkey == node
+                }) {
                     eprintln!("Error: Could not find node {node:?}");
                     exit(1);
                 }
@@ -272,6 +286,7 @@ fn process_spy(matches: &ArgMatches, socket_addr_space: SocketAddrSpace) -> std:
     }
 
     let discover_timeout = Duration::from_secs(timeout.unwrap_or(u64::MAX));
+    #[allow(deprecated)]
     let (_all_peers, validators) = discover(
         identity_keypair,
         entrypoint_addr.as_ref(),
@@ -320,6 +335,7 @@ fn process_rpc_url(
             .expect("need non-zero shred-version to join the cluster");
     }
 
+    #[allow(deprecated)]
     let (_all_peers, validators) = discover(
         None, // keypair
         entrypoint_addr.as_ref(),
@@ -335,13 +351,18 @@ fn process_rpc_url(
     let rpc_addrs: Vec<_> = validators
         .iter()
         .filter(|node| {
-            any || all
-                || node
-                    .gossip()
+            any || all || {
+                #[allow(deprecated)]
+                let addrs = node.gossip();
+                addrs
                     .map(|addr| Some(addr) == entrypoint_addr)
                     .unwrap_or_default()
+            }
         })
-        .filter_map(ContactInfo::rpc)
+        .filter_map(
+            #[allow(deprecated)]
+            ContactInfo::rpc,
+        )
         .filter(|addr| socket_addr_space.check(addr))
         .collect();
 

+ 15 - 9
net-utils/src/lib.rs

@@ -79,13 +79,16 @@ pub(crate) const IP_ECHO_SERVER_RESPONSE_LENGTH: usize = HEADER_LENGTH + 23;
     note = "Use `get_public_ip_addr_with_binding` instead"
 )]
 pub fn get_public_ip_addr(ip_echo_server_addr: &SocketAddr) -> Result<IpAddr, String> {
-    let fut = ip_echo_server_request(*ip_echo_server_addr, IpEchoServerMessage::default());
-    let rt = tokio::runtime::Builder::new_current_thread()
-        .enable_all()
-        .build()
-        .map_err(|e| e.to_string())?;
-    let resp = rt.block_on(fut).map_err(|e| e.to_string())?;
-    Ok(resp.address)
+    #[allow(deprecated)]
+    {
+        let fut = ip_echo_server_request(*ip_echo_server_addr, IpEchoServerMessage::default());
+        let rt = tokio::runtime::Builder::new_current_thread()
+            .enable_all()
+            .build()
+            .map_err(|e| e.to_string())?;
+        let resp = rt.block_on(fut).map_err(|e| e.to_string())?;
+        Ok(resp.address)
+    }
 }
 
 /// Determine the public IP address of this machine by asking an ip_echo_server at the given
@@ -461,8 +464,11 @@ pub fn bind_to_with_config_non_blocking(
 )]
 /// binds both a UdpSocket and a TcpListener
 pub fn bind_common(ip_addr: IpAddr, port: u16) -> io::Result<(UdpSocket, TcpListener)> {
-    let config = sockets::SocketConfiguration::default();
-    sockets::bind_common_with_config(ip_addr, port, config)
+    #[allow(deprecated)]
+    {
+        let config = sockets::SocketConfiguration::default();
+        sockets::bind_common_with_config(ip_addr, port, config)
+    }
 }
 
 #[deprecated(

+ 10 - 0
net-utils/src/sockets.rs

@@ -217,9 +217,19 @@ pub fn bind_in_range_with_config(
 }
 
 #[deprecated(since = "3.0.0", note = "Please bind to specific ports instead")]
+#[allow(deprecated)]
 pub fn bind_with_any_port_with_config(
     ip_addr: IpAddr,
     config: SocketConfiguration,
+) -> io::Result<UdpSocket> {
+    _bind_with_any_port_with_config(ip_addr, config)
+}
+
+// this private method works around a cargo bug involving nested deprecations
+// remove it with the above deprecated public method
+fn _bind_with_any_port_with_config(
+    ip_addr: IpAddr,
+    config: SocketConfiguration,
 ) -> io::Result<UdpSocket> {
     let sock = udp_socket_with_config(config)?;
     let addr = SocketAddr::new(ip_addr, 0);

+ 1 - 0
rayon-threadlimit/src/lib.rs

@@ -36,5 +36,6 @@ pub fn get_thread_count() -> usize {
             similar instead"
 )]
 pub fn get_max_thread_count() -> usize {
+    #[allow(deprecated)]
     get_thread_count().saturating_mul(2)
 }

+ 40 - 34
rpc-client/src/nonblocking/rpc_client.rs

@@ -3546,6 +3546,7 @@ impl RpcClient {
         pubkey: &Pubkey,
         config: RpcAccountInfoConfig,
     ) -> RpcResult<Option<Account>> {
+        #[allow(deprecated)]
         let response = self
             .send(
                 RpcRequest::GetAccountInfo,
@@ -3823,26 +3824,29 @@ impl RpcClient {
         pubkeys: &[Pubkey],
         config: RpcAccountInfoConfig,
     ) -> RpcResult<Vec<Option<Account>>> {
-        let config = RpcAccountInfoConfig {
-            commitment: config.commitment.or_else(|| Some(self.commitment())),
-            ..config
-        };
-        let pubkeys: Vec<_> = pubkeys.iter().map(|pubkey| pubkey.to_string()).collect();
-        let response = self
-            .send(RpcRequest::GetMultipleAccounts, json!([pubkeys, config]))
-            .await?;
-        let Response {
-            context,
-            value: accounts,
-        } = serde_json::from_value::<Response<Vec<Option<UiAccount>>>>(response)?;
-        let accounts: Vec<Option<Account>> = accounts
-            .into_iter()
-            .map(|rpc_account| rpc_account.and_then(|a| a.decode()))
-            .collect();
-        Ok(Response {
-            context,
-            value: accounts,
-        })
+        #[allow(deprecated)]
+        {
+            let config = RpcAccountInfoConfig {
+                commitment: config.commitment.or_else(|| Some(self.commitment())),
+                ..config
+            };
+            let pubkeys: Vec<_> = pubkeys.iter().map(|pubkey| pubkey.to_string()).collect();
+            let response = self
+                .send(RpcRequest::GetMultipleAccounts, json!([pubkeys, config]))
+                .await?;
+            let Response {
+                context,
+                value: accounts,
+            } = serde_json::from_value::<Response<Vec<Option<UiAccount>>>>(response)?;
+            let accounts: Vec<Option<Account>> = accounts
+                .into_iter()
+                .map(|rpc_account| rpc_account.and_then(|a| a.decode()))
+                .collect();
+            Ok(Response {
+                context,
+                value: accounts,
+            })
+        }
     }
 
     /// Returns the account information for a list of pubkeys.
@@ -4124,21 +4128,23 @@ impl RpcClient {
         pubkey: &Pubkey,
         mut config: RpcProgramAccountsConfig,
     ) -> ClientResult<Vec<(Pubkey, Account)>> {
-        let commitment = config
-            .account_config
-            .commitment
-            .unwrap_or_else(|| self.commitment());
-        config.account_config.commitment = Some(commitment);
-
-        let accounts = self
-            .send::<OptionalContext<Vec<RpcKeyedAccount>>>(
-                RpcRequest::GetProgramAccounts,
-                json!([pubkey.to_string(), config]),
-            )
-            .await?
-            .parse_value();
         #[allow(deprecated)]
-        parse_keyed_accounts(accounts, RpcRequest::GetProgramAccounts)
+        {
+            let commitment = config
+                .account_config
+                .commitment
+                .unwrap_or_else(|| self.commitment());
+            config.account_config.commitment = Some(commitment);
+
+            let accounts = self
+                .send::<OptionalContext<Vec<RpcKeyedAccount>>>(
+                    RpcRequest::GetProgramAccounts,
+                    json!([pubkey.to_string(), config]),
+                )
+                .await?
+                .parse_value();
+            parse_keyed_accounts(accounts, RpcRequest::GetProgramAccounts)
+        }
     }
 
     /// Returns all accounts owned by the provided program pubkey.