Skip to content

Commit 9a633ca

Browse files
committed
rust - satiate clippy
1 parent bab92e7 commit 9a633ca

File tree

8 files changed

+56
-58
lines changed

8 files changed

+56
-58
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
@@ -306,7 +306,7 @@ impl Ceed {
306306

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

rust/libceed/src/operator.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a> OperatorField<'a> {
4040
///
4141
/// // Operator field arguments
4242
/// let ne = 3;
43-
/// let q = 4 as usize;
43+
/// let q = 4_usize;
4444
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
4545
/// for i in 0..ne {
4646
/// ind[2 * i + 0] = i as i32;
@@ -87,7 +87,7 @@ impl<'a> OperatorField<'a> {
8787
///
8888
/// // Operator field arguments
8989
/// let ne = 3;
90-
/// let q = 4 as usize;
90+
/// let q = 4_usize;
9191
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
9292
/// for i in 0..ne {
9393
/// ind[2 * i + 0] = i as i32;
@@ -130,7 +130,7 @@ impl<'a> OperatorField<'a> {
130130
let slice = unsafe {
131131
std::slice::from_raw_parts(
132132
&ptr as *const bind_ceed::CeedElemRestriction as *const ElemRestriction,
133-
1 as usize,
133+
1_usize,
134134
)
135135
};
136136
ElemRestrictionOpt::Some(&slice[0])
@@ -147,7 +147,7 @@ impl<'a> OperatorField<'a> {
147147
///
148148
/// // Operator field arguments
149149
/// let ne = 3;
150-
/// let q = 4 as usize;
150+
/// let q = 4_usize;
151151
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
152152
/// for i in 0..ne {
153153
/// ind[2 * i + 0] = i as i32;
@@ -188,7 +188,7 @@ impl<'a> OperatorField<'a> {
188188
let slice = unsafe {
189189
std::slice::from_raw_parts(
190190
&ptr as *const bind_ceed::CeedBasis as *const Basis,
191-
1 as usize,
191+
1_usize,
192192
)
193193
};
194194
BasisOpt::Some(&slice[0])
@@ -205,7 +205,7 @@ impl<'a> OperatorField<'a> {
205205
///
206206
/// // Operator field arguments
207207
/// let ne = 3;
208-
/// let q = 4 as usize;
208+
/// let q = 4_usize;
209209
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
210210
/// for i in 0..ne {
211211
/// ind[2 * i + 0] = i as i32;
@@ -244,7 +244,7 @@ impl<'a> OperatorField<'a> {
244244
let slice = unsafe {
245245
std::slice::from_raw_parts(
246246
&ptr as *const bind_ceed::CeedVector as *const Vector,
247-
1 as usize,
247+
1_usize,
248248
)
249249
};
250250
VectorOpt::Some(&slice[0])
@@ -309,7 +309,7 @@ impl<'a> fmt::Display for OperatorCore<'a> {
309309
///
310310
/// // Operator field arguments
311311
/// let ne = 3;
312-
/// let q = 4 as usize;
312+
/// let q = 4_usize;
313313
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
314314
/// for i in 0..ne {
315315
/// ind[2 * i + 0] = i as i32;
@@ -348,7 +348,7 @@ impl<'a> fmt::Display for Operator<'a> {
348348
///
349349
/// // Sub operator field arguments
350350
/// let ne = 3;
351-
/// let q = 4 as usize;
351+
/// let q = 4_usize;
352352
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
353353
/// for i in 0..ne {
354354
/// ind[2 * i + 0] = i as i32;
@@ -547,7 +547,7 @@ impl<'a> Operator<'a> {
547547
///
548548
/// // Operator field arguments
549549
/// let ne = 3;
550-
/// let q = 4 as usize;
550+
/// let q = 4_usize;
551551
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
552552
/// for i in 0..ne {
553553
/// ind[2 * i + 0] = i as i32;
@@ -771,7 +771,7 @@ impl<'a> Operator<'a> {
771771
v: impl Into<VectorOpt<'b>>,
772772
) -> crate::Result<Self> {
773773
let fieldname = CString::new(fieldname).expect("CString::new failed");
774-
let fieldname = fieldname.as_ptr() as *const i8;
774+
let fieldname = fieldname.as_ptr();
775775
let ierr = unsafe {
776776
bind_ceed::CeedOperatorSetField(
777777
self.op_core.ptr,
@@ -795,7 +795,7 @@ impl<'a> Operator<'a> {
795795
///
796796
/// // Operator field arguments
797797
/// let ne = 3;
798-
/// let q = 4 as usize;
798+
/// let q = 4_usize;
799799
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
800800
/// for i in 0..ne {
801801
/// ind[2 * i + 0] = i as i32;
@@ -830,7 +830,7 @@ impl<'a> Operator<'a> {
830830
&mut num_inputs,
831831
&mut inputs_ptr,
832832
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
833-
std::ptr::null_mut() as *mut *mut bind_ceed::CeedOperatorField,
833+
std::ptr::null_mut(),
834834
)
835835
};
836836
self.op_core.check_error(ierr)?;
@@ -851,7 +851,7 @@ impl<'a> Operator<'a> {
851851
///
852852
/// // Operator field arguments
853853
/// let ne = 3;
854-
/// let q = 4 as usize;
854+
/// let q = 4_usize;
855855
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
856856
/// for i in 0..ne {
857857
/// ind[2 * i + 0] = i as i32;
@@ -884,7 +884,7 @@ impl<'a> Operator<'a> {
884884
bind_ceed::CeedOperatorGetFields(
885885
self.op_core.ptr,
886886
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
887-
std::ptr::null_mut() as *mut *mut bind_ceed::CeedOperatorField,
887+
std::ptr::null_mut(),
888888
&mut num_outputs,
889889
&mut outputs_ptr,
890890
)
@@ -2079,7 +2079,7 @@ impl<'a> CompositeOperator<'a> {
20792079
///
20802080
/// // Sub operator field arguments
20812081
/// let ne = 3;
2082-
/// let q = 4 as usize;
2082+
/// let q = 4_usize;
20832083
/// let mut ind: Vec<i32> = vec![0; 2 * ne];
20842084
/// for i in 0..ne {
20852085
/// 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

@@ -476,7 +476,7 @@ impl<'a> QFunctionCore<'a> {
476476
&mut num_inputs,
477477
&mut inputs_ptr,
478478
std::ptr::null_mut() as *mut bind_ceed::CeedInt,
479-
std::ptr::null_mut() as *mut *mut bind_ceed::CeedQFunctionField,
479+
std::ptr::null_mut(),
480480
)
481481
};
482482
self.check_error(ierr)?;
@@ -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
@@ -799,10 +799,7 @@ impl<'a> VectorView<'a> {
799799
)
800800
};
801801
vec.check_error(ierr)?;
802-
Ok(Self {
803-
vec: vec,
804-
array: array,
805-
})
802+
Ok(Self { vec, array })
806803
}
807804
}
808805

@@ -852,10 +849,7 @@ impl<'a> VectorViewMut<'a> {
852849
)
853850
};
854851
vec.check_error(ierr)?;
855-
Ok(Self {
856-
vec: vec,
857-
array: ptr,
858-
})
852+
Ok(Self { vec, array: ptr })
859853
}
860854
}
861855

0 commit comments

Comments
 (0)