From 0bb44c3bbc63d385d77d93da6abd07214bcfd700 Mon Sep 17 00:00:00 2001 From: jfecher Date: Wed, 13 Dec 2023 13:13:29 -0600 Subject: [PATCH] fix: Stop issuing unused variable warnings for variables in trait definitions (#3797) # Description ## Problem\* Previously we'd issue a warning for each trait function parameter that it is unused. This seemed to only trigger when the trait was in another crate. ## Summary\* Stop checking for unused variables in trait function declarations since there is no body to use the variable in anyway. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. Co-authored-by: kevaundray --- .../src/hir/resolution/resolver.rs | 5 ++--- compiler/noirc_frontend/src/tests.rs | 17 +++-------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/compiler/noirc_frontend/src/hir/resolution/resolver.rs b/compiler/noirc_frontend/src/hir/resolution/resolver.rs index 0556698fb58..9cd28d80784 100644 --- a/compiler/noirc_frontend/src/hir/resolution/resolver.rs +++ b/compiler/noirc_frontend/src/hir/resolution/resolver.rs @@ -239,9 +239,8 @@ impl<'a> Resolver<'a> { }; let (hir_func, func_meta) = self.intern_function(NoirFunction { kind, def }, func_id); - let func_scope_tree = self.scopes.end_function(); - self.check_for_unused_variables_in_scope_tree(func_scope_tree); - + let _ = self.scopes.end_function(); + // Don't check the scope tree for unused variables, they can't be used in a declaration anyway. self.trait_bounds.clear(); (hir_func, func_meta) } diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index 2619189ee8d..7b2a94b4f10 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -48,15 +48,6 @@ mod test { }); } - /// Many of the tests in this file have odd unused variable warnings which do not occur - /// when running an identical program using `nargo execute`. They're filtered out of the - /// errors returned by `get_errors` for now. - pub(crate) fn remove_unused_variable_warnings(errors: &mut Vec<(CompilationError, FileId)>) { - errors.retain(|(error, _)| { - !matches!(error, CompilationError::ResolverError(ResolverError::UnusedVariable { .. })) - }); - } - pub(crate) fn get_program( src: &str, ) -> (ParsedModule, Context, Vec<(CompilationError, FileId)>) { @@ -97,9 +88,7 @@ mod test { } pub(crate) fn get_program_errors(src: &str) -> Vec<(CompilationError, FileId)> { - let (_program, _context, mut errors) = get_program(src); - remove_unused_variable_warnings(&mut errors); - errors + get_program(src).2 } #[test] @@ -797,7 +786,7 @@ mod test { } "#; - let (_, _, errors) = get_program(src); + let errors = get_program_errors(src); assert!(errors.len() == 1, "Expected 1 error, got: {:?}", errors); // It should be regarding the unused variable match &errors[0].0 { @@ -874,7 +863,7 @@ mod test { } "#; - let (_, _, errors) = get_program(src); + let errors = get_program_errors(src); assert!(errors.len() == 3, "Expected 3 errors, got: {:?}", errors); // Errors are: