From e05f3da41d49b6bb311970218e61fc791625ada0 Mon Sep 17 00:00:00 2001 From: Jeremy L Thompson Date: Fri, 30 Aug 2024 14:10:41 -0600 Subject: [PATCH] rust - satiate clippy --- examples/rust/ex1-volume/src/main.rs | 17 +++++++------ examples/rust/ex2-surface/src/main.rs | 15 ++++++----- examples/rust/ex3-vector-volume/src/main.rs | 17 +++++++------ examples/rust/ex4-vector-surface/src/main.rs | 15 ++++++----- rust/libceed/src/lib.rs | 2 +- rust/libceed/src/operator.rs | 26 ++++++++++---------- rust/libceed/src/qfunction.rs | 6 ++--- rust/libceed/src/vector.rs | 10 ++------ 8 files changed, 53 insertions(+), 55 deletions(-) diff --git a/examples/rust/ex1-volume/src/main.rs b/examples/rust/ex1-volume/src/main.rs index ab9273f17f..749800fe04 100644 --- a/examples/rust/ex1-volume/src/main.rs +++ b/examples/rust/ex1-volume/src/main.rs @@ -46,17 +46,20 @@ fn example_1(options: opt::Opt) -> libceed::Result<()> { quiet, gallery, } = options; - assert!(dim >= 1 && dim <= 3); + assert!((1..=3).contains(&dim)); assert!(mesh_degree >= 1); assert!(solution_degree >= 1); assert!(num_qpts >= 1); let ncomp_x = dim; - let problem_size: i64; - if problem_size_requested < 0 { - problem_size = if test { 8 * 16 } else { 256 * 1024 }; + let problem_size: i64 = if problem_size_requested < 0 { + if test { + 8 * 16 + } else { + 256 * 1024 + } } else { - problem_size = problem_size_requested; - } + problem_size_requested + }; // Summary output if !quiet { @@ -102,7 +105,7 @@ fn example_1(options: opt::Opt) -> libceed::Result<()> { if dim > 2 { print!(", nz = {}", num_xyz[2]); } - print!("\n"); + println!(); } // Build ElemRestriction objects describing the mesh and solution discrete diff --git a/examples/rust/ex2-surface/src/main.rs b/examples/rust/ex2-surface/src/main.rs index e804f15287..34b5b7fdea 100644 --- a/examples/rust/ex2-surface/src/main.rs +++ b/examples/rust/ex2-surface/src/main.rs @@ -47,21 +47,20 @@ fn example_2(options: opt::Opt) -> libceed::Result<()> { quiet, gallery, } = options; - assert!(dim >= 1 && dim <= 3); + assert!((0..=3).contains(&dim)); assert!(mesh_degree >= 1); assert!(solution_degree >= 1); assert!(num_qpts >= 1); let ncomp_x = dim; - let problem_size: i64; - if problem_size_requested < 0 { - problem_size = if test { + let problem_size: i64 = if problem_size_requested < 0 { + if test { 16 * 16 * (dim * dim) as i64 } else { 256 * 1024 - }; + } } else { - problem_size = problem_size_requested; - } + problem_size_requested + }; // Summary output if !quiet { @@ -107,7 +106,7 @@ fn example_2(options: opt::Opt) -> libceed::Result<()> { if dim > 2 { print!(", nz = {}", num_xyz[2]); } - print!("\n"); + println!(); } // Build ElemRestriction objects describing the mesh and solution discrete diff --git a/examples/rust/ex3-vector-volume/src/main.rs b/examples/rust/ex3-vector-volume/src/main.rs index b37c896184..1d69aca19e 100644 --- a/examples/rust/ex3-vector-volume/src/main.rs +++ b/examples/rust/ex3-vector-volume/src/main.rs @@ -47,17 +47,20 @@ fn example_3(options: opt::Opt) -> libceed::Result<()> { quiet, gallery, } = options; - assert!(dim >= 1 && dim <= 3); + assert!((0..=3).contains(&dim)); assert!(mesh_degree >= 1); assert!(solution_degree >= 1); assert!(num_qpts >= 1); let ncomp_x = dim; - let problem_size: i64; - if problem_size_requested < 0 { - problem_size = if test { 8 * 16 } else { 256 * 1024 }; + let problem_size: i64 = if problem_size_requested < 0 { + if test { + 8 * 16 + } else { + 256 * 1024 + } } else { - problem_size = problem_size_requested; - } + problem_size_requested + }; let ncomp_u = 3; // Summary output @@ -104,7 +107,7 @@ fn example_3(options: opt::Opt) -> libceed::Result<()> { if dim > 2 { print!(", nz = {}", num_xyz[2]); } - print!("\n"); + println!(); } // Build ElemRestriction objects describing the mesh and solution discrete diff --git a/examples/rust/ex4-vector-surface/src/main.rs b/examples/rust/ex4-vector-surface/src/main.rs index c18d42599b..65915d9957 100644 --- a/examples/rust/ex4-vector-surface/src/main.rs +++ b/examples/rust/ex4-vector-surface/src/main.rs @@ -48,21 +48,20 @@ fn example_4(options: opt::Opt) -> libceed::Result<()> { quiet, gallery, } = options; - assert!(dim >= 1 && dim <= 3); + assert!((0..=3).contains(&dim)); assert!(mesh_degree >= 1); assert!(solution_degree >= 1); assert!(num_qpts >= 1); let ncomp_x = dim; - let problem_size: i64; - if problem_size_requested < 0 { - problem_size = if test { + let problem_size: i64 = if problem_size_requested < 0 { + if test { 16 * 16 * (dim * dim) as i64 } else { 256 * 1024 - }; + } } else { - problem_size = problem_size_requested; - } + problem_size_requested + }; let ncomp_u = 3; // Summary output @@ -109,7 +108,7 @@ fn example_4(options: opt::Opt) -> libceed::Result<()> { if dim > 2 { print!(", nz = {}", num_xyz[2]); } - print!("\n"); + println!(); } // Build ElemRestriction objects describing the mesh and solution discrete diff --git a/rust/libceed/src/lib.rs b/rust/libceed/src/lib.rs index 70d291a55e..a09f462efe 100755 --- a/rust/libceed/src/lib.rs +++ b/rust/libceed/src/lib.rs @@ -306,7 +306,7 @@ impl Ceed { // Call to libCEED let mut ptr = std::ptr::null_mut(); - let mut ierr = unsafe { bind_ceed::CeedInit(c_resource.as_ptr() as *const i8, &mut ptr) }; + let mut ierr = unsafe { bind_ceed::CeedInit(c_resource.as_ptr(), &mut ptr) }; if ierr != 0 { panic!("Error initializing backend resource: {}", resource) } diff --git a/rust/libceed/src/operator.rs b/rust/libceed/src/operator.rs index ff7cbfd373..df358a7a70 100644 --- a/rust/libceed/src/operator.rs +++ b/rust/libceed/src/operator.rs @@ -76,7 +76,7 @@ impl<'a> OperatorField<'a> { /// /// // Operator field arguments /// let ne = 3; - /// let q = 4 as usize; + /// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; @@ -123,7 +123,7 @@ impl<'a> OperatorField<'a> { /// /// // Operator field arguments /// let ne = 3; - /// let q = 4 as usize; + /// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; @@ -195,7 +195,7 @@ impl<'a> OperatorField<'a> { /// /// // Operator field arguments /// let ne = 3; - /// let q = 4 as usize; + /// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; @@ -257,7 +257,7 @@ impl<'a> OperatorField<'a> { /// /// // Operator field arguments /// let ne = 3; - /// let q = 4 as usize; + /// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; @@ -355,7 +355,7 @@ impl<'a> fmt::Display for OperatorCore<'a> { /// /// // Operator field arguments /// let ne = 3; -/// let q = 4 as usize; +/// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; @@ -394,7 +394,7 @@ impl<'a> fmt::Display for Operator<'a> { /// /// // Sub operator field arguments /// let ne = 3; -/// let q = 4 as usize; +/// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; @@ -593,7 +593,7 @@ impl<'a> Operator<'a> { /// /// // Operator field arguments /// let ne = 3; - /// let q = 4 as usize; + /// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; @@ -817,7 +817,7 @@ impl<'a> Operator<'a> { v: impl Into>, ) -> crate::Result { let fieldname = CString::new(fieldname).expect("CString::new failed"); - let fieldname = fieldname.as_ptr() as *const i8; + let fieldname = fieldname.as_ptr(); let ierr = unsafe { bind_ceed::CeedOperatorSetField( self.op_core.ptr, @@ -841,7 +841,7 @@ impl<'a> Operator<'a> { /// /// // Operator field arguments /// let ne = 3; - /// let q = 4 as usize; + /// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; @@ -876,7 +876,7 @@ impl<'a> Operator<'a> { &mut num_inputs, &mut inputs_ptr, std::ptr::null_mut() as *mut bind_ceed::CeedInt, - std::ptr::null_mut() as *mut *mut bind_ceed::CeedOperatorField, + std::ptr::null_mut(), ) }; self.op_core.check_error(ierr)?; @@ -913,7 +913,7 @@ impl<'a> Operator<'a> { /// /// // Operator field arguments /// let ne = 3; - /// let q = 4 as usize; + /// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; @@ -946,7 +946,7 @@ impl<'a> Operator<'a> { bind_ceed::CeedOperatorGetFields( self.op_core.ptr, std::ptr::null_mut() as *mut bind_ceed::CeedInt, - std::ptr::null_mut() as *mut *mut bind_ceed::CeedOperatorField, + std::ptr::null_mut(), &mut num_outputs, &mut outputs_ptr, ) @@ -2157,7 +2157,7 @@ impl<'a> CompositeOperator<'a> { /// /// // Sub operator field arguments /// let ne = 3; - /// let q = 4 as usize; + /// let q = 4_usize; /// let mut ind: Vec = vec![0; 2 * ne]; /// for i in 0..ne { /// ind[2 * i + 0] = i as i32; diff --git a/rust/libceed/src/qfunction.rs b/rust/libceed/src/qfunction.rs index 9723674284..bd5b9cbc81 100644 --- a/rust/libceed/src/qfunction.rs +++ b/rust/libceed/src/qfunction.rs @@ -108,7 +108,7 @@ impl<'a> QFunctionField<'a> { unsafe { bind_ceed::CeedQFunctionFieldGetEvalMode(self.ptr, &mut mode); } - crate::EvalMode::from_u32(mode as u32) + crate::EvalMode::from_u32(mode) } } @@ -476,7 +476,7 @@ impl<'a> QFunctionCore<'a> { &mut num_inputs, &mut inputs_ptr, std::ptr::null_mut() as *mut bind_ceed::CeedInt, - std::ptr::null_mut() as *mut *mut bind_ceed::CeedQFunctionField, + std::ptr::null_mut(), ) }; self.check_error(ierr)?; @@ -495,7 +495,7 @@ impl<'a> QFunctionCore<'a> { bind_ceed::CeedQFunctionGetFields( self.ptr, std::ptr::null_mut() as *mut bind_ceed::CeedInt, - std::ptr::null_mut() as *mut *mut bind_ceed::CeedQFunctionField, + std::ptr::null_mut(), &mut num_outputs, &mut outputs_ptr, ) diff --git a/rust/libceed/src/vector.rs b/rust/libceed/src/vector.rs index 473c2b0458..2526345452 100644 --- a/rust/libceed/src/vector.rs +++ b/rust/libceed/src/vector.rs @@ -799,10 +799,7 @@ impl<'a> VectorView<'a> { ) }; vec.check_error(ierr)?; - Ok(Self { - vec: vec, - array: array, - }) + Ok(Self { vec, array }) } } @@ -852,10 +849,7 @@ impl<'a> VectorViewMut<'a> { ) }; vec.check_error(ierr)?; - Ok(Self { - vec: vec, - array: ptr, - }) + Ok(Self { vec, array: ptr }) } }