Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unused self in trait impl generates warning #6297

Closed
aakoshh opened this issue Oct 17, 2024 · 3 comments · Fixed by #6298
Closed

Unused self in trait impl generates warning #6297

aakoshh opened this issue Oct 17, 2024 · 3 comments · Fixed by #6298
Labels
bug Something isn't working

Comments

@aakoshh
Copy link
Contributor

aakoshh commented Oct 17, 2024

Aim

On my machine tests::execution_success::test_trait_impl_base_type failed with the following error:

command=`"/Users/aakoshh/Work/aztec/noir/target/debug/nargo" "--program-dir" "/Users/aakoshh/Work/aztec/noir/test_programs/execution_success/trait_impl_base_type" "execute" "--force"`
code=1
stdout=""
stderr=```
warning: unused variable self
   ┌─ /Users/aakoshh/Work/aztec/noir/test_programs/execution_success/trait_impl_base_type/src/main.nr:38:17
   │
38 │     fn to_field(self) -> Field {
   │                 ---- unused variable 

Expected Behavior

The test should compile without warning.

Bug

The method is an implementation of Fieldable::to_field. We can't use _self to silence this, and Rust does not warn about it.

To Reproduce

cargo test -p nargo_cli test_trait_impl_base_type

Workaround

Yes

Workaround Description

Add let _ = self; to the method body.

Another one suggested in the comments below is to use _self: Self (or _: Self).

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

Yes

Support Needs

No response

@aakoshh aakoshh added the bug Something isn't working label Oct 17, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Oct 17, 2024
github-merge-queue bot pushed a commit that referenced this issue Oct 18, 2024
# Description

## Problem\*

Resolves #6297 

## Summary\*

Sets `warn_if_unused` to `false` for the `self` parameter of a function
if it's for a trait implementation.

## 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.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Oct 18, 2024
@jfecher
Copy link
Contributor

jfecher commented Oct 21, 2024

The method is an implementation of Fieldable::to_field. We can't use _self to silence this, and Rust does not warn about it.

Why can't we use _self: Self?

@aakoshh
Copy link
Contributor Author

aakoshh commented Oct 21, 2024

You're right, if we specify the type as : Self we can use _self, I haven't tried that 👍

I meant that if I just try to use _self , the compiler says:

`Fieldable::to_field` expects 1 parameter, but this method has 0`.

NB the Rust compiler doesn't seem to like _self: Self:

method `to_field` has a `self` declaration in the trait, but not in the impl
expected `self` in impl`

@jfecher
Copy link
Contributor

jfecher commented Oct 21, 2024

NB the Rust compiler doesn't seem to like _self: Self:

Yep, this is a difference between Rust and Noir. Noir is a bit more permissive with methods, you don't need a self parameter to call something as a method. Just an impl and the first type must match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants