Skip to content

Commit d276183

Browse files
authored
Fix remaining clippy issues with --all-targets (#1113)
Branched from #1112 Progress towards #1104
2 parents c97520f + c536b0f commit d276183

File tree

33 files changed

+226
-240
lines changed

33 files changed

+226
-240
lines changed

crates/amalthea/tests/client/dummy_frontend.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ use crossbeam::channel::Sender;
2727
use super::control;
2828
use super::shell;
2929

30-
static AMALTHEA_FRONTEND: OnceLock<
31-
Arc<Mutex<(DummyFrontend, Sender<CommEvent>, Sender<IOPubMessage>)>>,
32-
> = OnceLock::new();
30+
type FrontendState = (DummyFrontend, Sender<CommEvent>, Sender<IOPubMessage>);
31+
32+
static AMALTHEA_FRONTEND: OnceLock<Arc<Mutex<FrontendState>>> = OnceLock::new();
3333

3434
/// Wrapper around `DummyFrontend` that checks sockets are empty on drop
3535
pub struct DummyAmaltheaFrontend {
3636
pub comm_event_tx: Sender<CommEvent>,
3737
pub iopub_tx: Sender<IOPubMessage>,
38-
guard: MutexGuard<'static, (DummyFrontend, Sender<CommEvent>, Sender<IOPubMessage>)>,
38+
guard: MutexGuard<'static, FrontendState>,
3939
}
4040

4141
impl DummyAmaltheaFrontend {
@@ -50,12 +50,11 @@ impl DummyAmaltheaFrontend {
5050
}
5151
}
5252

53-
fn get_frontend(
54-
) -> &'static Arc<Mutex<(DummyFrontend, Sender<CommEvent>, Sender<IOPubMessage>)>> {
53+
fn get_frontend() -> &'static Arc<Mutex<FrontendState>> {
5554
AMALTHEA_FRONTEND.get_or_init(|| Arc::new(Mutex::new(DummyAmaltheaFrontend::init())))
5655
}
5756

58-
fn init() -> (DummyFrontend, Sender<CommEvent>, Sender<IOPubMessage>) {
57+
fn init() -> FrontendState {
5958
let connection = DummyConnection::new();
6059
let (connection_file, registration_file) = connection.get_connection_files();
6160

crates/ark/src/connections/r_connection.rs

Lines changed: 79 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -104,73 +104,69 @@ impl RConnection {
104104
match message {
105105
ConnectionsBackendRequest::ListObjects(ListObjectsParams { path }) => {
106106
let tables = r_task(|| -> Result<_, anyhow::Error> {
107-
unsafe {
108-
let mut call = RFunction::from(".ps.connection_list_objects");
109-
call.add(RObject::from(self.comm.comm_id.clone()));
110-
for obj in path {
111-
call.param(obj.kind.as_str(), obj.name);
112-
}
113-
// returns a data.frame with columns name and type
114-
let tables = call.call()?;
115-
116-
let names = RFunction::from("[[")
117-
.add(tables.clone())
118-
.add(RObject::from("name"))
119-
.call()?;
120-
121-
let types = RFunction::from("[[")
122-
.add(tables)
123-
.add(RObject::from("type"))
124-
.call()?;
125-
126-
let resulting = RObject::to::<Vec<String>>(names)?
127-
.iter()
128-
.zip(RObject::to::<Vec<String>>(types)?.iter())
129-
.map(|(name, kind)| ObjectSchema {
130-
name: name.clone(),
131-
kind: kind.clone(),
132-
has_children: None,
133-
})
134-
.collect::<Vec<_>>();
135-
136-
Ok(resulting)
107+
let mut call = RFunction::from(".ps.connection_list_objects");
108+
call.add(RObject::from(self.comm.comm_id.clone()));
109+
for obj in path {
110+
call.param(obj.kind.as_str(), obj.name);
137111
}
112+
// returns a data.frame with columns name and type
113+
let tables = call.call()?;
114+
115+
let names = RFunction::from("[[")
116+
.add(tables.clone())
117+
.add(RObject::from("name"))
118+
.call()?;
119+
120+
let types = RFunction::from("[[")
121+
.add(tables)
122+
.add(RObject::from("type"))
123+
.call()?;
124+
125+
let resulting = RObject::to::<Vec<String>>(names)?
126+
.iter()
127+
.zip(RObject::to::<Vec<String>>(types)?.iter())
128+
.map(|(name, kind)| ObjectSchema {
129+
name: name.clone(),
130+
kind: kind.clone(),
131+
has_children: None,
132+
})
133+
.collect::<Vec<_>>();
134+
135+
Ok(resulting)
138136
})?;
139137

140138
Ok(ConnectionsBackendReply::ListObjectsReply(tables))
141139
},
142140
ConnectionsBackendRequest::ListFields(ListFieldsParams { path }) => {
143141
let fields = r_task(|| -> Result<_, anyhow::Error> {
144-
unsafe {
145-
let mut call = RFunction::from(".ps.connection_list_fields");
146-
call.add(RObject::from(self.comm.comm_id.clone()));
147-
for obj in path {
148-
call.param(obj.kind.as_str(), obj.name);
149-
}
150-
let fields = call.call()?;
151-
152-
// for now we only need the name column
153-
let names = RFunction::from("[[")
154-
.add(fields.clone())
155-
.add(RObject::from("name"))
156-
.call()?;
157-
158-
let dtypes = RFunction::from("[[")
159-
.add(fields)
160-
.add(RObject::from("type"))
161-
.call()?;
162-
163-
let resulting = RObject::to::<Vec<String>>(names)?
164-
.iter()
165-
.zip(RObject::to::<Vec<String>>(dtypes)?.iter())
166-
.map(|(name, dtype)| FieldSchema {
167-
name: name.clone(),
168-
dtype: dtype.clone(),
169-
})
170-
.collect::<Vec<_>>();
171-
172-
Ok(resulting)
142+
let mut call = RFunction::from(".ps.connection_list_fields");
143+
call.add(RObject::from(self.comm.comm_id.clone()));
144+
for obj in path {
145+
call.param(obj.kind.as_str(), obj.name);
173146
}
147+
let fields = call.call()?;
148+
149+
// for now we only need the name column
150+
let names = RFunction::from("[[")
151+
.add(fields.clone())
152+
.add(RObject::from("name"))
153+
.call()?;
154+
155+
let dtypes = RFunction::from("[[")
156+
.add(fields)
157+
.add(RObject::from("type"))
158+
.call()?;
159+
160+
let resulting = RObject::to::<Vec<String>>(names)?
161+
.iter()
162+
.zip(RObject::to::<Vec<String>>(dtypes)?.iter())
163+
.map(|(name, dtype)| FieldSchema {
164+
name: name.clone(),
165+
dtype: dtype.clone(),
166+
})
167+
.collect::<Vec<_>>();
168+
169+
Ok(resulting)
174170
})?;
175171

176172
Ok(ConnectionsBackendReply::ListFieldsReply(fields))
@@ -191,38 +187,34 @@ impl RConnection {
191187
ConnectionsBackendRequest::GetIcon(GetIconParams { path }) => {
192188
// Calls back into R to get the icon.
193189
let icon_path = r_task(|| -> Result<_, anyhow::Error> {
194-
unsafe {
195-
let mut call = RFunction::from(".ps.connection_icon");
196-
call.add(RObject::from(self.comm.comm_id.clone()));
197-
for obj in path {
198-
call.param(obj.kind.as_str(), obj.name);
199-
}
200-
201-
let icon = call.call()?;
202-
203-
if r_is_null(*icon) {
204-
// we'd rather use the option type but couldn't find a way to autogenerate RPC optionals
205-
Ok("".to_string())
206-
} else {
207-
Ok(RObject::to::<String>(icon)?)
208-
}
190+
let mut call = RFunction::from(".ps.connection_icon");
191+
call.add(RObject::from(self.comm.comm_id.clone()));
192+
for obj in path {
193+
call.param(obj.kind.as_str(), obj.name);
194+
}
195+
196+
let icon = call.call()?;
197+
198+
if r_is_null(*icon) {
199+
// we'd rather use the option type but couldn't find a way to autogenerate RPC optionals
200+
Ok("".to_string())
201+
} else {
202+
Ok(RObject::to::<String>(icon)?)
209203
}
210204
})?;
211205
Ok(ConnectionsBackendReply::GetIconReply(icon_path))
212206
},
213207
ConnectionsBackendRequest::ContainsData(ContainsDataParams { path }) => {
214208
// Calls back into R to check if the object contains data.
215209
let contains_data = r_task(|| -> Result<_, anyhow::Error> {
216-
unsafe {
217-
let mut contains_data_call: RFunction =
218-
RFunction::from(".ps.connection_contains_data");
219-
contains_data_call.add(RObject::from(self.comm.comm_id.clone()));
220-
for obj in path {
221-
contains_data_call.param(obj.kind.as_str(), obj.name);
222-
}
223-
let contains_data = contains_data_call.call()?;
224-
Ok(RObject::to::<bool>(contains_data)?)
210+
let mut contains_data_call: RFunction =
211+
RFunction::from(".ps.connection_contains_data");
212+
contains_data_call.add(RObject::from(self.comm.comm_id.clone()));
213+
for obj in path {
214+
contains_data_call.param(obj.kind.as_str(), obj.name);
225215
}
216+
let contains_data = contains_data_call.call()?;
217+
Ok(RObject::to::<bool>(contains_data)?)
226218
})?;
227219
Ok(ConnectionsBackendReply::ContainsDataReply(contains_data))
228220
},
@@ -255,12 +247,10 @@ impl RConnection {
255247
fn disconnect(&self) -> std::result::Result<bool, anyhow::Error> {
256248
// Execute database side disconnect method.
257249
r_task(|| -> Result<bool, anyhow::Error> {
258-
unsafe {
259-
let mut call = RFunction::from(".ps.connection_close");
260-
call.add(RObject::from(self.comm.comm_id.clone()));
261-
let closed = call.call()?;
262-
Ok(RObject::to::<bool>(closed)?)
263-
}
250+
let mut call = RFunction::from(".ps.connection_close");
251+
call.add(RObject::from(self.comm.comm_id.clone()));
252+
let closed = call.call()?;
253+
Ok(RObject::to::<bool>(closed)?)
264254
})
265255
}
266256

crates/ark/src/console/console_repl.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ impl Console {
10031003
}
10041004
}
10051005
if let Ok(req) = kernel_request_rx.try_recv() {
1006-
self.handle_kernel_request(req, &info);
1006+
self.handle_kernel_request(req, info);
10071007
continue;
10081008
}
10091009
}
@@ -2345,13 +2345,11 @@ impl Console {
23452345

23462346
/// Converts a data frame to HTML
23472347
fn to_html(frame: SEXP) -> Result<String> {
2348-
unsafe {
2349-
let result = RFunction::from(".ps.format.toHtml")
2350-
.add(frame)
2351-
.call()?
2352-
.to::<String>()?;
2353-
Ok(result)
2354-
}
2348+
let result = RFunction::from(".ps.format.toHtml")
2349+
.add(frame)
2350+
.call()?
2351+
.to::<String>()?;
2352+
Ok(result)
23552353
}
23562354

23572355
// Inputs generated by `ReadConsole` for the LSP

crates/ark/src/dap/dap_state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ mod tests {
790790

791791
dap.did_change_document(&uri);
792792

793-
assert!(dap.breakpoints.get(&uri).is_none());
793+
assert!(!dap.breakpoints.contains_key(&uri));
794794

795795
let event1 = rx.try_recv().unwrap();
796796
let event2 = rx.try_recv().unwrap();
@@ -848,8 +848,8 @@ mod tests {
848848

849849
dap.did_change_document(&uri1);
850850

851-
assert!(dap.breakpoints.get(&uri1).is_none());
852-
assert!(dap.breakpoints.get(&uri2).is_some());
851+
assert!(!dap.breakpoints.contains_key(&uri1));
852+
assert!(dap.breakpoints.contains_key(&uri2));
853853

854854
let event = rx.try_recv().unwrap();
855855
assert!(matches!(event, DapBackendEvent::BreakpointState {
@@ -897,6 +897,6 @@ mod tests {
897897
dap.did_change_document(&uri);
898898

899899
// Breakpoints should still be removed
900-
assert!(dap.breakpoints.get(&uri).is_none());
900+
assert!(!dap.breakpoints.contains_key(&uri));
901901
}
902902
}

crates/ark/src/help/r_help.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl RHelp {
235235
let topic = HelpTopic::parse(topic);
236236

237237
let found = match topic {
238-
HelpTopic::Simple(symbol) => r_task(|| unsafe {
238+
HelpTopic::Simple(symbol) => r_task(|| {
239239
// Try evaluating the help handler first and then fall back to
240240
// the default help topic display function.
241241

crates/ark/src/help_proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ async fn preview_rd(params: web::Query<PreviewRdParams>) -> HttpResponse {
240240
return HttpResponse::BadGateway().finish();
241241
}
242242

243-
let content = r_task(|| unsafe {
243+
let content = r_task(|| {
244244
RFunction::from(".ps.Rd2HTML")
245245
.param("rd_file", file)
246246
.call()

crates/ark/src/lsp/completions/sources/composite/call.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,11 @@ fn completions_from_session_arguments(
211211
return Ok(Some(completions));
212212
}
213213

214-
let strings = unsafe {
215-
RFunction::from(".ps.completions.formalNames")
216-
.add(r_callable)
217-
.add(object)
218-
.call()?
219-
.to::<Vec<String>>()?
220-
};
214+
let strings = RFunction::from(".ps.completions.formalNames")
215+
.add(r_callable)
216+
.add(object)
217+
.call()?
218+
.to::<Vec<String>>()?;
221219

222220
// Return the names of these formals.
223221
for string in strings.iter() {

crates/ark/src/lsp/completions/sources/unique/comment.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@ fn completions_from_comment(
6464

6565
// TODO: cache these?
6666
// TODO: use an indexer to build the tag list?
67-
let tags = unsafe {
68-
RFunction::new("base", "system.file")
69-
.param("package", "roxygen2")
70-
.add("roxygen2-tags.yml")
71-
.call()?
72-
.to::<String>()?
73-
};
67+
let tags = RFunction::new("base", "system.file")
68+
.param("package", "roxygen2")
69+
.add("roxygen2-tags.yml")
70+
.call()?
71+
.to::<String>()?;
7472

7573
if tags.is_empty() {
7674
return Ok(Some(completions));

crates/ark/src/lsp/completions/sources/unique/namespace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn completions_from_namespace(
9494
list_namespace_symbols(*namespace)
9595
};
9696

97-
let strings = unsafe { symbols.to::<Vec<String>>()? };
97+
let strings = symbols.to::<Vec<String>>()?;
9898

9999
for string in strings.iter() {
100100
let item = unsafe {

crates/ark/src/lsp/inputs/package.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,14 @@ mod tests {
181181

182182
#[test]
183183
fn exported_symbols_are_sorted_and_unique() {
184-
let mut ns = Namespace::default();
185-
ns.exports = vec!["b".to_string(), "a".to_string(), "a".to_string()];
184+
let ns = Namespace {
185+
exports: vec!["b".to_string(), "a".to_string(), "a".to_string()],
186+
..Default::default()
187+
};
186188

187-
let mut index = Index::default();
188-
index.names = vec!["c".to_string(), "a".to_string(), "a".to_string()];
189+
let index = Index {
190+
names: vec!["c".to_string(), "a".to_string(), "a".to_string()],
191+
};
189192

190193
let pkg = new_package("foo", ns, index);
191194
assert_eq!(pkg.exported_symbols, vec!["a", "b", "c"]);

0 commit comments

Comments
 (0)