Merge pull request #59 from jhwgh1968/rusfmt_ci

New CI Job for Formatting
This commit is contained in:
Stephen Chung 2020-09-21 09:24:03 +08:00 committed by GitHub
commit 748d4d2f36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 10 deletions

View File

@ -77,6 +77,29 @@ jobs:
with: with:
command: build command: build
args: --manifest-path=no_std/no_std_test/Cargo.toml ${{matrix.flags}} 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 Clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all -- -Aclippy::all -Dclippy::perf
codegen_build: codegen_build:
name: Codegen Build name: Codegen Build
runs-on: ${{matrix.os}} runs-on: ${{matrix.os}}

View File

@ -32,7 +32,10 @@ pub struct ExportInfo {
pub fn parse_attr_items(args: ParseStream) -> syn::Result<ExportInfo> { pub fn parse_attr_items(args: ParseStream) -> syn::Result<ExportInfo> {
if args.is_empty() { 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 let arg_list = args
.call(syn::punctuated::Punctuated::<syn::Expr, syn::Token![,]>::parse_separated_nonempty)?; .call(syn::punctuated::Punctuated::<syn::Expr, syn::Token![,]>::parse_separated_nonempty)?;
@ -80,10 +83,17 @@ pub fn parse_punctuated_items(
.ok_or_else(|| syn::Error::new(attr_path.span(), "expecting attribute name"))?, .ok_or_else(|| syn::Error::new(attr_path.span(), "expecting attribute name"))?,
x => return Err(syn::Error::new(x.span(), "expecting identifier")), 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<T: ExportedParams>( pub(crate) fn outer_item_attributes<T: ExportedParams>(

View File

@ -187,7 +187,6 @@ fn export_nested_by_prefix_test() -> Result<(), Box<EvalAltResult>> {
if s == "math::bar_fourth_adders::add_int (i64, i64)" if s == "math::bar_fourth_adders::add_int (i64, i64)"
&& p == rhai::Position::new(3, 42))); && p == rhai::Position::new(3, 42)));
assert!(matches!(*engine.eval::<FLOAT>( assert!(matches!(*engine.eval::<FLOAT>(
r#"import "Math::Advanced" as math; r#"import "Math::Advanced" as math;
let ex = 41.0; let ex = 41.0;

View File

@ -1168,7 +1168,7 @@ impl Engine {
.take_immutable_string() .take_immutable_string()
.map_err(|_| EvalAltResult::ErrorStringIndexExpr(idx_pos))?; .map_err(|_| EvalAltResult::ErrorStringIndexExpr(idx_pos))?;
map.entry(index).or_insert(Default::default()).into() map.entry(index).or_insert_with(Default::default).into()
} else { } else {
let index = idx let index = idx
.read_lock::<ImmutableString>() .read_lock::<ImmutableString>()
@ -2014,6 +2014,6 @@ impl Engine {
self.type_names self.type_names
.as_ref() .as_ref()
.and_then(|t| t.get(name).map(String::as_str)) .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))
} }
} }

View File

@ -46,9 +46,7 @@ mod map_functions {
} }
pub fn fill_with(map1: &mut Map, map2: Map) { pub fn fill_with(map1: &mut Map, map2: Map) {
map2.into_iter().for_each(|(key, value)| { map2.into_iter().for_each(|(key, value)| {
if !map1.contains_key(&key) { map1.entry(key).or_insert(value);
map1.insert(key, value);
}
}); });
} }

View File

@ -1,5 +1,8 @@
//! Module containing all built-in _packages_ available to Rhai, plus facilities to define custom packages. //! 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::fn_native::{CallableFunction, IteratorFn, Shared};
use crate::module::Module; use crate::module::Module;
use crate::utils::StaticVec; use crate::utils::StaticVec;

View File

@ -3479,7 +3479,7 @@ pub fn map_dynamic_to_expr(value: Dynamic, pos: Position) -> Option<Expr> {
Union::Unit(_) => Some(Expr::Unit(pos)), Union::Unit(_) => Some(Expr::Unit(pos)),
Union::Int(value) => Some(Expr::IntegerConstant(Box::new((value, pos)))), Union::Int(value) => Some(Expr::IntegerConstant(Box::new((value, pos)))),
Union::Char(value) => Some(Expr::CharConstant(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(true) => Some(Expr::True(pos)),
Union::Bool(false) => Some(Expr::False(pos)), Union::Bool(false) => Some(Expr::False(pos)),
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]