Skip to content

Commit a5ceb37

Browse files
committed
style: fix clippy warnings
1 parent d6c7d6b commit a5ceb37

File tree

19 files changed

+230
-232
lines changed

19 files changed

+230
-232
lines changed

bindings/jsonnet/src/import.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl ImportResolver for CallbackImportResolver {
6464
self.ctx,
6565
base.as_ptr(),
6666
rel.as_ptr(),
67-
&mut (found_here as *const _),
67+
&mut found_here.cast_const(),
6868
&mut buf,
6969
&mut buf_len,
7070
)
@@ -121,7 +121,7 @@ pub unsafe extern "C" fn jsonnet_import_callback(
121121
cb,
122122
ctx,
123123
out: RefCell::new(HashMap::new()),
124-
})
124+
});
125125
}
126126

127127
/// # Safety

bindings/jsonnet/src/lib.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ pub extern "C" fn jsonnet_make() -> *mut VM {
8686
let state = State::default();
8787
state.settings_mut().import_resolver = tb!(FileImportResolver::default());
8888
state.settings_mut().context_initializer = tb!(jrsonnet_stdlib::ContextInitializer::new(
89-
state.clone(),
9089
PathResolver::new_cwd_fallback(),
9190
));
9291
Box::into_raw(Box::new(VM {
@@ -107,7 +106,7 @@ pub extern "C" fn jsonnet_destroy(vm: Box<VM>) {
107106
/// Set the maximum stack depth.
108107
#[no_mangle]
109108
pub extern "C" fn jsonnet_max_stack(_vm: &VM, v: c_uint) {
110-
set_stack_depth_limit(v as usize)
109+
set_stack_depth_limit(v as usize);
111110
}
112111

113112
/// Set the number of objects required before a garbage collection cycle is allowed.
@@ -175,15 +174,15 @@ pub extern "C" fn jsonnet_json_destroy(_vm: &VM, v: Box<Val>) {
175174
#[no_mangle]
176175
pub extern "C" fn jsonnet_max_trace(vm: &mut VM, v: c_uint) {
177176
if let Some(format) = vm.trace_format.as_any_mut().downcast_mut::<CompactFormat>() {
178-
format.max_trace = v as usize
177+
format.max_trace = v as usize;
179178
} else {
180179
panic!("max_trace is not supported by current tracing format")
181180
}
182181
}
183182

184183
/// Evaluate a file containing Jsonnet code, return a JSON string.
185184
///
186-
/// The returned string should be cleaned up with jsonnet_realloc.
185+
/// The returned string should be cleaned up with `jsonnet_realloc`.
187186
///
188187
/// # Safety
189188
///
@@ -216,7 +215,7 @@ pub unsafe extern "C" fn jsonnet_evaluate_file(
216215

217216
/// Evaluate a string containing Jsonnet code, return a JSON string.
218217
///
219-
/// The returned string should be cleaned up with jsonnet_realloc.
218+
/// The returned string should be cleaned up with `jsonnet_realloc`.
220219
///
221220
/// # Safety
222221
///
@@ -359,7 +358,7 @@ fn stream_to_raw(multi: Vec<IStr>) -> *const c_char {
359358
out.push(0);
360359
let v = out.as_ptr();
361360
std::mem::forget(out);
362-
v as *const c_char
361+
v.cast::<c_char>()
363362
}
364363

365364
/// # Safety

bindings/jsonnet/src/val_extract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub extern "C" fn jsonnet_json_extract_string(_vm: &VM, v: &Val) -> *mut c_char
2626
pub extern "C" fn jsonnet_json_extract_number(_vm: &VM, v: &Val, out: &mut c_double) -> c_int {
2727
match v {
2828
Val::Num(n) => {
29-
*out = *n;
29+
*out = n.get();
3030
1
3131
}
3232
_ => 0,

bindings/jsonnet/src/val_make.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use std::{
55
os::raw::{c_char, c_double, c_int},
66
};
77

8-
use jrsonnet_evaluator::{val::ArrValue, ObjValue, Val};
8+
use jrsonnet_evaluator::{
9+
val::{ArrValue, NumValue},
10+
ObjValue, Val,
11+
};
912

1013
use crate::VM;
1114

@@ -24,7 +27,9 @@ pub unsafe extern "C" fn jsonnet_json_make_string(_vm: &VM, val: *const c_char)
2427
/// Convert the given double to a `JsonnetJsonValue`.
2528
#[no_mangle]
2629
pub extern "C" fn jsonnet_json_make_number(_vm: &VM, v: c_double) -> *mut Val {
27-
Box::into_raw(Box::new(Val::Num(v)))
30+
Box::into_raw(Box::new(Val::Num(
31+
NumValue::new(v).expect("jsonnet numbers are finite"),
32+
)))
2833
}
2934

3035
/// Convert the given `bool` (`1` or `0`) to a `JsonnetJsonValue`.

bindings/jsonnet/src/val_modify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::VM;
1212
///
1313
/// # Safety
1414
///
15-
/// `arr` should be a pointer to array value allocated by make_array, or returned by other library call
15+
/// `arr` should be a pointer to array value allocated by `make_array`, or returned by other library call
1616
/// `val` should be a pointer to value allocated using this library
1717
#[no_mangle]
1818
pub unsafe extern "C" fn jsonnet_json_array_append(_vm: &VM, arr: &mut Val, val: &Val) {

bindings/jsonnet/src/vars_tlas.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub unsafe extern "C" fn jsonnet_ext_var(vm: &VM, name: *const c_char, value: *c
2727
.add_ext_str(
2828
name.to_str().expect("name is not utf-8").into(),
2929
value.to_str().expect("value is not utf-8").into(),
30-
)
30+
);
3131
}
3232

3333
/// Binds a Jsonnet external variable to the given code.
@@ -51,7 +51,7 @@ pub unsafe extern "C" fn jsonnet_ext_code(vm: &VM, name: *const c_char, code: *c
5151
name.to_str().expect("name is not utf-8"),
5252
code.to_str().expect("code is not utf-8"),
5353
)
54-
.expect("can't parse ext code")
54+
.expect("can't parse ext code");
5555
}
5656

5757
/// Binds a top-level string argument for a top-level parameter.

cmds/jrsonnet-fmt/src/children.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn trivia_before(node: SyntaxNode, end: Option<&SyntaxElement>) -> ChildTriv
2828
TS![, ;].contains(item.kind()),
2929
"silently eaten token: {:?}",
3030
item.kind()
31-
)
31+
);
3232
}
3333
}
3434
out
@@ -48,13 +48,13 @@ pub fn trivia_after(node: SyntaxNode, start: Option<&SyntaxElement>) -> ChildTri
4848
if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {
4949
out.push(Ok(trivia));
5050
} else if CustomError::can_cast(item.kind()) {
51-
out.push(Err(item.to_string()))
51+
out.push(Err(item.to_string()));
5252
} else {
5353
assert!(
5454
TS![, ;].contains(item.kind()),
5555
"silently eaten token: {:?}",
5656
item.kind()
57-
)
57+
);
5858
}
5959
}
6060
out
@@ -115,11 +115,7 @@ fn count_newlines_after(tt: &ChildTrivia) -> usize {
115115
TriviaKind::Whitespace => {
116116
nl_count += t.text().bytes().filter(|b| *b == b'\n').count();
117117
}
118-
TriviaKind::SingleLineHashComment => {
119-
nl_count += 1;
120-
break;
121-
}
122-
TriviaKind::SingleLineSlashComment => {
118+
TriviaKind::SingleLineHashComment | TriviaKind::SingleLineSlashComment => {
123119
nl_count += 1;
124120
break;
125121
}
@@ -163,7 +159,7 @@ pub fn children<T: AstNode + Debug>(
163159
inline_trivia: Vec::new(),
164160
});
165161
if let Some(last_child) = last_child {
166-
out.push(last_child)
162+
out.push(last_child);
167163
}
168164
had_some = true;
169165
started_next = false;
@@ -188,7 +184,7 @@ pub fn children<T: AstNode + Debug>(
188184
}
189185
had_some = true;
190186
} else if CustomError::can_cast(item.kind()) {
191-
next.push(Err(item.to_string()))
187+
next.push(Err(item.to_string()));
192188
} else if loose {
193189
if had_some {
194190
break;
@@ -199,7 +195,7 @@ pub fn children<T: AstNode + Debug>(
199195
TS![, ;].contains(item.kind()),
200196
"silently eaten token: {:?}",
201197
item.kind()
202-
)
198+
);
203199
}
204200
}
205201

cmds/jrsonnet-fmt/src/comments.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::string::String;
2+
13
use dprint_core::formatting::PrintItems;
24
use jrsonnet_rowan_parser::{nodes::TriviaKind, AstToken};
35

@@ -12,6 +14,7 @@ pub enum CommentLocation {
1214
EndOfItems,
1315
}
1416

17+
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
1518
pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut PrintItems) {
1619
for c in comments {
1720
let Ok(c) = c else {
@@ -62,14 +65,14 @@ pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut P
6265
}
6366
})
6467
.collect::<Vec<_>>();
65-
while lines.last().map(|l| l.is_empty()).unwrap_or(false) {
68+
while lines.last().is_some_and(String::is_empty) {
6669
lines.pop();
6770
}
6871
if lines.len() == 1 && !doc {
6972
if matches!(loc, CommentLocation::ItemInline) {
7073
p!(out, str(" "));
7174
}
72-
p!(out, str("/* ") string(lines[0].trim().to_string()) str(" */") nl)
75+
p!(out, str("/* ") string(lines[0].trim().to_string()) str(" */") nl);
7376
} else if !lines.is_empty() {
7477
fn common_ws_prefix<'a>(a: &'a str, b: &str) -> &'a str {
7578
let offset = a
@@ -95,7 +98,7 @@ pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut P
9598
}
9699
for line in lines
97100
.iter_mut()
98-
.skip(if immediate_start { 1 } else { 0 })
101+
.skip(usize::from(immediate_start))
99102
.filter(|l| !l.is_empty())
100103
{
101104
*line = line
@@ -127,13 +130,13 @@ pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut P
127130
}
128131
line = new_line.to_string();
129132
}
130-
p!(out, string(line.to_string()) nl)
133+
p!(out, string(line.to_string()) nl);
131134
}
132135
}
133136
if doc {
134137
p!(out, str(" "));
135138
}
136-
p!(out, str("*/") nl)
139+
p!(out, str("*/") nl);
137140
}
138141
}
139142
// TODO: Keep common padding for multiple continous lines of single-line comments
@@ -154,20 +157,20 @@ pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut P
154157
// ```
155158
TriviaKind::SingleLineHashComment => {
156159
if matches!(loc, CommentLocation::ItemInline) {
157-
p!(out, str(" "))
160+
p!(out, str(" "));
158161
}
159162
p!(out, str("# ") string(c.text().strip_prefix('#').expect("hash comment starts with #").trim().to_string()));
160163
if !matches!(loc, CommentLocation::ItemInline) {
161-
p!(out, nl)
164+
p!(out, nl);
162165
}
163166
}
164167
TriviaKind::SingleLineSlashComment => {
165168
if matches!(loc, CommentLocation::ItemInline) {
166-
p!(out, str(" "))
169+
p!(out, str(" "));
167170
}
168171
p!(out, str("// ") string(c.text().strip_prefix("//").expect("comment starts with //").trim().to_string()));
169172
if !matches!(loc, CommentLocation::ItemInline) {
170-
p!(out, nl)
173+
p!(out, nl);
171174
}
172175
}
173176
// Garbage in - garbage out

0 commit comments

Comments
 (0)