From 72aeaef5f33dd409d7326b710d7c6dafa3f05e00 Mon Sep 17 00:00:00 2001 From: Ali Bektas Date: Fri, 30 Jun 2023 15:46:39 +0200 Subject: [PATCH 1/2] Purge of unwraps --- crates/rust-analyzer/src/handlers/request.rs | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs index b103341f3ca..c34adac5405 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -2039,20 +2039,19 @@ fn to_url(path: VfsPath) -> Option { } fn resource_ops_supported(config: &Config, kind: ResourceOperationKind) -> anyhow::Result<()> { - let ctn = config - .caps() - .workspace - .as_ref() - .unwrap() - .workspace_edit - .as_ref() - .unwrap() - .resource_operations - .as_ref() - .unwrap() - .contains(&kind); + #[rustfmt::skip] + let resops = (|| { + config + .caps() + .workspace + .as_ref()? + .workspace_edit + .as_ref()? + .resource_operations + .as_ref() + })(); - if !ctn { + if resops.is_none() || !resops.unwrap().contains(&kind) { return Err(LspError::new( ErrorCode::RequestFailed as i32, format!( From cfbeb66a6310508dc45bf59b8ce19540b3d4a1be Mon Sep 17 00:00:00 2001 From: Ali Bektas Date: Fri, 30 Jun 2023 16:31:20 +0200 Subject: [PATCH 2/2] Purge of unwrap version 2 --- crates/rust-analyzer/src/handlers/request.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs index c34adac5405..69799a54cb1 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -2051,7 +2051,7 @@ fn resource_ops_supported(config: &Config, kind: ResourceOperationKind) -> anyho .as_ref() })(); - if resops.is_none() || !resops.unwrap().contains(&kind) { + if !matches!(resops, Some(resops) if resops.contains(&kind)) { return Err(LspError::new( ErrorCode::RequestFailed as i32, format!(