From 1df8c456d6d256f120d6df6ae3e6735cb7eb7dae Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Tue, 12 Nov 2024 18:26:55 -0300 Subject: [PATCH] fix: set local_module before elaborating each trait (#6506) --- .../noirc_frontend/src/elaborator/traits.rs | 2 ++ .../noirc_frontend/src/tests/unused_items.rs | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/compiler/noirc_frontend/src/elaborator/traits.rs b/compiler/noirc_frontend/src/elaborator/traits.rs index ae278616e03..e1be45927ca 100644 --- a/compiler/noirc_frontend/src/elaborator/traits.rs +++ b/compiler/noirc_frontend/src/elaborator/traits.rs @@ -23,6 +23,8 @@ use super::Elaborator; impl<'context> Elaborator<'context> { pub fn collect_traits(&mut self, traits: &BTreeMap) { for (trait_id, unresolved_trait) in traits { + self.local_module = unresolved_trait.module_id; + self.recover_generics(|this| { this.current_trait = Some(*trait_id); diff --git a/compiler/noirc_frontend/src/tests/unused_items.rs b/compiler/noirc_frontend/src/tests/unused_items.rs index 86f77fc397a..5f9fc887b27 100644 --- a/compiler/noirc_frontend/src/tests/unused_items.rs +++ b/compiler/noirc_frontend/src/tests/unused_items.rs @@ -294,3 +294,23 @@ fn no_warning_on_self_in_trait_impl() { "#; assert_no_errors(src); } + +#[test] +fn resolves_trait_where_clause_in_the_correct_module() { + // This is a regression test for https://github.com/noir-lang/noir/issues/6479 + let src = r#" + mod foo { + pub trait Foo {} + } + + use foo::Foo; + + pub trait Bar + where + T: Foo, + {} + + fn main() {} + "#; + assert_no_errors(src); +}