about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-04-27 19:53:56 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-04-27 19:53:56 +0200
commit8b056fad450d8bb97997c1bd16aa016a3e1328e7 (patch)
tree6db6f0aac60208b6c86331003e7aa2175ad07107
parente2344e78f36f399b94893f4947c943101b29958b (diff)
downloadrust-8b056fad450d8bb97997c1bd16aa016a3e1328e7.tar.gz
rust-8b056fad450d8bb97997c1bd16aa016a3e1328e7.zip
Simplify
-rw-r--r--crates/rust-analyzer/src/cargo_target_spec.rs34
-rw-r--r--crates/rust-analyzer/src/dispatch.rs36
2 files changed, 30 insertions, 40 deletions
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs
index 35f8f61ef44..1c39e9391af 100644
--- a/crates/rust-analyzer/src/cargo_target_spec.rs
+++ b/crates/rust-analyzer/src/cargo_target_spec.rs
@@ -26,22 +26,16 @@ pub(crate) struct CargoTargetSpec {
 impl CargoTargetSpec {
     pub(crate) fn runnable_args(
         snap: &GlobalStateSnapshot,
-        mut spec: Option<CargoTargetSpec>,
+        spec: Option<CargoTargetSpec>,
         kind: &RunnableKind,
         cfg: &Option<CfgExpr>,
     ) -> Result<(Vec<String>, Vec<String>)> {
         let mut args = Vec::new();
         let mut extra_args = Vec::new();
 
-        let target_required_features =
-            spec.as_mut().map(|spec| mem::take(&mut spec.required_features)).unwrap_or(Vec::new());
-
         match kind {
             RunnableKind::Test { test_id, attr } => {
                 args.push("test".to_string());
-                if let Some(spec) = spec {
-                    spec.push_to(&mut args, kind);
-                }
                 extra_args.push(test_id.to_string());
                 if let TestId::Path(_) = test_id {
                     extra_args.push("--exact".to_string());
@@ -53,17 +47,11 @@ impl CargoTargetSpec {
             }
             RunnableKind::TestMod { path } => {
                 args.push("test".to_string());
-                if let Some(spec) = spec {
-                    spec.push_to(&mut args, kind);
-                }
                 extra_args.push(path.to_string());
                 extra_args.push("--nocapture".to_string());
             }
             RunnableKind::Bench { test_id } => {
                 args.push("bench".to_string());
-                if let Some(spec) = spec {
-                    spec.push_to(&mut args, kind);
-                }
                 extra_args.push(test_id.to_string());
                 if let TestId::Path(_) = test_id {
                     extra_args.push("--exact".to_string());
@@ -73,9 +61,6 @@ impl CargoTargetSpec {
             RunnableKind::DocTest { test_id } => {
                 args.push("test".to_string());
                 args.push("--doc".to_string());
-                if let Some(spec) = spec {
-                    spec.push_to(&mut args, kind);
-                }
                 extra_args.push(test_id.to_string());
                 extra_args.push("--nocapture".to_string());
             }
@@ -85,12 +70,17 @@ impl CargoTargetSpec {
                     _ => "run",
                 };
                 args.push(subcommand.to_string());
-                if let Some(spec) = spec {
-                    spec.push_to(&mut args, kind);
-                }
             }
         }
 
+        let target_required_features = if let Some(mut spec) = spec {
+            let required_features = mem::take(&mut spec.required_features);
+            spec.push_to(&mut args, kind);
+            required_features
+        } else {
+            Vec::new()
+        };
+
         let cargo_config = snap.config.cargo();
         if cargo_config.all_features {
             args.push("--all-features".to_string());
@@ -122,9 +112,9 @@ impl CargoTargetSpec {
         global_state_snapshot: &GlobalStateSnapshot,
         file_id: FileId,
     ) -> Result<Option<CargoTargetSpec>> {
-        let crate_id = match global_state_snapshot.analysis.crate_for(file_id)?.first() {
-            Some(&crate_id) => crate_id,
-            None => return Ok(None),
+        let crate_id = match &*global_state_snapshot.analysis.crate_for(file_id)? {
+            &[crate_id, ..] => crate_id,
+            _ => return Ok(None),
         };
         let (cargo_ws, target) = match global_state_snapshot.cargo_target_for_crate_root(crate_id) {
             Some(it) => it,
diff --git a/crates/rust-analyzer/src/dispatch.rs b/crates/rust-analyzer/src/dispatch.rs
index d770325983a..d208ba16cb9 100644
--- a/crates/rust-analyzer/src/dispatch.rs
+++ b/crates/rust-analyzer/src/dispatch.rs
@@ -39,9 +39,9 @@ impl<'a> RequestDispatcher<'a> {
         f: fn(&mut GlobalState, R::Params) -> Result<R::Result>,
     ) -> Result<&mut Self>
     where
-        R: lsp_types::request::Request + 'static,
-        R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug + 'static,
-        R::Result: Serialize + 'static,
+        R: lsp_types::request::Request,
+        R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug,
+        R::Result: Serialize,
     {
         let (id, params, panic_context) = match self.parse::<R>() {
             Some(it) => it,
@@ -63,8 +63,8 @@ impl<'a> RequestDispatcher<'a> {
     ) -> Result<&mut Self>
     where
         R: lsp_types::request::Request + 'static,
-        R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug + 'static,
-        R::Result: Serialize + 'static,
+        R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug,
+        R::Result: Serialize,
     {
         let (id, params, panic_context) = match self.parse::<R>() {
             Some(it) => it,
@@ -89,8 +89,8 @@ impl<'a> RequestDispatcher<'a> {
     ) -> &mut Self
     where
         R: lsp_types::request::Request + 'static,
-        R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug + 'static,
-        R::Result: Serialize + 'static,
+        R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
+        R::Result: Serialize,
     {
         let (id, params, panic_context) = match self.parse::<R>() {
             Some(it) => it,
@@ -126,11 +126,11 @@ impl<'a> RequestDispatcher<'a> {
 
     fn parse<R>(&mut self) -> Option<(lsp_server::RequestId, R::Params, String)>
     where
-        R: lsp_types::request::Request + 'static,
-        R::Params: DeserializeOwned + fmt::Debug + 'static,
+        R: lsp_types::request::Request,
+        R::Params: DeserializeOwned + fmt::Debug,
     {
         let req = match &self.req {
-            Some(req) if req.method == R::METHOD => self.req.take().unwrap(),
+            Some(req) if req.method == R::METHOD => self.req.take()?,
             _ => return None,
         };
 
@@ -159,9 +159,9 @@ fn thread_result_to_response<R>(
     result: thread::Result<Result<R::Result>>,
 ) -> lsp_server::Response
 where
-    R: lsp_types::request::Request + 'static,
-    R::Params: DeserializeOwned + 'static,
-    R::Result: Serialize + 'static,
+    R: lsp_types::request::Request,
+    R::Params: DeserializeOwned,
+    R::Result: Serialize,
 {
     match result {
         Ok(result) => result_to_response::<R>(id, result),
@@ -188,9 +188,9 @@ fn result_to_response<R>(
     result: Result<R::Result>,
 ) -> lsp_server::Response
 where
-    R: lsp_types::request::Request + 'static,
-    R::Params: DeserializeOwned + 'static,
-    R::Result: Serialize + 'static,
+    R: lsp_types::request::Request,
+    R::Params: DeserializeOwned,
+    R::Result: Serialize,
 {
     match result {
         Ok(resp) => lsp_server::Response::new_ok(id, &resp),
@@ -226,8 +226,8 @@ impl<'a> NotificationDispatcher<'a> {
         f: fn(&mut GlobalState, N::Params) -> Result<()>,
     ) -> Result<&mut Self>
     where
-        N: lsp_types::notification::Notification + 'static,
-        N::Params: DeserializeOwned + Send + 'static,
+        N: lsp_types::notification::Notification,
+        N::Params: DeserializeOwned + Send,
     {
         let not = match self.not.take() {
             Some(it) => it,