Skip to content

Commit 8b056fa

Browse files
committed
Simplify
1 parent e2344e7 commit 8b056fa

File tree

2 files changed

+30
-40
lines changed

2 files changed

+30
-40
lines changed

crates/rust-analyzer/src/cargo_target_spec.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,16 @@ pub(crate) struct CargoTargetSpec {
2626
impl CargoTargetSpec {
2727
pub(crate) fn runnable_args(
2828
snap: &GlobalStateSnapshot,
29-
mut spec: Option<CargoTargetSpec>,
29+
spec: Option<CargoTargetSpec>,
3030
kind: &RunnableKind,
3131
cfg: &Option<CfgExpr>,
3232
) -> Result<(Vec<String>, Vec<String>)> {
3333
let mut args = Vec::new();
3434
let mut extra_args = Vec::new();
3535

36-
let target_required_features =
37-
spec.as_mut().map(|spec| mem::take(&mut spec.required_features)).unwrap_or(Vec::new());
38-
3936
match kind {
4037
RunnableKind::Test { test_id, attr } => {
4138
args.push("test".to_string());
42-
if let Some(spec) = spec {
43-
spec.push_to(&mut args, kind);
44-
}
4539
extra_args.push(test_id.to_string());
4640
if let TestId::Path(_) = test_id {
4741
extra_args.push("--exact".to_string());
@@ -53,17 +47,11 @@ impl CargoTargetSpec {
5347
}
5448
RunnableKind::TestMod { path } => {
5549
args.push("test".to_string());
56-
if let Some(spec) = spec {
57-
spec.push_to(&mut args, kind);
58-
}
5950
extra_args.push(path.to_string());
6051
extra_args.push("--nocapture".to_string());
6152
}
6253
RunnableKind::Bench { test_id } => {
6354
args.push("bench".to_string());
64-
if let Some(spec) = spec {
65-
spec.push_to(&mut args, kind);
66-
}
6755
extra_args.push(test_id.to_string());
6856
if let TestId::Path(_) = test_id {
6957
extra_args.push("--exact".to_string());
@@ -73,9 +61,6 @@ impl CargoTargetSpec {
7361
RunnableKind::DocTest { test_id } => {
7462
args.push("test".to_string());
7563
args.push("--doc".to_string());
76-
if let Some(spec) = spec {
77-
spec.push_to(&mut args, kind);
78-
}
7964
extra_args.push(test_id.to_string());
8065
extra_args.push("--nocapture".to_string());
8166
}
@@ -85,12 +70,17 @@ impl CargoTargetSpec {
8570
_ => "run",
8671
};
8772
args.push(subcommand.to_string());
88-
if let Some(spec) = spec {
89-
spec.push_to(&mut args, kind);
90-
}
9173
}
9274
}
9375

76+
let target_required_features = if let Some(mut spec) = spec {
77+
let required_features = mem::take(&mut spec.required_features);
78+
spec.push_to(&mut args, kind);
79+
required_features
80+
} else {
81+
Vec::new()
82+
};
83+
9484
let cargo_config = snap.config.cargo();
9585
if cargo_config.all_features {
9686
args.push("--all-features".to_string());
@@ -122,9 +112,9 @@ impl CargoTargetSpec {
122112
global_state_snapshot: &GlobalStateSnapshot,
123113
file_id: FileId,
124114
) -> Result<Option<CargoTargetSpec>> {
125-
let crate_id = match global_state_snapshot.analysis.crate_for(file_id)?.first() {
126-
Some(&crate_id) => crate_id,
127-
None => return Ok(None),
115+
let crate_id = match &*global_state_snapshot.analysis.crate_for(file_id)? {
116+
&[crate_id, ..] => crate_id,
117+
_ => return Ok(None),
128118
};
129119
let (cargo_ws, target) = match global_state_snapshot.cargo_target_for_crate_root(crate_id) {
130120
Some(it) => it,

crates/rust-analyzer/src/dispatch.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ impl<'a> RequestDispatcher<'a> {
3939
f: fn(&mut GlobalState, R::Params) -> Result<R::Result>,
4040
) -> Result<&mut Self>
4141
where
42-
R: lsp_types::request::Request + 'static,
43-
R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug + 'static,
44-
R::Result: Serialize + 'static,
42+
R: lsp_types::request::Request,
43+
R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug,
44+
R::Result: Serialize,
4545
{
4646
let (id, params, panic_context) = match self.parse::<R>() {
4747
Some(it) => it,
@@ -63,8 +63,8 @@ impl<'a> RequestDispatcher<'a> {
6363
) -> Result<&mut Self>
6464
where
6565
R: lsp_types::request::Request + 'static,
66-
R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug + 'static,
67-
R::Result: Serialize + 'static,
66+
R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug,
67+
R::Result: Serialize,
6868
{
6969
let (id, params, panic_context) = match self.parse::<R>() {
7070
Some(it) => it,
@@ -89,8 +89,8 @@ impl<'a> RequestDispatcher<'a> {
8989
) -> &mut Self
9090
where
9191
R: lsp_types::request::Request + 'static,
92-
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug + 'static,
93-
R::Result: Serialize + 'static,
92+
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
93+
R::Result: Serialize,
9494
{
9595
let (id, params, panic_context) = match self.parse::<R>() {
9696
Some(it) => it,
@@ -126,11 +126,11 @@ impl<'a> RequestDispatcher<'a> {
126126

127127
fn parse<R>(&mut self) -> Option<(lsp_server::RequestId, R::Params, String)>
128128
where
129-
R: lsp_types::request::Request + 'static,
130-
R::Params: DeserializeOwned + fmt::Debug + 'static,
129+
R: lsp_types::request::Request,
130+
R::Params: DeserializeOwned + fmt::Debug,
131131
{
132132
let req = match &self.req {
133-
Some(req) if req.method == R::METHOD => self.req.take().unwrap(),
133+
Some(req) if req.method == R::METHOD => self.req.take()?,
134134
_ => return None,
135135
};
136136

@@ -159,9 +159,9 @@ fn thread_result_to_response<R>(
159159
result: thread::Result<Result<R::Result>>,
160160
) -> lsp_server::Response
161161
where
162-
R: lsp_types::request::Request + 'static,
163-
R::Params: DeserializeOwned + 'static,
164-
R::Result: Serialize + 'static,
162+
R: lsp_types::request::Request,
163+
R::Params: DeserializeOwned,
164+
R::Result: Serialize,
165165
{
166166
match result {
167167
Ok(result) => result_to_response::<R>(id, result),
@@ -188,9 +188,9 @@ fn result_to_response<R>(
188188
result: Result<R::Result>,
189189
) -> lsp_server::Response
190190
where
191-
R: lsp_types::request::Request + 'static,
192-
R::Params: DeserializeOwned + 'static,
193-
R::Result: Serialize + 'static,
191+
R: lsp_types::request::Request,
192+
R::Params: DeserializeOwned,
193+
R::Result: Serialize,
194194
{
195195
match result {
196196
Ok(resp) => lsp_server::Response::new_ok(id, &resp),
@@ -226,8 +226,8 @@ impl<'a> NotificationDispatcher<'a> {
226226
f: fn(&mut GlobalState, N::Params) -> Result<()>,
227227
) -> Result<&mut Self>
228228
where
229-
N: lsp_types::notification::Notification + 'static,
230-
N::Params: DeserializeOwned + Send + 'static,
229+
N: lsp_types::notification::Notification,
230+
N::Params: DeserializeOwned + Send,
231231
{
232232
let not = match self.not.take() {
233233
Some(it) => it,

0 commit comments

Comments
 (0)