From f755eb439012c75bf1056520491e7d2492a2a18e Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Tue, 8 Oct 2024 12:12:01 +0100 Subject: [PATCH 1/2] do not warn when a nested struct is provided as input to main --- compiler/noirc_frontend/src/elaborator/mod.rs | 12 +++------- .../noirc_frontend/src/tests/unused_items.rs | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/compiler/noirc_frontend/src/elaborator/mod.rs b/compiler/noirc_frontend/src/elaborator/mod.rs index bd78febc1d0..ddbb80e2bfc 100644 --- a/compiler/noirc_frontend/src/elaborator/mod.rs +++ b/compiler/noirc_frontend/src/elaborator/mod.rs @@ -846,6 +846,9 @@ impl<'context> Elaborator<'context> { for generic in generics { self.mark_parameter_type_as_used(generic); } + for (_, typ) in struct_type.borrow().get_fields(generics) { + self.mark_parameter_type_as_used(&typ); + } } Type::Alias(alias_type, generics) => { self.mark_parameter_type_as_used(&alias_type.borrow().get_type(generics)); @@ -872,15 +875,6 @@ impl<'context> Elaborator<'context> { | Type::Forall(..) | Type::Error => (), } - - if let Type::Alias(alias_type, generics) = typ { - self.mark_parameter_type_as_used(&alias_type.borrow().get_type(generics)); - return; - } - - if let Type::Struct(struct_type, _generics) = typ { - self.mark_struct_as_constructed(struct_type.clone()); - } } fn run_function_lints(&mut self, func: &FuncMeta, modifiers: &FunctionModifiers) { diff --git a/compiler/noirc_frontend/src/tests/unused_items.rs b/compiler/noirc_frontend/src/tests/unused_items.rs index 4d8e504b705..9f5a079b90b 100644 --- a/compiler/noirc_frontend/src/tests/unused_items.rs +++ b/compiler/noirc_frontend/src/tests/unused_items.rs @@ -210,3 +210,25 @@ fn warns_on_unused_global() { assert_eq!(ident.to_string(), "foo"); assert_eq!(item.item_type(), "global"); } + +#[test] +fn no_warning_on_inner_struct_when_parent_is_used() { + let src = r#" + struct Bar { + inner: [Field; 3], + } + + struct Foo { + a: Field, + bar: Bar, + } + + fn main(foos: [Foo; 1]) { + assert_eq(foos[0].a, 10); + } + "#; + + let errors = get_program_errors(src); + println!("{errors:?}"); + assert_eq!(errors.len(), 0); +} From 61782298d2f442ec3b015587878d3b4a60cfdb59 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Tue, 8 Oct 2024 07:16:17 -0400 Subject: [PATCH 2/2] Update compiler/noirc_frontend/src/tests/unused_items.rs --- compiler/noirc_frontend/src/tests/unused_items.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/noirc_frontend/src/tests/unused_items.rs b/compiler/noirc_frontend/src/tests/unused_items.rs index 9f5a079b90b..80b6c7db09a 100644 --- a/compiler/noirc_frontend/src/tests/unused_items.rs +++ b/compiler/noirc_frontend/src/tests/unused_items.rs @@ -229,6 +229,5 @@ fn no_warning_on_inner_struct_when_parent_is_used() { "#; let errors = get_program_errors(src); - println!("{errors:?}"); assert_eq!(errors.len(), 0); }