diff options
author | Christian Poveda <31802960+pvdrz@users.noreply.github.com> | 2022-10-18 12:19:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-18 12:19:40 -0500 |
commit | 68c741d42d2d312037a978ac16e80d0bcc88bbef (patch) | |
tree | 1d17e6342b8ee0fbc3a74ab16b145480fe10c6ed | |
parent | 66388deae3b363cebc07d3e0b5570565bc5bb482 (diff) | |
parent | c1d1f1b694952cd91dc4e24614d65e70e2dadf84 (diff) |
Merge pull request #2313 from ferrous-systems/fix-clippy-lints
Fix clippy lints
-rw-r--r-- | bindgen-tests/tests/expectations/build.rs | 5 | ||||
-rw-r--r-- | bindgen-tests/tests/quickchecking/src/fuzzers.rs | 11 | ||||
-rw-r--r-- | bindgen-tests/tests/quickchecking/src/lib.rs | 46 | ||||
-rw-r--r-- | bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs | 28 |
4 files changed, 38 insertions, 52 deletions
diff --git a/bindgen-tests/tests/expectations/build.rs b/bindgen-tests/tests/expectations/build.rs index edbcafb9..21111853 100644 --- a/bindgen-tests/tests/expectations/build.rs +++ b/bindgen-tests/tests/expectations/build.rs @@ -8,8 +8,7 @@ use std::fs; use std::io::Write; use std::path::Path; -const LIBCLANG_VERSION_DIRS: &'static [&'static str] = - &["libclang-5", "libclang-9"]; +const LIBCLANG_VERSION_DIRS: &[&str] = &["libclang-5", "libclang-9"]; fn main() { println!("cargo:rerun-if-changed=build.rs"); @@ -26,7 +25,7 @@ fn main() { for entry in fs::read_dir(dir).unwrap() { let entry = entry.unwrap(); let path = entry.path(); - let path = path.canonicalize().unwrap_or_else(|_| path.into()); + let path = path.canonicalize().unwrap_or(path); if path.extension().map(|e| e.to_string_lossy()) != Some("rs".into()) { diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs index b609dd5a..4188f8f5 100644 --- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -327,12 +327,7 @@ impl Arbitrary for ArrayDimensionC { let dimensions = g.gen_range(0, 5); let mut def = String::new(); - let lower_bound; - if cfg!(feature = "zero-sized-arrays") { - lower_bound = 0; - } else { - lower_bound = 1; - } + let lower_bound = i32::from(cfg!(feature = "zero-sized-arrays")); for _ in 1..dimensions { // 16 is an arbitrary "not too big" number for capping array size. @@ -400,7 +395,7 @@ impl Arbitrary for StructDeclarationC { fn arbitrary<G: Gen>(g: &mut G) -> StructDeclarationC { // Reduce generator size as a method of putting a bound on recursion. // When size < 1 the empty list is generated. - let reduced_size: usize = (g.size() / 2) as usize + 1; + let reduced_size: usize = (g.size() / 2) + 1; let mut decl_list: DeclarationListC = Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size)); let mut fields: DeclarationListC = DeclarationListC { decls: vec![] }; @@ -448,7 +443,7 @@ impl Arbitrary for UnionDeclarationC { fn arbitrary<G: Gen>(g: &mut G) -> UnionDeclarationC { // Reduce generator size as a method of putting a bound on recursion. // When size < 1 the empty list is generated. - let reduced_size: usize = (g.size() / 2) as usize + 1; + let reduced_size: usize = (g.size() / 2) + 1; let mut decl_list: DeclarationListC = Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size)); let mut fields: DeclarationListC = DeclarationListC { decls: vec![] }; diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index b09d1c49..75bfc237 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -63,32 +63,27 @@ fn run_predicate_script( header_file.write_all(header.to_string().as_bytes())?; header_file.sync_all()?; - let header_path_string; - match header_path.into_os_string().into_string() { - Ok(s) => header_path_string = s, - Err(_) => return Err(From::from("error converting path into String")), - } + let header_path_string = header_path + .into_os_string() + .into_string() + .map_err(|_| "error converting path into String")?; let mut predicate_script_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); predicate_script_path.push("../../csmith-fuzzing/predicate.py"); - let predicate_script_path_string; - match predicate_script_path.into_os_string().into_string() { - Ok(s) => predicate_script_path_string = s, - Err(_) => return Err(From::from("error converting path into String")), - } + let predicate_script_path_string = predicate_script_path + .into_os_string() + .into_string() + .map_err(|_| "error converting path into String")?; // Copy generated temp files to output_path directory for inspection. // If `None`, output path not specified, don't copy. - match CONTEXT.lock().unwrap().output_path { - Some(ref path) => { - Command::new("cp") - .arg("-a") - .arg(&dir.path().to_str().unwrap()) - .arg(&path) - .output()?; - } - None => {} + if let Some(ref path) = CONTEXT.lock().unwrap().output_path { + Command::new("cp") + .arg("-a") + .arg(dir.path().to_str().unwrap()) + .arg(path) + .output()?; } Ok(Command::new(&predicate_script_path_string) @@ -101,10 +96,10 @@ fn run_predicate_script( // status of that command. fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult { match run_predicate_script(header) { - Ok(o) => return TestResult::from_bool(o.status.success()), + Ok(o) => TestResult::from_bool(o.status.success()), Err(e) => { println!("{:?}", e); - return TestResult::from_bool(false); + TestResult::from_bool(false) } } } @@ -118,12 +113,9 @@ pub fn test_bindgen( tests: usize, output_path: Option<&str>, ) { - match output_path { - Some(path) => { - CONTEXT.lock().unwrap().output_path = - Some(String::from(PathBuf::from(path).to_str().unwrap())); - } - None => {} // Path not specified, don't provide output. + if let Some(path) = output_path { + CONTEXT.lock().unwrap().output_path = + Some(String::from(PathBuf::from(path).to_str().unwrap())); } QuickCheck::new() diff --git a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs index 800c70b4..0d43f300 100644 --- a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs +++ b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs @@ -13,84 +13,84 @@ use rand::thread_rng; #[test] fn test_declaraion_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: DeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_declaraion_list_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: DeclarationListC = Arbitrary::arbitrary(gen); } #[test] fn test_base_type_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: BaseTypeC = Arbitrary::arbitrary(gen); } #[test] fn test_type_qualifier_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: TypeQualifierC = Arbitrary::arbitrary(gen); } #[test] fn test_pointer_level_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: PointerLevelC = Arbitrary::arbitrary(gen); } #[test] fn test_array_dimension_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: ArrayDimensionC = Arbitrary::arbitrary(gen); } #[test] fn test_basic_type_declaration_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: BasicTypeDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_struct_declaration_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: StructDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_union_declaration_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: UnionDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_function_pointer_declaration_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: FunctionPointerDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_function_prototype_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: FunctionPrototypeC = Arbitrary::arbitrary(gen); } #[test] fn test_parameter_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: ParameterC = Arbitrary::arbitrary(gen); } #[test] fn test_parameter_list_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: ParameterListC = Arbitrary::arbitrary(gen); } #[test] fn test_header_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: HeaderC = Arbitrary::arbitrary(gen); } |