From 26a483425439137bc4174058738a81cf9f698758 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Sat, 26 Mar 2022 18:52:08 +0800 Subject: [PATCH] fix warnings --- nac3core/src/codegen/expr.rs | 6 +++--- nac3core/src/codegen/test.rs | 2 +- nac3core/src/toplevel/builtins.rs | 2 +- nac3core/src/toplevel/composer.rs | 2 +- nac3core/src/toplevel/test.rs | 4 ++-- nac3core/src/typecheck/type_inferencer/test.rs | 4 ++-- nac3parser/src/parser.rs | 14 +++++++------- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index 7991b55c..6066a969 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -990,7 +990,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>( .map(|x| { generator .gen_expr(ctx, x) - .map_or_else(|e| Err(e), |v| v.unwrap().to_basic_value_enum(ctx, generator)) + .map_or_else(Err, |v| v.unwrap().to_basic_value_enum(ctx, generator)) }) .collect::, _>>()?; let ty = if elements.is_empty() { @@ -1023,7 +1023,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>( .map(|x| { generator .gen_expr(ctx, x) - .map_or_else(|e| Err(e), |v| v.unwrap().to_basic_value_enum(ctx, generator)) + .map_or_else(Err, |v| v.unwrap().to_basic_value_enum(ctx, generator)) }) .collect::, _>>()?; let element_ty = element_val.iter().map(BasicValueEnum::get_type).collect_vec(); @@ -1051,7 +1051,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>( v.into_pointer_value(), &[zero, int32.const_int(index as u64, false)], ))) as Result<_, String> - }, |v| Ok(v))?, + }, Ok)?, ValueEnum::Dynamic(v) => { let index = ctx.get_attr_index(value.custom.unwrap(), *attr); ValueEnum::Dynamic(ctx.build_gep_and_load( diff --git a/nac3core/src/codegen/test.rs b/nac3core/src/codegen/test.rs index e6c4bbb0..f1ca5385 100644 --- a/nac3core/src/codegen/test.rs +++ b/nac3core/src/codegen/test.rs @@ -71,7 +71,7 @@ impl SymbolResolver for Resolver { unimplemented!() } - fn get_exception_id(&self, tyid: usize) -> usize { + fn get_exception_id(&self, _tyid: usize) -> usize { unimplemented!() } } diff --git a/nac3core/src/toplevel/builtins.rs b/nac3core/src/toplevel/builtins.rs index 6b171286..9491d5e7 100644 --- a/nac3core/src/toplevel/builtins.rs +++ b/nac3core/src/toplevel/builtins.rs @@ -263,7 +263,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { instance_to_stmt: Default::default(), resolver: None, codegen_callback: Some(Arc::new(GenCall::new(Box::new( - |ctx, obj, _, _, generator| { + |_, _, _, _, _| { unreachable!("handled in gen_expr") }, )))), diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index bfed6690..0261aa7d 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -91,7 +91,7 @@ impl TopLevelComposer { assert!(name == *simple_name); builtin_ty.insert(name, *signature); builtin_id.insert(name, DefinitionId(id)); - } else if let TopLevelDef::Class { name, constructor, object_id, type_vars, .. } = &*def + } else if let TopLevelDef::Class { name, constructor, object_id, .. } = &*def { assert!(id == object_id.0); if let Some(constructor) = constructor { diff --git a/nac3core/src/toplevel/test.rs b/nac3core/src/toplevel/test.rs index 23f5b85c..41f7fa63 100644 --- a/nac3core/src/toplevel/test.rs +++ b/nac3core/src/toplevel/test.rs @@ -65,14 +65,14 @@ impl SymbolResolver for Resolver { } fn get_identifier_def(&self, id: StrRef) -> Result { - self.0.id_to_def.lock().get(&id).cloned().ok_or("Unknown identifier".to_string()) + self.0.id_to_def.lock().get(&id).cloned().ok_or_else(|| "Unknown identifier".to_string()) } fn get_string_id(&self, _: &str) -> i32 { unimplemented!() } - fn get_exception_id(&self, tyid: usize) -> usize { + fn get_exception_id(&self, _tyid: usize) -> usize { unimplemented!() } } diff --git a/nac3core/src/typecheck/type_inferencer/test.rs b/nac3core/src/typecheck/type_inferencer/test.rs index 2c5a6ded..74930814 100644 --- a/nac3core/src/typecheck/type_inferencer/test.rs +++ b/nac3core/src/typecheck/type_inferencer/test.rs @@ -44,14 +44,14 @@ impl SymbolResolver for Resolver { } fn get_identifier_def(&self, id: StrRef) -> Result { - self.id_to_def.get(&id).cloned().ok_or("Unknown identifier".to_string()) + self.id_to_def.get(&id).cloned().ok_or_else(|| "Unknown identifier".to_string()) } fn get_string_id(&self, _: &str) -> i32 { unimplemented!() } - fn get_exception_id(&self, tyid: usize) -> usize { + fn get_exception_id(&self, _tyid: usize) -> usize { unimplemented!() } } diff --git a/nac3parser/src/parser.rs b/nac3parser/src/parser.rs index 55da3fad..b8968d59 100644 --- a/nac3parser/src/parser.rs +++ b/nac3parser/src/parser.rs @@ -121,7 +121,7 @@ mod tests { #[test] fn test_parse_lambda() { let source = "lambda x, y: x * y"; // lambda(x, y): x * y"; - let parse_ast = parse_program(&source, Default::default()).unwrap(); + let parse_ast = parse_program(source, Default::default()).unwrap(); insta::assert_debug_snapshot!(parse_ast); } @@ -129,7 +129,7 @@ mod tests { fn test_parse_tuples() { let source = "a, b = 4, 5"; - insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap()); + insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap()); } #[test] @@ -140,7 +140,7 @@ class Foo(A, B): pass def method_with_default(self, arg='default'): pass"; - insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap()); + insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap()); } #[test] @@ -183,7 +183,7 @@ while i < 2: # nac3: 4 # nac3: if1 if 1: # nac3: if2 3"; - insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap()); + insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap()); } #[test] @@ -196,7 +196,7 @@ while test: # nac3: while3 # nac3: simple assign0 a = 3 # nac3: simple assign1 "; - insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap()); + insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap()); } #[test] @@ -215,7 +215,7 @@ if a: # nac3: small2 for i in a: # nac3: for1 pass "; - insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap()); + insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap()); } #[test] @@ -224,6 +224,6 @@ for i in a: # nac3: for1 if a: # nac3: something a = 3 "; - assert!(parse_program(&source, Default::default()).is_err()); + assert!(parse_program(source, Default::default()).is_err()); } }