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..80b6c7db09a 100644 --- a/compiler/noirc_frontend/src/tests/unused_items.rs +++ b/compiler/noirc_frontend/src/tests/unused_items.rs @@ -210,3 +210,24 @@ 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); + assert_eq!(errors.len(), 0); +}