Skip to content

Commit 2f2912b

Browse files
committed
rust - satiate clippy
1 parent 7e72315 commit 2f2912b

File tree

8 files changed

+53
-55
lines changed

8 files changed

+53
-55
lines changed

examples/rust/ex1-volume/src/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,20 @@ fn example_1(options: opt::Opt) -> libceed::Result<()> {
4646
quiet,
4747
gallery,
4848
} = options;
49-
assert!(dim >= 1 && dim <= 3);
49+
assert!((1..=3).contains(&dim));
5050
assert!(mesh_degree >= 1);
5151
assert!(solution_degree >= 1);
5252
assert!(num_qpts >= 1);
5353
let ncomp_x = dim;
54-
let problem_size: i64;
55-
if problem_size_requested < 0 {
56-
problem_size = if test { 8 * 16 } else { 256 * 1024 };
54+
let problem_size: i64 = if problem_size_requested < 0 {
55+
if test {
56+
8 * 16
57+
} else {
58+
256 * 1024
59+
}
5760
} else {
58-
problem_size = problem_size_requested;
59-
}
61+
problem_size_requested
62+
};
6063

6164
// Summary output
6265
if !quiet {
@@ -102,7 +105,7 @@ fn example_1(options: opt::Opt) -> libceed::Result<()> {
102105
if dim > 2 {
103106
print!(", nz = {}", num_xyz[2]);
104107
}
105-
print!("\n");
108+
println!();
106109
}
107110

108111
// Build ElemRestriction objects describing the mesh and solution discrete

examples/rust/ex2-surface/src/main.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,20 @@ fn example_2(options: opt::Opt) -> libceed::Result<()> {
4747
quiet,
4848
gallery,
4949
} = options;
50-
assert!(dim >= 1 && dim <= 3);
50+
assert!((0..=3).contains(&dim));
5151
assert!(mesh_degree >= 1);
5252
assert!(solution_degree >= 1);
5353
assert!(num_qpts >= 1);
5454
let ncomp_x = dim;
55-
let problem_size: i64;
56-
if problem_size_requested < 0 {
57-
problem_size = if test {
55+
let problem_size: i64 = if problem_size_requested < 0 {
56+
if test {
5857
16 * 16 * (dim * dim) as i64
5958
} else {
6059
256 * 1024
61-
};
60+
}
6261
} else {
63-
problem_size = problem_size_requested;
64-
}
62+
problem_size_requested
63+
};
6564

6665
// Summary output
6766
if !quiet {
@@ -107,7 +106,7 @@ fn example_2(options: opt::Opt) -> libceed::Result<()> {
107106
if dim > 2 {
108107
print!(", nz = {}", num_xyz[2]);
109108
}
110-
print!("\n");
109+
println!();
111110
}
112111

113112
// Build ElemRestriction objects describing the mesh and solution discrete

examples/rust/ex3-vector-volume/src/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,20 @@ fn example_3(options: opt::Opt) -> libceed::Result<()> {
4747
quiet,
4848
gallery,
4949
} = options;
50-
assert!(dim >= 1 && dim <= 3);
50+
assert!((0..=3).contains(&dim));
5151
assert!(mesh_degree >= 1);
5252
assert!(solution_degree >= 1);
5353
assert!(num_qpts >= 1);
5454
let ncomp_x = dim;
55-
let problem_size: i64;
56-
if problem_size_requested < 0 {
57-
problem_size = if test { 8 * 16 } else { 256 * 1024 };
55+
let problem_size: i64 = if problem_size_requested < 0 {
56+
if test {
57+
8 * 16
58+
} else {
59+
256 * 1024
60+
}
5861
} else {
59-
problem_size = problem_size_requested;
60-
}
62+
problem_size_requested
63+
};
6164
let ncomp_u = 3;
6265

6366
// Summary output
@@ -104,7 +107,7 @@ fn example_3(options: opt::Opt) -> libceed::Result<()> {
104107
if dim > 2 {
105108
print!(", nz = {}", num_xyz[2]);
106109
}
107-
print!("\n");
110+
println!();
108111
}
109112

110113
// Build ElemRestriction objects describing the mesh and solution discrete

examples/rust/ex4-vector-surface/src/main.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,20 @@ fn example_4(options: opt::Opt) -> libceed::Result<()> {
4848
quiet,
4949
gallery,
5050
} = options;
51-
assert!(dim >= 1 && dim <= 3);
51+
assert!((0..=3).contains(&dim));
5252
assert!(mesh_degree >= 1);
5353
assert!(solution_degree >= 1);
5454
assert!(num_qpts >= 1);
5555
let ncomp_x = dim;
56-
let problem_size: i64;
57-
if problem_size_requested < 0 {
58-
problem_size = if test {
56+
let problem_size: i64 = if problem_size_requested < 0 {
57+
if test {
5958
16 * 16 * (dim * dim) as i64
6059
} else {
6160
256 * 1024
62-
};
61+
}
6362
} else {
64-
problem_size = problem_size_requested;
65-
}
63+
problem_size_requested
64+
};
6665
let ncomp_u = 3;
6766

6867
// Summary output
@@ -109,7 +108,7 @@ fn example_4(options: opt::Opt) -> libceed::Result<()> {
109108
if dim > 2 {
110109
print!(", nz = {}", num_xyz[2]);
111110
}
112-
print!("\n");
111+
println!();
113112
}
114113

115114
// Build ElemRestriction objects describing the mesh and solution discrete

rust/libceed/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl Ceed {
309309

310310
// Call to libCEED
311311
let mut ptr = std::ptr::null_mut();
312-
let mut ierr = unsafe { bind_ceed::CeedInit(c_resource.as_ptr() as *const i8, &mut ptr) };
312+
let mut ierr = unsafe { bind_ceed::CeedInit(c_resource.as_ptr(), &mut ptr) };
313313
if ierr != 0 {
314314
panic!("Error initializing backend resource: {}", resource)
315315
}

rust/libceed/src/operator.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'a> OperatorField<'a> {
7575
///
7676
/// // Operator field arguments
7777
/// let ne = 3;
78-
/// let q = 4 as usize;
78+
/// let q = 4_usize;
7979
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
8080
/// for i in 0..ne {
8181
/// ind[2 * i + 0] = i as i32;
@@ -122,7 +122,7 @@ impl<'a> OperatorField<'a> {
122122
///
123123
/// // Operator field arguments
124124
/// let ne = 3;
125-
/// let q = 4 as usize;
125+
/// let q = 4_usize;
126126
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
127127
/// for i in 0..ne {
128128
/// ind[2 * i + 0] = i as i32;
@@ -194,7 +194,7 @@ impl<'a> OperatorField<'a> {
194194
///
195195
/// // Operator field arguments
196196
/// let ne = 3;
197-
/// let q = 4 as usize;
197+
/// let q = 4_usize;
198198
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
199199
/// for i in 0..ne {
200200
/// ind[2 * i + 0] = i as i32;
@@ -256,7 +256,7 @@ impl<'a> OperatorField<'a> {
256256
///
257257
/// // Operator field arguments
258258
/// let ne = 3;
259-
/// let q = 4 as usize;
259+
/// let q = 4_usize;
260260
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
261261
/// for i in 0..ne {
262262
/// ind[2 * i + 0] = i as i32;
@@ -354,7 +354,7 @@ impl<'a> fmt::Display for OperatorCore<'a> {
354354
///
355355
/// // Operator field arguments
356356
/// let ne = 3;
357-
/// let q = 4 as usize;
357+
/// let q = 4_usize;
358358
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
359359
/// for i in 0..ne {
360360
/// ind[2 * i + 0] = i as i32;
@@ -393,7 +393,7 @@ impl<'a> fmt::Display for Operator<'a> {
393393
///
394394
/// // Sub operator field arguments
395395
/// let ne = 3;
396-
/// let q = 4 as usize;
396+
/// let q = 4_usize;
397397
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
398398
/// for i in 0..ne {
399399
/// ind[2 * i + 0] = i as i32;
@@ -585,7 +585,7 @@ impl<'a> Operator<'a> {
585585
///
586586
/// // Operator field arguments
587587
/// let ne = 3;
588-
/// let q = 4 as usize;
588+
/// let q = 4_usize;
589589
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
590590
/// for i in 0..ne {
591591
/// ind[2 * i + 0] = i as i32;
@@ -809,7 +809,7 @@ impl<'a> Operator<'a> {
809809
v: impl Into<VectorOpt<'b>>,
810810
) -> crate::Result<Self> {
811811
let fieldname = CString::new(fieldname).expect("CString::new failed");
812-
let fieldname = fieldname.as_ptr() as *const i8;
812+
let fieldname = fieldname.as_ptr();
813813
self.op_core.check_error(unsafe {
814814
bind_ceed::CeedOperatorSetField(
815815
self.op_core.ptr,
@@ -832,7 +832,7 @@ impl<'a> Operator<'a> {
832832
///
833833
/// // Operator field arguments
834834
/// let ne = 3;
835-
/// let q = 4 as usize;
835+
/// let q = 4_usize;
836836
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
837837
/// for i in 0..ne {
838838
/// ind[2 * i + 0] = i as i32;
@@ -867,7 +867,7 @@ impl<'a> Operator<'a> {
867867
&mut num_inputs,
868868
&mut inputs_ptr,
869869
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
870-
std::ptr::null_mut() as *mut *mut bind_ceed::CeedOperatorField,
870+
std::ptr::null_mut(),
871871
)
872872
})?;
873873
// Convert raw C pointers to fixed length slice
@@ -902,7 +902,7 @@ impl<'a> Operator<'a> {
902902
///
903903
/// // Operator field arguments
904904
/// let ne = 3;
905-
/// let q = 4 as usize;
905+
/// let q = 4_usize;
906906
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
907907
/// for i in 0..ne {
908908
/// ind[2 * i + 0] = i as i32;
@@ -935,7 +935,7 @@ impl<'a> Operator<'a> {
935935
bind_ceed::CeedOperatorGetFields(
936936
self.op_core.ptr,
937937
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
938-
std::ptr::null_mut() as *mut *mut bind_ceed::CeedOperatorField,
938+
std::ptr::null_mut(),
939939
&mut num_outputs,
940940
&mut outputs_ptr,
941941
)
@@ -2140,7 +2140,7 @@ impl<'a> CompositeOperator<'a> {
21402140
///
21412141
/// // Sub operator field arguments
21422142
/// let ne = 3;
2143-
/// let q = 4 as usize;
2143+
/// let q = 4_usize;
21442144
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
21452145
/// for i in 0..ne {
21462146
/// ind[2 * i + 0] = i as i32;

rust/libceed/src/qfunction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'a> QFunctionField<'a> {
108108
unsafe {
109109
bind_ceed::CeedQFunctionFieldGetEvalMode(self.ptr, &mut mode);
110110
}
111-
crate::EvalMode::from_u32(mode as u32)
111+
crate::EvalMode::from_u32(mode)
112112
}
113113
}
114114

@@ -477,7 +477,7 @@ impl<'a> QFunctionCore<'a> {
477477
&mut num_inputs,
478478
&mut inputs_ptr,
479479
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
480-
std::ptr::null_mut() as *mut *mut bind_ceed::CeedQFunctionField,
480+
std::ptr::null_mut(),
481481
)
482482
})?;
483483
// Convert raw C pointers to fixed length slice
@@ -495,7 +495,7 @@ impl<'a> QFunctionCore<'a> {
495495
bind_ceed::CeedQFunctionGetFields(
496496
self.ptr,
497497
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
498-
std::ptr::null_mut() as *mut *mut bind_ceed::CeedQFunctionField,
498+
std::ptr::null_mut(),
499499
&mut num_outputs,
500500
&mut outputs_ptr,
501501
)

rust/libceed/src/vector.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,7 @@ impl<'a> VectorView<'a> {
787787
&mut array,
788788
)
789789
})?;
790-
Ok(Self {
791-
vec: vec,
792-
array: array,
793-
})
790+
Ok(Self { vec, array })
794791
}
795792
}
796793

@@ -839,10 +836,7 @@ impl<'a> VectorViewMut<'a> {
839836
&mut ptr,
840837
)
841838
})?;
842-
Ok(Self {
843-
vec: vec,
844-
array: ptr,
845-
})
839+
Ok(Self { vec, array: ptr })
846840
}
847841
}
848842

0 commit comments

Comments
 (0)