# VSCode rust plugin error : \[init\] function already declared

**URL:** <https://forum.dfinity.org/t/vscode-rust-plugin-error-init-function-already-declared/10186>\
**Category:** Rust\
**Created:** [January 9, 2022, 8:30am UTC](https://forum.dfinity.org/t/vscode-rust-plugin-error-init-function-already-declared/10186 "2022-01-09T08:30:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![coin\_master](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/coin_master/32/15963_2.png) [@coin\_master](https://forum.dfinity.org/u/coin_master)\
**Post date:** [January 9, 2022, 8:31am UTC](https://forum.dfinity.org/t/vscode-rust-plugin-error-init-function-already-declared/10186/1 "2022-01-09T08:31:00Z")

</div>

Hello,  
I wonder if anyone else have the same issue.  
I am following the [rust counter example](https://smartcontracts.org/docs/rust-guide/rust-counter.html)  
and I am getting an error in vscode from [rust analyzer](https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer)  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/e/e05a9d81e67d6e42b96e01ed1e5136f06a6d6fe6.png)

However running `cargo check` doesn’t show any issues.  
The issue also happens with the [main rust plugin](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust)

`"dfx": "0.8.4"`  
`rust-analyzer: v0.2.890` updating to `v0.3.896` also doesn’t solve the issue.

The issue is not a blocker but it’s just annoying.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [February 4, 2022, 10:46pm UTC](https://forum.dfinity.org/t/vscode-rust-plugin-error-init-function-already-declared/10186/2 "2022-02-04T22:46:32Z")

</div>

This is happening to me in multiple projects and I would also love for it to go away

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [February 4, 2022, 11:20pm UTC](https://forum.dfinity.org/t/vscode-rust-plugin-error-init-function-already-declared/10186/3 "2022-02-04T23:20:10Z")

</div>

Yeah, it’s on our radar. I think we’ll be able to prioritize this in the next couple of sprints

---

<div class="post-metadata">

**Author:** ![coin\_master](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/coin_master/32/15963_2.png) [@coin\_master](https://forum.dfinity.org/u/coin_master)\
**Post date:** [February 10, 2022, 3:41am UTC](https://forum.dfinity.org/t/vscode-rust-plugin-error-init-function-already-declared/10186/4 "2022-02-10T03:41:10Z")

</div>

Looks like there was an answer in another thread:  
[https://forum.dfinity.org/t/rust-error-on-pre-upgrade-and-post-upgrade-attributes/5732](https://forum.dfinity.org/t/rust-error-on-pre-upgrade-and-post-upgrade-attributes/5732)

> [@Rust error on pre\_upgrade and post\_upgrade attributes](https://forum.dfinity.org/t/rust-error-on-pre-upgrade-and-post-upgrade-attributes/5732/2):
>
> My guess that it might be purely an IDE problem. I wonder if replacing `#[pre_upgrade]` with `#[export_name = "canister_pre_upgrade"]` and `#[post_upgrade]` with `#[export_name = "canister_post_upgrade"]` could help your IDE figure out what’s going on.

changing `#init` to `#[export_name = "canister_init"]` seems to satisfy the IDE

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [February 12, 2022, 1:09am UTC](https://forum.dfinity.org/t/vscode-rust-plugin-error-init-function-already-declared/10186/5 "2022-02-12T01:09:25Z")

</div>

I this PR is aiming to address the problem.

> <https://github.com/dfinity/cdk-rs/pull/203>
>
> The linker already does this uniqueness check for us. By eliminating state from …the macro, rust-analyzer will stop causing persistent errors by carrying that state over between invocations.
