proc macro not found - rust

My main function is decorated with two proc macros like this:
#[paw::main]
#[tokio::main]
pub async fn main(args: Args) -> Result<()>
This compiles and runs as I expect it but VS code's rust-analyzer gives me this error on both lines of attribute macros #[paw::main] and #[tokio::main]. The error message is:
proc macro `main` not expanded: proc macro not found rust-analyzer (unresolved-proc-macro)

Judging by this GitHub issue, and in particular this comment, it seems that proc macro expansion is quite dependent on the version of the Rust compiler. The suggested fix is to keep your rust-analyzer updated. Switching to the pre-release version of rust-analyzer fixed this for me on rustc 1.61, which is the latest stable in time of writing. Presumably the pre-release version of rust-analyzer is always most likely to be ABI-compatible with the latest stable version of rustc.

There might be a better way, but this will make the error go away:
Go to settings and find rust-analyzer > Diagnostics: Disabled. You can search for "rust analyzer diagnostics" to find this option.
Press Add Item
Add the item unresolved-proc-macro and press OK.
Source for this solution was found here.

Related

Proc Macro with compiler error and quickfix suggestion?

I'm working on some procedural macros in Rust and I use vim-lsp to help me write Rust. I find it very helpful when the compiler error suggests a change to fix an error and I can use a quick action to apply the fix.
In my proc macros, I use syn::Error to provide spanned compiler errors for users of my macros. Is there any way for me to encode quick fixes into my compiler errors?

Use nightly rustfmt with stable compiler in CLion

I am running into an unexpected issue when it comes to toolchains in CLion. I want to use the stable channel for the compiler while using the nightly for rustfmt. The reason is that I want to use rustfmt features that are not available in the stable version. Unfortunately CLion only picks up the currently selected toolchain without any way to override or customize this and thus has not option to select the nightly of rustfmt for formatting. Is there any workaround or option I did not notice when looking for it?
In the comment there was the suggestion that cargo +nightly fmt might be what I am looking for. Even though it allows to used the nightly of rustfmt it is not integrated into the flow of CLion which seems to use the currently enabled version of the entire toolchain.
Under Clion | Preferences...:
search for formatter
select Rustfmt on the left column
add +nightly to the Additional arguments: box
check Use rustfmt instead of the built-in formatter
click Ok
Now Code | Reformat File with rustfmt should respect rustfmt nightly settings. (CLion 2022.2.4)

Android Studio IDE Syntax Highlighting Breaks after a few minutes (macOSX)

PROBLEM
The Android Studio IDE (macOSX) has issues with Syntax/Intellisense. I'm running Flutter/Dart on it to code and compile a Flutter app. I have the latest install to date and I have the latest flutter/dart sdks as of date.
If I create a new file and start working in it, something causes the syntax highlighting and intellisense to break. This appears to happen within minutes of opening up Android Studio. I have to close it and reopen it for it to resume. When it breaks, other files seem to keep their syntax highlighting, but it no longer updates if I work in them. It keeps old errors on the page regardless of the code I change. Is there a fix for this?
EDIT
I found the problem has to do with type definitions, particularly when defining a Future type for a class method.
REPRODUCE
Open up your flutter project (doesn't matter what it is).
Go to your services code (or code that works with Future).
Create a new method with a future return type with a generic specified. Do this by hand, just start typing it in, do not copy paste: Future<List<asdfasdf>>.
After writing Future<List< it should break. It should do it every time for you like it is for me.
If I'm not working with Future, it doesn't break. The way I'm getting around it is defining the method with the future before defining the generics. So I first write Future myMethod() async { } make sure the syntax is correct and there's no errors, then I go in and define the generic.

How do I configure Geany to do code completion for Rust?

I am trying to learn Rust, and I like Geany. I don't know how to do code completion with Geany. I have all of the settings turned on for it, but it only recognises C++ syntax for code completion/assist, not Rust. How can I fix this?
I don't think it is possible for Geany now, at least according to https://areweideyet.com/
For now, the most stable tool in rust for completion is rust-analyzer. It works over Language-Server Protocol, but it seems to be missing in Geany.

How do I tell VS code what toolchain I want to use?

After installing extensions for Rust, I get this error:
To properly function, the extension needs to know what toolchain you
want to use.
Press Close to select toolchain :)
The extension will provide a prompt after you close that prompt, which allows you to select the toolchain you want. You can see the toolchain that you selected in your preferences file.
As the message says, you must choose a toolchain (documentation here):
$ rustup default stable
for the stable Rust, or
$ rustup default nightly
for the newest development version.
If you only want to play with Rust, I advise you to use nightly Rust because there are more new things in it.
Add this to your configuration with toolchain you want to use to enforce it in VS Code:
"rust.rustup": {
"toolchain": "stable-x86_64-apple-darwin"
}

Resources