From c389014df73ffc24ae4860bf1c54699e310c7711 Mon Sep 17 00:00:00 2001 From: J Henry Waugh Date: Sun, 20 Sep 2020 12:37:37 -0500 Subject: [PATCH 1/5] Run cargo fmt for loose ends --- codegen/src/attrs.rs | 16 +++++++++++++--- codegen/tests/test_nested.rs | 1 - 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/codegen/src/attrs.rs b/codegen/src/attrs.rs index 32d258f7..eb8d999a 100644 --- a/codegen/src/attrs.rs +++ b/codegen/src/attrs.rs @@ -32,7 +32,10 @@ pub struct ExportInfo { pub fn parse_attr_items(args: ParseStream) -> syn::Result { if args.is_empty() { - return Ok(ExportInfo { item_span: args.span(), items: Vec::new()}); + return Ok(ExportInfo { + item_span: args.span(), + items: Vec::new(), + }); } let arg_list = args .call(syn::punctuated::Punctuated::::parse_separated_nonempty)?; @@ -80,10 +83,17 @@ pub fn parse_punctuated_items( .ok_or_else(|| syn::Error::new(attr_path.span(), "expecting attribute name"))?, x => return Err(syn::Error::new(x.span(), "expecting identifier")), }; - attrs.push(AttrItem { key, value, span: arg_span }); + attrs.push(AttrItem { + key, + value, + span: arg_span, + }); } - Ok(ExportInfo { item_span: list_span, items: attrs }) + Ok(ExportInfo { + item_span: list_span, + items: attrs, + }) } pub(crate) fn outer_item_attributes( diff --git a/codegen/tests/test_nested.rs b/codegen/tests/test_nested.rs index f0144990..4d0d39aa 100644 --- a/codegen/tests/test_nested.rs +++ b/codegen/tests/test_nested.rs @@ -187,7 +187,6 @@ fn export_nested_by_prefix_test() -> Result<(), Box> { if s == "math::bar_fourth_adders::add_int (i64, i64)" && p == rhai::Position::new(3, 42))); - assert!(matches!(*engine.eval::( r#"import "Math::Advanced" as math; let ex = 41.0; From 795c3f870b41e236d06d016c871d183dd1869e94 Mon Sep 17 00:00:00 2001 From: J Henry Waugh Date: Sun, 20 Sep 2020 12:47:31 -0500 Subject: [PATCH 2/5] New CI Job for Formatting --- .github/workflows/build.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 37d8c233..1d005821 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,6 +77,29 @@ jobs: with: command: build args: --manifest-path=no_std/no_std_test/Cargo.toml ${{matrix.flags}} + rustfmt: + name: Check Formatting + runs-on: windows-latest + continue-on-error: true + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + components: rustfmt, clippy + - name: Run Rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + - name: Run Rustfmt + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- codegen_build: name: Codegen Build runs-on: ${{matrix.os}} From 788a22108bfd319c517f1e3a5c8b1e79e417159c Mon Sep 17 00:00:00 2001 From: J Henry Waugh Date: Sun, 20 Sep 2020 13:03:35 -0500 Subject: [PATCH 3/5] Hide clippy errors from exported modules --- src/packages/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/packages/mod.rs b/src/packages/mod.rs index 1c6dc3a9..53fbf94f 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -1,5 +1,8 @@ //! Module containing all built-in _packages_ available to Rhai, plus facilities to define custom packages. +// Hide clippy errors from exported modules +#![allow(clippy::redundant_clone)] + use crate::fn_native::{CallableFunction, IteratorFn, Shared}; use crate::module::Module; use crate::utils::StaticVec; From c8dffff515c00f4be1227354a2de1c803d30e425 Mon Sep 17 00:00:00 2001 From: J Henry Waugh Date: Sun, 20 Sep 2020 13:07:43 -0500 Subject: [PATCH 4/5] Fix clippy::perf lint errors --- src/engine.rs | 4 ++-- src/packages/map_basic.rs | 4 +--- src/parser.rs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index ad5b1c0a..a35d3458 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1168,7 +1168,7 @@ impl Engine { .take_immutable_string() .map_err(|_| EvalAltResult::ErrorStringIndexExpr(idx_pos))?; - map.entry(index).or_insert(Default::default()).into() + map.entry(index).or_insert_with(Default::default).into() } else { let index = idx .read_lock::() @@ -2014,6 +2014,6 @@ impl Engine { self.type_names .as_ref() .and_then(|t| t.get(name).map(String::as_str)) - .unwrap_or(map_std_type_name(name)) + .unwrap_or_else(|| map_std_type_name(name)) } } diff --git a/src/packages/map_basic.rs b/src/packages/map_basic.rs index fde57db7..e944bfb7 100644 --- a/src/packages/map_basic.rs +++ b/src/packages/map_basic.rs @@ -46,9 +46,7 @@ mod map_functions { } pub fn fill_with(map1: &mut Map, map2: Map) { map2.into_iter().for_each(|(key, value)| { - if !map1.contains_key(&key) { - map1.insert(key, value); - } + map1.entry(key).or_insert(value); }); } diff --git a/src/parser.rs b/src/parser.rs index d598c7a6..2c0076df 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -3479,7 +3479,7 @@ pub fn map_dynamic_to_expr(value: Dynamic, pos: Position) -> Option { Union::Unit(_) => Some(Expr::Unit(pos)), Union::Int(value) => Some(Expr::IntegerConstant(Box::new((value, pos)))), Union::Char(value) => Some(Expr::CharConstant(Box::new((value, pos)))), - Union::Str(value) => Some(Expr::StringConstant(Box::new((value.clone(), pos)))), + Union::Str(value) => Some(Expr::StringConstant(Box::new((value, pos)))), Union::Bool(true) => Some(Expr::True(pos)), Union::Bool(false) => Some(Expr::False(pos)), #[cfg(not(feature = "no_index"))] From 896761eaa941dc0ee19f3bfc33e3407bf7b295cf Mon Sep 17 00:00:00 2001 From: J Henry Waugh Date: Sun, 20 Sep 2020 13:11:15 -0500 Subject: [PATCH 5/5] Update CI to enforce clippy::perf --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1d005821..1ffeec22 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -95,11 +95,11 @@ jobs: with: command: fmt args: --all -- --check - - name: Run Rustfmt + - name: Run Clippy uses: actions-rs/cargo@v1 with: command: clippy - args: -- + args: --all -- -Aclippy::all -Dclippy::perf codegen_build: name: Codegen Build runs-on: ${{matrix.os}}