From 56c1a85056ed338644595f1aa58cc94563786b9e Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Tue, 28 May 2024 16:50:55 +0100 Subject: [PATCH] fix: Auto dereference trait methods in the elaborator (#5124) # Description ## Problem\* Follow-up to https://github.com/noir-lang/noir/pull/5094 ## Summary\* This was missed when moving over changes due to the turbofish operator over to the elaborato.r ## Additional Context ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** 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. --- compiler/noirc_frontend/src/elaborator/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/noirc_frontend/src/elaborator/mod.rs b/compiler/noirc_frontend/src/elaborator/mod.rs index 0581e7900f..121a4d89ef 100644 --- a/compiler/noirc_frontend/src/elaborator/mod.rs +++ b/compiler/noirc_frontend/src/elaborator/mod.rs @@ -344,8 +344,15 @@ impl<'context> Elaborator<'context> { } // Verify any remaining trait constraints arising from the function body - for (constraint, expr_id) in std::mem::take(&mut self.trait_constraints) { + for (mut constraint, expr_id) in std::mem::take(&mut self.trait_constraints) { let span = self.interner.expr_span(&expr_id); + + if matches!(&constraint.typ, Type::MutableReference(_)) { + let (_, dereferenced_typ) = + self.insert_auto_dereferences(expr_id, constraint.typ.clone()); + constraint.typ = dereferenced_typ; + } + self.verify_trait_constraint( &constraint.typ, constraint.trait_id,