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

Support mutable function arguments #77

Closed
dalcde opened this issue Mar 24, 2022 · 1 comment · Fixed by #81
Closed

Support mutable function arguments #77

dalcde opened this issue Mar 24, 2022 · 1 comment · Fixed by #81

Comments

@dalcde
Copy link

dalcde commented Mar 24, 2022

auto_impl should support trait methods of the form

fn foo(&self, mut bar: Bar) {
    // default implementation that mutates bar
}
@KodrAus
Copy link
Member

KodrAus commented Jun 1, 2022

The current failure here is:

┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error: argument patterns are not supported by #[auto-impl]
 --> tests/compile-pass/self_by_value_mut.rs:9:19
  |
9 |     fn foo(&self, mut data: Data) {
  |                   ^^^^^^^^
  |
  = help: please use a simple name like "foo" (but not `_`)

error[E0057]: this function takes 1 argument but 0 arguments were supplied
  --> tests/compile-pass/self_by_value_mut.rs:7:1
   |
7  | #[auto_impl(Fn)]
   | ^^^^^^^^^^^^^^^^ an argument of type `Data` is missing
   |
note: associated function defined here
  --> $RUST/core/src/ops/function.rs
   |
   |     extern "rust-call" fn call(&self, args: Args) -> Self::Output;
   |                           ^^^^
   = note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: provide the argument
   |
7  | #[auto_impl(Fn)]({Data})
   |
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

This is just a limitation we could work around for this style of simple pattern. In the meantime, you can write:

fn foo(&self, data: Data) {
    let mut data = data;
    data.id += 1;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants