Skip to content

proc macro * not expanded: proc macro not found #12610

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

Closed
arturoc opened this issue Jun 21, 2022 · 32 comments
Closed

proc macro * not expanded: proc macro not found #12610

arturoc opened this issue Jun 21, 2022 · 32 comments
Labels
A-proc-macro proc macro C-support Category: support questions S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@arturoc
Copy link

arturoc commented Jun 21, 2022

rust-analyzer version: 6fc5c3c 2022-06-20

rustc version: (latest stable) rustc 1.61.0 (fe5b13d68 2022-05-18)

Since last week, rust analyzer shows several errors for proc macros not found including sometimes cfg_attr in the header of some files where there's no apparent cfg_attr.

Until yesterday's update the errors used to go away after a while but with yesterdays version and with latest pre-release the errors stay.

@flodiebold
Copy link
Member

Please report the concrete examples, otherwise it's impossible to tell what's going on. These might be proc macros declared with cfg(not(test)), in which case this is mostly fixed by #12599, or it might be some other reason.

@flodiebold flodiebold added S-unactionable Issue requires feedback, design decisions or is blocked on other work C-support Category: support questions A-proc-macro proc macro labels Jun 21, 2022
@vvilhonen
Copy link

rust-analyzer v0.3.1099

dependencies

tokio = { version = "1.19.2", features = ["full"] }
#[tokio::main]
async fn main() {
    println!("Hello, world!");
}
[{
	"resource": "/src/main.rs",
	"owner": "rustc",
	"code": {
		"value": "unresolved-proc-macro",
		"target": {
			"$mid": 1,
			"external": "https://rust-analyzer.github.io/manual.html#unresolved-proc-macro",
			"path": "/manual.html",
			"scheme": "https",
			"authority": "rust-analyzer.github.io",
			"fragment": "unresolved-proc-macro"
		}
	},
	"severity": 8,
	"message": "proc macro `main` not expanded: proc macro not found",
	"source": "rust-analyzer",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 1,
	"endColumn": 15
}]

@flodiebold
Copy link
Member

tokio::main is #12450, which should be fixed in the next release.

@cisaacson
Copy link

I have the same issue using ifmt, which has the iwriteln! macro.

The error message is:

proc macro proc_macro_fake_call_site_iwriteln not expanded: proc macro not foundrust-analyzer

It looks like the error prints out for every usage, so 100s of times in my case.

The use statement is:

use ifmt::{iwrite, iwriteln};

After that all other use statements show errors, the repeating message above. cargo check runs with no errors.

An example usage of this macro is:

iwriteln!(code, module_header)?;

As the original report said, this used to show up sometimes and go away. Even after restarting rust-analyzer the spurious error remains.

I must say that rust-analyzer has gotten so much better recently, once you get this fixed it will be awesome.

@flodiebold
Copy link
Member

Opened #12614 for ifmt.

@rib
Copy link

rib commented Jun 23, 2022

Hi, I'm currently seeing this with clap:

E.g. with the stub program:

use clap::Parser;

#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Args {
}

fn main() {

}

Cargo.toml:
clap = { version = "3.2.6", features = ["derive"]}

Then I get this error from rust-analyzer:

proc macro clap not expanded: proc macro not found

(Although the code itself builds fine without any errors/warnings via cargo)

rustc 1.61.0 (fe5b13d68 2022-05-18)
rust-analyzer: v0.4.1102 (also saw the same thing with the stable release before trying this pre-release)

@flodiebold
Copy link
Member

@rib I can't reproduce this with either the stable or the pre-release. What does the Show RA Version command say?

@arturoc
Copy link
Author

arturoc commented Jun 23, 2022

I've noticed this doesn't always happens. It just happened to me by pulling latest changes from git while vs code is open. Closing vs code and reopening again fixes it in some cases. I'll try to reproduce it on a minimal example.

@alice-i-cecile
Copy link

I can reproduce this with the tokio snippet above, with RA version v0.4.1102.

@flodiebold
Copy link
Member

@alice-i-cecile What's the precise error message, and what does Show RA Version say?

@juanmait
Copy link

juanmait commented Jun 23, 2022

same issue with tokio. Show RA Version says rust-analyzer version: 0.0.0 (427061da1 2022-06-19)

Message says proc macro main not expanded: proc macro not found

The Quick fix suggestions is saying: "Remove unnecessary async"

@alice-i-cecile
Copy link

rust-analyzer version: 0.0.0 (427061d 2022-06-19)
proc macro main not expanded: proc macro not found

@flodiebold
Copy link
Member

@juanmait @alice-i-cecile That version is older than the fix for the tokio::main problem. If you install the pre-release, I'd expect you to get a newer version though (2022-06-20 or now 2022-06-23 with extension version 0.4.1103).

@Milo123459
Copy link
Contributor

Not sure if it matters, but also happening with sqlx.

@flodiebold
Copy link
Member

flodiebold commented Jun 25, 2022

@Milo123459 If you can reproduce this with the newest pre-release version of rust-analyzer, it would be helpful if you can report a new issue for this. Ideally with a small example project, because sqlx issues are usually hard to reproduce without a bunch of setup.

@Milo123459
Copy link
Contributor

It only happens occasionally, but I'll try.

@JOSBEAK
Copy link

JOSBEAK commented Jun 27, 2022

Hi I am currently seeing this with tokio :
regenerate it :

#[tokio::main]
async fn main() {
    println!("Hello, world!");
}

Cargo.toml

tokio = { version = "1.19.2", features = ["full"] }

@flodiebold
Copy link
Member

@JOSBEAK what's your extension version, and what does the "Show RA version" command say?

@JOSBEAK
Copy link

JOSBEAK commented Jun 27, 2022

@flodiebold Actually it just worked after doing a simple extension reload 👍🏼 Thanks :)

@mattbradbury
Copy link

mattbradbury commented Jun 28, 2022

Having the same issue. I just created this from scratch on an M1 with an up to date rustup. Compiles fine and the html! macro works correctly in the output.

I get this error in the tooltip:

proc macro not expanded: proc macro not found rust-analyzer[unresolved-proc-macro]

When I Ctrl-Click I go straight to the downloaded source file for the macro.

main.rs

use yew::Component;
use yew::html;

struct Test;

impl Component for Test {
    type Message = ();
    type Properties = ();
    fn create(_ctx: &yew::Context<Self>) -> Self {
        Test {}
    }
    fn view(&self, _ctx: &yew::Context<Self>) -> yew::Html {
        // Line below is red-underlined by RA
        html!(<div>{"Hello World"}</div>)
    }
}

fn main() {
    yew::start_app::<Test>();
}

cargo.toml
yew = "0.19.3"

ra-version: rust-analyzer version: 0.0.0 (9eaf96c9e 2022-06-27)

Also used the non pre-release rust-analyzer version: 0.0.0 (b74e96f50 2022-06-26) and got the same error

Edit: I've restarted VSCode several times

@flodiebold
Copy link
Member

@mattbradbury Can you please set RA_LOG to warn;project_model=info in rust-analyzer.server.extraEnv, restart the server, and provide the contents of the Rust Analyzer Language Server output tab?

@mattbradbury
Copy link

mattbradbury commented Jun 28, 2022

@flodiebold Here's the results. Interesting extra findings below them.

[WARN rust_analyzer::reload] proc-macro loading for /Users/bradbury/src/test1/target/debug/deps/libproc_macro_error_attr-15aee3621757800e.dylib failed: Cannot create expander for /Users/bradbury/src/test1/target/debug/deps/libproc_macro_error_attr-15aee3621757800e.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(/Users/bradbury/src/test1/target/debug/deps/libproc_macro_error_attr-15aee3621757800e.dylib, 10): no suitable image found.  Did find:\n\t/Users/bradbury/src/test1/target/debug/deps/libproc_macro_error_attr-15aee3621757800e.dylib: mach-o, but wrong architecture\n\t/Users/bradbury/src/test1/target/debug/deps/libproc_macro_error_attr-15aee3621757800e.dylib: mach-o, but wrong architecture" } })
[WARN rust_analyzer::reload] proc-macro loading for /Users/bradbury/src/test1/target/debug/deps/libserde_derive-e0ca39a2b696cc24.dylib failed: Cannot create expander for /Users/bradbury/src/test1/target/debug/deps/libserde_derive-e0ca39a2b696cc24.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(/Users/bradbury/src/test1/target/debug/deps/libserde_derive-e0ca39a2b696cc24.dylib, 10): no suitable image found.  Did find:\n\t/Users/bradbury/src/test1/target/debug/deps/libserde_derive-e0ca39a2b696cc24.dylib: mach-o, but wrong architecture\n\t/Users/bradbury/src/test1/target/debug/deps/libserde_derive-e0ca39a2b696cc24.dylib: mach-o, but wrong architecture" } })
[WARN rust_analyzer::reload] proc-macro loading for /Users/bradbury/src/test1/target/debug/deps/libthiserror_impl-4bcb25d5354f1bf3.dylib failed: Cannot create expander for /Users/bradbury/src/test1/target/debug/deps/libthiserror_impl-4bcb25d5354f1bf3.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(/Users/bradbury/src/test1/target/debug/deps/libthiserror_impl-4bcb25d5354f1bf3.dylib, 10): no suitable image found.  Did find:\n\t/Users/bradbury/src/test1/target/debug/deps/libthiserror_impl-4bcb25d5354f1bf3.dylib: mach-o, but wrong architecture\n\t/Users/bradbury/src/test1/target/debug/deps/libthiserror_impl-4bcb25d5354f1bf3.dylib: mach-o, but wrong architecture" } })
[WARN rust_analyzer::reload] proc-macro loading for /Users/bradbury/src/test1/target/debug/deps/libwasm_bindgen_macro-f598390ca3726057.dylib failed: Cannot create expander for /Users/bradbury/src/test1/target/debug/deps/libwasm_bindgen_macro-f598390ca3726057.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(/Users/bradbury/src/test1/target/debug/deps/libwasm_bindgen_macro-f598390ca3726057.dylib, 10): no suitable image found.  Did find:\n\t/Users/bradbury/src/test1/target/debug/deps/libwasm_bindgen_macro-f598390ca3726057.dylib: mach-o, but wrong architecture\n\t/Users/bradbury/src/test1/target/debug/deps/libwasm_bindgen_macro-f598390ca3726057.dylib: mach-o, but wrong architecture" } })
[WARN rust_analyzer::reload] proc-macro loading for /Users/bradbury/src/test1/target/debug/deps/libyew_macro-bf62b6065c107422.dylib failed: Cannot create expander for /Users/bradbury/src/test1/target/debug/deps/libyew_macro-bf62b6065c107422.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(/Users/bradbury/src/test1/target/debug/deps/libyew_macro-bf62b6065c107422.dylib, 10): no suitable image found.  Did find:\n\t/Users/bradbury/src/test1/target/debug/deps/libyew_macro-bf62b6065c107422.dylib: mach-o, but wrong architecture\n\t/Users/bradbury/src/test1/target/debug/deps/libyew_macro-bf62b6065c107422.dylib: mach-o, but wrong architecture" } })

I saw that my VsCode is running emulated in Rosetta (Intel version here on out). I downloaded the Apple Silicon version, ran it from the zip file and Rust Analyzer started working correctly. I went back to the Intel version and rust-analyzer is working correctly now in both versions.

This felt a bit fishy so I started looking around. I noticed that while in the Intel version it said the RA extension needed a Reload. So I reloaded and the the OG error re-appeared. Closed the Intel, opened the Silicon version and the same error was happening in the Silicon version. Again the Reload Required message appeared in the extension. Upon reloading it works again. And again when i switch to the Intel version it's still working. As long as I don't click the Reload Required on the extension it seems to work fine. I did this roundtrip 3 or 4 times with no variation in behavior. Still don't know why the Silicon version worked immediately. Maybe some architecture specific files were missing and it downloaded the Silicon RA version on first start.

In conclusion:

It appears that the extension downloaded while Silicon works fine, the extension downloaded for Intel is borked.

Maybe a separate Intel version is no longer needed for M1 machines?

Hope this helps and I'll add anything else that can help, just ask.

Oh, btw, in Silicon version the RA versions are the same as Intel for release and pre-release and the behavior was the same as above when switching between Silicon and Intel pre-release versions.

@flodiebold
Copy link
Member

flodiebold commented Jun 28, 2022

You currently need to be using the same architecture (intel vs. ARM) for rust-analyzer as your rust toolchain. And VSCode will download the extension for its own architecture, so unless you're using a separate rust-analyzer you're getting the one matching the VSCode architecture. Hence why it only works with the extension downloaded by the ARM version. This will be fixed by #12579.

I'm a bit confused why it showed "proc macro not found" instead of the architecture mismatch. I suspect the errors are sometimes getting lost somewhere on the way somehow, I'm also seeing this when the proc macro build isn't finished yet 🤔

Edit: Found it, #12648.

@ajf-sa
Copy link

ajf-sa commented Jun 28, 2022

problem in my case

my system MacOS m1
rust-lang.rust-analyzer : version 0.4.1108

#[tokio::main(flavor = "current_thread")]
async fn main() {
    Args::parse(matches())
        .map(serve)
        .unwrap_or_else(handle_err)
        .await
        .unwrap_or_else(handle_err);
}

error show message

proc macro `main` not expanded: Cannot create expander for /Users/p/Documents/projects/github/private/static-file/app/target/debug/deps/libtokio_macros-596412c618b55b4d.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(/Users/p/Documents/projects/github/private/static-file/app/target/debug/deps/libtokio_macros-596412c618b55b4d.dylib, 0x000A): tried: \'/Users/p/Documents/projects/github/private/static-file/app/target/debug/deps/libtokio_macros-596412c618b55b4d.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })

my try to solve it

use tokio::main; // that should fix error


#[main(flavor = "current_thread")]
async fn main() {
    Args::parse(matches())
        .map(serve)
        .unwrap_or_else(handle_err)
        .await
        .unwrap_or_else(handle_err);
}

@bjorn3
Copy link
Member

bjorn3 commented Jun 28, 2022

@alfuhigi Your problem is the exact opposite of @mattbradbury. You are using an arm64 version of vscode, but you are using an x86_64 version of rustc. Switching to the aarch64-apple-darwin version should work.

@ajf-sa
Copy link

ajf-sa commented Jun 28, 2022

@bjorn3 I try it on windows 10 inel x86_64 version vscode , rustc 1.61.0 (fe5b13d68 2022-05-18)
and stil geting error if i use code like this:

#[tokio::main(flavor = "current_thread")]
async fn main() { ....

proc macro "main" not expanded: proc macro not found unresolved-proc-macro

this code work fine for me !

use tokio::main;
#[main(flavor = "current_thread")]
async fn main() {...

@flodiebold
Copy link
Member

flodiebold commented Jun 28, 2022

@alfuhigi that the error doesn't show up when you import the macro is a bug, #12649. I would not recommend changing it to that since it will actually make the situation worse for rust-analyzer, you just don't see it.

Try to make sure you've got the newest version of the extension running on the Windows PC -- what does the Show RA Version command say?

@mattbradbury
Copy link

@flodiebold FYI, this morning I installed the x86_64 toolchain and mostly had the same behavior in reverse, except that in the Arm64 version of VsCode it didn't put the 'Reload Required' tag on the RA Extension in the Extensions pane.

Apparently I've been running my setup with Arm64 toolchain and Intel VsCode since I got this Mac a year and a half ago. Something changed in the last week or so to break this.

@flodiebold
Copy link
Member

@mattbradbury Nothing broke it, it never worked. We just didn't show the error as prominently before.

@flodiebold
Copy link
Member

Let's close this. If you're still encountering proc macro issues, please

  1. make sure they're reproducible with the newest pre-release of the extension;
  2. on M1 Macs, check that your VSCode architecture matches the rust toolchain architecture, and
  3. check that you're not using a very recent rust nightly, since that's currently known to be broken.

If so, please open a new ticket with the code that results in the error, and the full error message.

@flodiebold flodiebold closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2022
@jplatte
Copy link
Contributor

jplatte commented Jun 29, 2022

check that you're not using a very recent rust nightly, since that's currently known to be broken.

Which issue should I watch to know when that's fixed?

@flodiebold
Copy link
Member

#12600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macro proc macro C-support Category: support questions S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests