Skip to content

Commit ec3bfaa

Browse files
committed
style: Silence Clippy's complaint on nightly toolchain
Clippy, with the nightly toolchain, complains as follows: error: this `if` statement can be collapsed --> cli/bin/completions.rs:75:17 | 75 | / if let Some((arg_side, value_side)) = word.split_once("=") { 76 | | if let Some(arg) = node.find_arg(arg_side) { 77 | | // if left side of = is arg and it has choices, offer them 78 | | if !arg.choices.is_empty() { ... | 90 | | } | |_________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `-D clippy::collapsible-if` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | 75 ~ if let Some((arg_side, value_side)) = word.split_once("=") 76 ~ && let Some(arg) = node.find_arg(arg_side) { 77 | // if left side of = is arg and it has choices, offer them ... 88 | } 89 ~ } | However, applying the suggested fix leads to compiler errors with the stable toolchain: error[E0658]: `let` expressions in this position are unstable --> cli/bin/completions.rs:75:20 | 75 | if let Some((arg_side, value_side)) = word.split_once("=") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #53667 <rust-lang/rust#53667> for more information error[E0658]: `let` expressions in this position are unstable --> cli/bin/completions.rs:76:24 | 76 | && let Some(arg) = node.find_arg(arg_side) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #53667 <rust-lang/rust#53667> for more information For more information about this error, try `rustc --explain E0658`. error: could not compile `dataplane-cli` (bin "cli" test) due to 2 previous errors This is apparently better supported in beta and nightly, but not in the stable version just yet. Just silence the warning for now. Same happens at a few other locations. We should remove the macros and "collapse" the "if"s once we have switched to Rust v1.88 as stable. Signed-off-by: Quentin Monnet <[email protected]>
1 parent d25d5ba commit ec3bfaa

File tree

11 files changed

+16
-0
lines changed

11 files changed

+16
-0
lines changed

cli/bin/completions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl Completer for CmdCompleter {
7272
// FIXME
7373
if let Some(word) = left.front() {
7474
if word.contains("=") {
75+
#[allow(clippy::collapsible_if)]
7576
if let Some((arg_side, value_side)) = word.split_once("=") {
7677
if let Some(arg) = node.find_arg(arg_side) {
7778
// if left side of = is arg and it has choices, offer them

interface-manager/src/interface/vtep.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ impl Update for Manager<VtepProperties> {
8686
where
8787
Self: 'a,
8888
{
89+
#[allow(clippy::collapsible_if)]
8990
if let InterfaceProperties::Vtep(props) = &observation.properties {
9091
if requirement == props {
9192
return Ok(());

mgmt/src/frr/frrmi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ impl FrrMi {
234234

235235
if let Some(sock) = &mut self.sock {
236236
/* send the request: if sending fails, we may disconnect */
237+
#[allow(clippy::collapsible_if)]
237238
if let Err(e) = send_msg(sock, genid, msg.as_bytes()).await {
238239
if matches!(e, FrrErr::PeerLeft | FrrErr::RxFail(_) | FrrErr::TxFail(_)) {
239240
warn!("Got error: {e}. Disconnecting frrmi...");

mgmt/src/grpc/converter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ pub fn convert_ospf_config_from_grpc(
209209
let mut ospf = Ospf::new(router_id);
210210

211211
// Set VRF name if present
212+
#[allow(clippy::collapsible_if)]
212213
if let Some(vrf_name) = &ospf_config.vrf {
213214
if !vrf_name.is_empty() {
214215
ospf.set_vrf_name(vrf_name.clone());

mgmt/src/processor/gwconfigdb.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl GwConfigDatabase {
4747
self.configs.get_mut(&generation)
4848
}
4949
pub fn unmark_current(&mut self, value: bool) {
50+
#[allow(clippy::collapsible_if)]
5051
if let Some(genid) = &self.current {
5152
if let Some(config) = self.configs.get_mut(genid) {
5253
config.set_applied(value);
@@ -127,6 +128,7 @@ impl GwConfigDatabase {
127128
let previous = last.unwrap_or(ExternalConfig::BLANK_GENID);
128129
info!("Rolling back to config '{}'...", previous);
129130
let mut config = self.get_mut(previous);
131+
#[allow(clippy::collapsible_if)]
130132
if let Some(config) = &mut config {
131133
if let Err(e) = config.apply(frrmi).await {
132134
error!("Fatal: could not roll-back to previous config: {e}");

mgmt/src/processor/proc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ async fn start_grpc_server_unix(
228228
);
229229

230230
// Remove existing socket file if present
231+
#[allow(clippy::collapsible_if)]
231232
if socket_path.exists() {
232233
if let Err(e) = std::fs::remove_file(socket_path) {
233234
error!("Failed to remove existing socket file: {}", e);
@@ -236,6 +237,7 @@ async fn start_grpc_server_unix(
236237
}
237238

238239
// Create parent directory if it doesn't exist
240+
#[allow(clippy::collapsible_if)]
239241
if let Some(parent) = socket_path.parent() {
240242
if !parent.exists() {
241243
if let Err(e) = std::fs::create_dir_all(parent) {
@@ -270,6 +272,7 @@ async fn start_grpc_server_unix(
270272
.await;
271273

272274
// Clean up the socket file after server shutdown
275+
#[allow(clippy::collapsible_if)]
273276
if socket_path.exists() {
274277
if let Err(e) = std::fs::remove_file(socket_path) {
275278
error!("Failed to remove socket file: {}", e);

routing/src/interface.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ impl IfTable {
258258
//////////////////////////////////////////////////////////////////
259259
pub fn detach_vrf_interfaces(&mut self, vrf: &Arc<RwLock<Vrf>>) {
260260
for iface in self.0.values_mut() {
261+
#[allow(clippy::collapsible_if)]
261262
if let Some(if_vrf) = &iface.vrf {
262263
if Arc::ptr_eq(if_vrf, vrf) {
263264
iface.detach();

routing/src/nexthop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ impl NhopStore {
279279
pub(crate) fn del_nhop(&mut self, key: &NhopKey) {
280280
let target = Nhop::new_from_key(key);
281281
let mut remove: bool = false;
282+
#[allow(clippy::collapsible_if)]
282283
if let Some(existing) = self.0.get(&target) {
283284
if Arc::strong_count(existing) == 1 {
284285
remove = true;

routing/src/rmac.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl RmacStore {
4747
/// Delete an rmac entry. The mac address must match (sanity)
4848
pub fn del_rmac(&mut self, vni: Vni, address: IpAddr, mac: Mac) {
4949
let key = (address, vni);
50+
#[allow(clippy::collapsible_if)]
5051
if let Entry::Occupied(o) = self.0.entry(key) {
5152
if o.get().mac == mac {
5253
self.0.remove_entry(&key);
@@ -57,6 +58,7 @@ impl RmacStore {
5758
/// Identical to[`add_rmac`], but getting the entry as param
5859
pub fn del_rmac_entry(&mut self, entry: RmacEntry) {
5960
let key = (entry.address, entry.vni);
61+
#[allow(clippy::collapsible_if)]
6062
if let Entry::Occupied(o) = self.0.entry(key) {
6163
if o.get().mac == entry.mac {
6264
self.0.remove_entry(&key);

routing/src/routingdb.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl VrfTable {
4747
};
4848

4949
/* Forbid VRF addition if one exists with same vni */
50+
#[allow(clippy::collapsible_if)]
5051
if let Some(vni) = vni_checked {
5152
if self.by_vni.contains_key(&vni) {
5253
return Err(RouterError::VniInUse(vni.as_u32()));
@@ -78,6 +79,7 @@ impl VrfTable {
7879
pub fn remove_vrf(&mut self, vrfid: VrfId, iftable: &mut IfTable) -> Result<(), RouterError> {
7980
if let Some(vrf) = self.by_id.remove(&vrfid) {
8081
iftable.detach_vrf_interfaces(&vrf);
82+
#[allow(clippy::collapsible_if)]
8183
if let Ok(vrf) = vrf.read() {
8284
if let Some(vni) = vrf.vni {
8385
self.by_vni.remove(&vni);

routing/src/rpc_adapt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl From<ForwardAction> for FwAction {
4545
impl From<&NextHop> for RouteNhop {
4646
fn from(nh: &NextHop) -> Self {
4747
let mut encap = nh.encap.as_ref().map(Encapsulation::from);
48+
#[allow(clippy::collapsible_if)]
4849
if let Some(Encapsulation::Vxlan(vxlan)) = &mut encap {
4950
if let Some(address) = nh.address {
5051
vxlan.remote = address;

0 commit comments

Comments
 (0)