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

Regression: Proc macros not being expanded #10894

Closed
jkelleyrtp opened this issue Dec 1, 2021 · 31 comments
Closed

Regression: Proc macros not being expanded #10894

jkelleyrtp opened this issue Dec 1, 2021 · 31 comments
Labels
A-macro macro expansion C-support Category: support questions S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@jkelleyrtp
Copy link
Contributor

It seems that proc macro support degraded heavily from the previous version of RA for me. In the last version, both web-sys autocomplete and proc macro inlay hints worked.

Now, it seems that RA is blind to any web-sys types (once again) and none of my proc macros are being expanded (proc macro not expanded rust-analyzerunresolved-proc-macro). My proc macro is fairly well behaved and, in the past, had significant IDE support for hovers/go-to/inlay hints.

For instance, my code

let g = rsx!(div {});

expands to

    let g = NodeFactory::annotate_lazy(move |__cx: NodeFactory| -> VNode {
        __cx.element(dioxus_elements::div, [], [], [], None)
    });

I would expect to see hints on div since I re-use the token literally, but the macro simply fails to expand.

Is there a different proc-macro server I can use that works?

rust-analyzer version: d9b2291f5 2021-11-29 stable

rustc version: rustc 1.56.1 (59eed8a2a 2021-11-01)

Screen Shot 2021-11-30 at 8 34 11 PM

@jkelleyrtp
Copy link
Contributor Author

jkelleyrtp commented Dec 1, 2021

In general, RA just seems broken across the board for me.

This code should generate an error but doesn't.

Screen Shot 2021-11-30 at 8 44 05 PM

Edit: it seems that a config is breaking RA. Haven't figure out exactly but here's what I have enabled:

  "rust-analyzer.diagnostics.enable": true,
  "rust-analyzer.updates.askBeforeDownload": true,
  "rust-analyzer.completion.autoimport.enable": true,
  "rust-analyzer.procMacro.enable": true,
  "rust-analyzer.lens.references": true,
  "rust-analyzer.inlayHints.enable": true,
  "rust-analyzer.checkOnSave.allTargets": false,
  "rust-analyzer.experimental.procAttrMacros": true,
  "rust-analyzer.inlayHints.hideNamedConstructorHints": true,
  // "rust-analyzer.updates.channel": "stable",
  "rust-analyzer.diagnostics.enableExperimental": true,
  "rust-analyzer.cargo.runBuildScripts": true,
  "rust-analyzer.checkOnSave.allFeatures": true,
  "rust-analyzer.assist.importGroup": true,

The RA LSP downloaded via the stable channel does not work for me even with all my configs disabled. However, the previous version (11-15) RA does work when I patch it in manually:

  "rust-analyzer.server.path": "~/Downloads/rust-analyzer-aarch64-apple-darwin",

I'm running an m1 Mac in case RA is downloading the wrong binary.

@Veykril Veykril added the A-macro macro expansion label Dec 1, 2021
@Veykril
Copy link
Member

Veykril commented Dec 1, 2021

I assume the version of dioxus you are using is not the current one on crates io right? As your snippet doesn't compile for me at all.

@al2me6
Copy link

al2me6 commented Dec 12, 2021

Are there any updates on this issue? Proc macro expansion seems to have entirely stopped working after I upgraded to rustc 1.59.0-nightly (928783de6 2021-12-11), with both release and nightly RA.

(This can be seen by opening https://github.com/al2me6/evanescence using RA.)

@lnicola
Copy link
Member

lnicola commented Dec 13, 2021

Are there any updates on this issue?

@al2me6 the proc macro ABI sometimes changes in nightly (which is to be expected), and rust-analyzer needs to be updated.

CC @alexjg

@lnicola
Copy link
Member

lnicola commented Dec 13, 2021

I'm running an m1 Mac in case RA is downloading the wrong binary.

Are you running the x86 version of Code instead of the native M1 one?

bors bot added a commit that referenced this issue Dec 13, 2021
11002: fix: Add support for v6 macro metadata format r=lnicola a=lnicola

CC #10894 (comment)

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
@lnicola
Copy link
Member

lnicola commented Dec 13, 2021

@al2me6 can you try with the next RA nightly? This seems to work now for me.

image

@alexjg false alert :-).

@al2me6
Copy link

al2me6 commented Dec 13, 2021

evanescence_web/src/state.rs`, for example, seems to be still broken:

image

That same file is also still broken for me:

image

With
image

@lnicola
Copy link
Member

lnicola commented Dec 13, 2021

@al2me6 you need to try with the next nightly.

image

@pwaller
Copy link

pwaller commented Dec 13, 2021

FYI I just tried on 791722b (verified with version output in vscode) and still don't have proc macros being resolved.
This turned out to be PEBKAC, it works now (I discovered from the log that I had procMacros set to false somewhere, and now it works with rust stable 1.57.0. Rust nightly still doesn't appear to work)

@Veykril Veykril added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Dec 17, 2021
@bobbbay
Copy link

bobbbay commented Jan 15, 2022

Bump: I'm getting this a lot and it's making it hard to read my code. Any thoughts on how to fix this?

@Veykril
Copy link
Member

Veykril commented Jan 15, 2022

whats your rust version and rust-analyzer version

@bobbbay
Copy link

bobbbay commented Jan 15, 2022

$ rustc --version
rustc 1.57.0 (f1edd0429 2021-11-29)
$ rust-analyzer --version
rust-analyzer 2021-10-25

@Veykril
Copy link
Member

Veykril commented Jan 15, 2022

That rust-analyzer version is heavily outdated which might be the reason for your troubles, try updating to the latest release.

@bobbbay
Copy link

bobbbay commented Jan 15, 2022

Updated to 2021-12-27, the newest version packaged for my distribution. I still have this issue. Should I switch to a manual installation via binary to get to 2022-01-10?

@Veykril
Copy link
Member

Veykril commented Jan 15, 2022

That one should probably work. Not sure what could be causing this then without a reproduction/more info

@vorporeal
Copy link

I'm running into this issue using the nightly toolchain with VSCode rust-analyzer extension.

$ ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rust-analyzer --version
rust-analyzer 9700add 2022-01-30 dev

Example code that reproduces the issue for me:

use clap::Parser;

#[derive(Parser, Debug)]
struct Args {
}

fn main() {
    let args = Args::parse();
}

image

@lukekeum
Copy link

lukekeum commented Feb 3, 2022

Did you guys tried to download rust-analyzer to your bin and add path to "rust-analyzer.server.path" in "settings.json" which is in vscode ?

This worked me

@Palladinium
Copy link

I can confirm this is still an issue.

2022-02-04_12_23_745228021

rust-analyzer was installed with cargo install rust-analyzer --git https://github.com/rust-analyzer/rust-analyzer.git --locked
Running in Spacemacs with the Rust layer.

$ rustc --version
rustc 1.60.0-nightly (27f5d830e 2022-02-02)
$ rust-analyzer --version
rust-analyzer 9597e55e9 2022-02-04 dev

I am positive this is the only version of rust-analyzer I have installed - Spacemacs does not install its own version.

@flodiebold
Copy link
Member

Works for me with both stable and nightly Rust.

It'd be nice if we could show some more information when we're emitting this error (whether proc macros are disabled would be one thing, but also maybe we're dropping / only logging some errors that can lead to this?)

@Palladinium
Copy link

Digging a bit deeper it turns out that yes, I simply didn't correctly enable proc-macros in the LSP config.
For anyone else in my same situation, the answer was (setq-default lsp-rust-analyzer-proc-macro-enable t).

I agree that it'd be nice to have more informative errors. Something along the lines of proc-macro expansion disabled in configuration would help separate user configuration errors from legitimate rust-analyzer errors.

@alxiong
Copy link

alxiong commented Feb 12, 2022

I also run into this problem on Doom Emacs, I use rust-analyzer ba3305480 2022-02-07 stable and rustc 1.56.1 (59eed8a2a 2021-11-01).

I'm sure my lsp-rust-analyzer-proc-macro-enable is set to t, in fact I have no problem expand locally declared macro, but failed to correctly expand foreign (imported) proc macro.

(btw, I also confirm the output of expanded code on vscode via "Rust Analyzer: Expand macro recursively" to perfectly matched that of my emacs, both have no issue with locally defined macro, but both failed with imported macro)

@flodiebold flodiebold added the C-support Category: support questions label Mar 31, 2022
@flodiebold
Copy link
Member

Let's close this since the original issue is not reproducible, and the ticket risks becoming a dumping ground for proc macro expansion problems.

@cloutiertyler
Copy link

@flodiebold I think this issue may be related to the M1 Mac aspect of things. I am currently getting these errors in VSCode running the latest version of pre-release rust-analyzer and getting the following error. Seems to be an x86 vs arm issue.

[{
	"resource": "./crates/spacetimedb/src/routes/mod.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 `Deserialize` not expanded: Cannot create expander for ./target/debug/deps/libserde_derive-88182fb8c70c39d8.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: \"dlopen(./target/debug/deps/libserde_derive-88182fb8c70c39d8.dylib, 0x000A): tried: \\'./target/debug/deps/libserde_derive-88182fb8c70c39d8.dylib\\' (mach-o file, but is an incompatible architecture (have \\'x86_64\\', need \\'arm64e\\'))\" } })",
	"source": "rust-analyzer",
	"startLineNumber": 19,
	"startColumn": 10,
	"endLineNumber": 19,
	"endColumn": 21
}]```

@lnicola
Copy link
Member

lnicola commented Jun 18, 2022

@cloutiertyler you should file a new issue if you still have trouble. My guess is that you're either running the x86 version of Code, or you have a stale target directory from an x86.

@isosphere
Copy link

Chiming in to say I had an issue with this when writing a fresh derive macro, and it went away when I reloaded rust-analyzer (rust-analyzer: Restart Server in VSCode).

My precise output from rust-analyzer was "Proc macro not expanded: no proc macro dynlib present".

@moutikabdessabour
Copy link

Had the same issue, I am using leptos with rust nightly. But I had installed rust-analyzer manually not with rust-up. so I removed it and reinstalled it with rustup and installed the nightly toolchain again. and everything works

@joelong01
Copy link

for me, the issue turned out to be that I had a sub project in my repo that I decided to delete and remove...but the vscode/settings.json had this in it:

{
"rust-analyzer.linkedProjects": [
"./Cargo.toml",
"./Deleted_Project/Cargo.toml"
]
}

I deleted the "./Deleted_Project/Cargo.toml" line and the problem went away

i'td be awesome if rust-analyzer reported that I was asking for it to link to a project that no longer existed and stopped executing.

@spraza
Copy link

spraza commented Oct 30, 2023

Just had the same issue and the root cause seemed to be what @joelong01 mentioned above, since removing the stale project fixed the issue for me. +1 to that it'd be great if rust-analyzer points to the right root cause here.

@shitcodebykaushik
Copy link

The Problem is coming at the root of the project file.
I am still figuring out how to solve with the nighty rust .

@Veykril
Copy link
Member

Veykril commented May 13, 2024

Please open a new issue and fill out the template, including what operating system you are on and what error(s) you are getting

@silvio2402
Copy link

I encountered this issue with rustc 1.76.0 (07dca489a 2024-02-04). After updating to rustc 1.78.0 (9b00956e5 2024-04-29) the error is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion 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