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

Rust analyzer marks proc macros as errors #12538

Closed
saadjhk opened this issue Jun 14, 2022 · 44 comments
Closed

Rust analyzer marks proc macros as errors #12538

saadjhk opened this issue Jun 14, 2022 · 44 comments
Labels
A-proc-macro proc macro C-support Category: support questions

Comments

@saadjhk
Copy link

saadjhk commented Jun 14, 2022

rust-analyzer version: v0.3.1091

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

When using IntEnum proc macro rust analyzer gives the error:

proc macro IntEnum not expanded rust-analyzer unresolved-proc-macro

@tommyip

This comment was marked as resolved.

@bjorn3

This comment was marked as resolved.

@tommyip

This comment was marked as resolved.

@bjorn3

This comment was marked as resolved.

@bjorn3 bjorn3 reopened this Jun 15, 2022
@Veykril Veykril added the A-proc-macro proc macro label Jun 15, 2022
@dreamerlzl
Copy link

dreamerlzl commented Jun 16, 2022

Same problem with rust-analyzer 2022-06-06, rustc 1.63.0-nightly (b31f9cc22 2022-06-15).
I am using neovim with lsp.

@flodiebold
Copy link
Member

@dreamerlzl you need a newer version of rust-analyzer to get support for this rustc nightly.

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

@saadjhk Please try the current nightly; it should show a more detailed error message.

@axyiee
Copy link

axyiee commented Jun 16, 2022

Install the latest version of rust-analyzer. If you are using VSCode, download the .vsix file in releases and install it by using the Extensions => Install from VSIX feature, since it seems to be not available in the marketplace yet.

@flodiebold
Copy link
Member

As far as I can tell, the pre-release in the marketplace is from yesterday and does contain the relevant commits.

@axyiee
Copy link

axyiee commented Jun 16, 2022

Member

@flodiebold ** flodiebold ** commented 2 hours ago

That's strange, for me it have this issue of proc macros not being expanded, while the VSIX does not.

@flodiebold
Copy link
Member

@eexsty Are you using VSCode or VSCodium?

@axyiee
Copy link

axyiee commented Jun 16, 2022

@eexsty Are you using VSCode or VSCodium?

VSCode

@dreamerlzl
Copy link

dreamerlzl commented Jun 17, 2022

@dreamerlzl you need a newer version of rust-analyzer to get support for this rustc nightly.

Thank you flodiebold! That's the latest version one can get from homebrew(I am using mac).
I tried with the latest release rust-analyzer 0.0.0 (7322a98 2022-06-16), still a similar error encountered(cargo check & build works fine):

image

The log entry in lsp.log is the following

[DEBUG][2022-06-17 16:31:22] .../vim/lsp/rpc.lua:454	"rpc.receive"	{  jsonrpc = "2.0",  method = "textDocument/publishDiagnostics",  params = {    diagnostics = { {        code = "unresolved-proc-macro",        codeDescription = {          href = "https://rust-analyzer.github.io/manual.html#unresolved-proc-macro"        },        message = "proc macro `clap` not expanded: proc macro not found",        range = {          end = {            character = 23,            line = 12          },          start = {            character = 0,            line = 12          }        },        severity = 1,        source = "rust-analyzer"      } },    uri = "secret",    version = 0  }}

@Veykril
Copy link
Member

Veykril commented Jun 17, 2022

The diagnostics log isn't relevant.
Can you set the RA_LOG env var for the server to "warn,project_model=info" and paste your logs?

@dreamerlzl
Copy link

@Veykril Hi, thanks for your guide! However, after setting the env var, I can't find any useful info from the log. Could you please give some hint? The log itself is too long to put it here.

@Veykril
Copy link
Member

Veykril commented Jun 17, 2022

There should definitely be useful information in those logs now, why is it too long? This shouldn't be logging too much

@brianbruggeman

This comment was marked as resolved.

@Veykril
Copy link
Member

Veykril commented Jun 17, 2022

Those mbe::expander::transcriber errors aren't relevant for proc-macros, those are macro_rules errors.

The logs with that env var set should contain some info logs that states what proc-macros have been loaded, those would be of interest (basically all the logs coming from project_model)

@brianbruggeman
Copy link

These appear to be the errors. I have an M1 Mac pro.

In particular, it looks like an architecture issue (M1 vs an assumed x86_64).

[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libasync_recursion-e7597ac493dcaf16.dylib failed: Cannot create expander for <redacted>/debug/deps/libasync_recursion-e7597ac493dcaf16.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libasync_recursion-e7597ac493dcaf16.dylib, 0x000A): tried: \'<redacted>/debug/deps/libasync_recursion-e7597ac493dcaf16.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libasync_trait-c02af3e5ded98856.dylib failed: Cannot create expander for <redacted>/debug/deps/libasync_trait-c02af3e5ded98856.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libasync_trait-c02af3e5ded98856.dylib, 0x000A): tried: \'<redacted>/debug/deps/libasync_trait-c02af3e5ded98856.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libclap_derive-23f5130148fc3df2.dylib failed: Cannot create expander for <redacted>/debug/deps/libclap_derive-23f5130148fc3df2.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libclap_derive-23f5130148fc3df2.dylib, 0x000A): tried: \'<redacted>/debug/deps/libclap_derive-23f5130148fc3df2.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libdarling_macro-1950e851acec16d0.dylib failed: Cannot create expander for <redacted>/debug/deps/libdarling_macro-1950e851acec16d0.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libdarling_macro-1950e851acec16d0.dylib, 0x000A): tried: \'<redacted>/debug/deps/libdarling_macro-1950e851acec16d0.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libfailure_derive-df4479d6777433d8.dylib failed: Cannot create expander for <redacted>/debug/deps/libfailure_derive-df4479d6777433d8.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libfailure_derive-df4479d6777433d8.dylib, 0x000A): tried: \'<redacted>/debug/deps/libfailure_derive-df4479d6777433d8.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libfutures_macro-697fca8cc948c039.dylib failed: Cannot create expander for <redacted>/debug/deps/libfutures_macro-697fca8cc948c039.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libfutures_macro-697fca8cc948c039.dylib, 0x000A): tried: \'<redacted>/debug/deps/libfutures_macro-697fca8cc948c039.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libinclude_dir_macros-15beb622ddbed0b3.dylib failed: Cannot create expander for <redacted>/debug/deps/libinclude_dir_macros-15beb622ddbed0b3.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libinclude_dir_macros-15beb622ddbed0b3.dylib, 0x000A): tried: \'<redacted>/debug/deps/libinclude_dir_macros-15beb622ddbed0b3.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libpin_project_internal-dbc83b681a0f8e73.dylib failed: Cannot create expander for <redacted>/debug/deps/libpin_project_internal-dbc83b681a0f8e73.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libpin_project_internal-dbc83b681a0f8e73.dylib, 0x000A): tried: \'<redacted>/debug/deps/libpin_project_internal-dbc83b681a0f8e73.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libproc_macro_error_attr-17b3750f3be93995.dylib failed: Cannot create expander for <redacted>/debug/deps/libproc_macro_error_attr-17b3750f3be93995.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libproc_macro_error_attr-17b3750f3be93995.dylib, 0x000A): tried: \'<redacted>/debug/deps/libproc_macro_error_attr-17b3750f3be93995.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/librsb_derive-48cea39863f31151.dylib failed: Cannot create expander for <redacted>/debug/deps/librsb_derive-48cea39863f31151.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/librsb_derive-48cea39863f31151.dylib, 0x000A): tried: \'<redacted>/debug/deps/librsb_derive-48cea39863f31151.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/librstest-b1e56480a50adec4.dylib failed: Cannot create expander for <redacted>/debug/deps/librstest-b1e56480a50adec4.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/librstest-b1e56480a50adec4.dylib, 0x000A): tried: \'<redacted>/debug/deps/librstest-b1e56480a50adec4.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/librvs_derive-cbd2ebe3a8372e60.dylib failed: Cannot create expander for <redacted>/debug/deps/librvs_derive-cbd2ebe3a8372e60.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/librvs_derive-cbd2ebe3a8372e60.dylib, 0x000A): tried: \'<redacted>/debug/deps/librvs_derive-cbd2ebe3a8372e60.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libserde_derive-5fd4729769f4a066.dylib failed: Cannot create expander for <redacted>/debug/deps/libserde_derive-5fd4729769f4a066.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libserde_derive-5fd4729769f4a066.dylib, 0x000A): tried: \'<redacted>/debug/deps/libserde_derive-5fd4729769f4a066.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libserde_with_macros-ce93a0deb33d545f.dylib failed: Cannot create expander for <redacted>/debug/deps/libserde_with_macros-ce93a0deb33d545f.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libserde_with_macros-ce93a0deb33d545f.dylib, 0x000A): tried: \'<redacted>/debug/deps/libserde_with_macros-ce93a0deb33d545f.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libthiserror_impl-983f34bb434dee2a.dylib failed: Cannot create expander for <redacted>/debug/deps/libthiserror_impl-983f34bb434dee2a.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libthiserror_impl-983f34bb434dee2a.dylib, 0x000A): tried: \'<redacted>/debug/deps/libthiserror_impl-983f34bb434dee2a.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libtokio_macros-c7147c5e60674f0b.dylib failed: Cannot create expander for <redacted>/debug/deps/libtokio_macros-c7147c5e60674f0b.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libtokio_macros-c7147c5e60674f0b.dylib, 0x000A): tried: \'<redacted>/debug/deps/libtokio_macros-c7147c5e60674f0b.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })
[WARN rust_analyzer::reload] proc-macro loading for <redacted>/debug/deps/libtracing_attributes-a938b66e0ee304c1.dylib failed: Cannot create expander for <redacted>/debug/deps/libtracing_attributes-a938b66e0ee304c1.dylib: Io(Custom { kind: InvalidData, error: DlOpen { desc: "dlopen(<redacted>/debug/deps/libtracing_attributes-a938b66e0ee304c1.dylib, 0x000A): tried: \'<redacted>/debug/deps/libtracing_attributes-a938b66e0ee304c1.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\'))" } })

@Veykril
Copy link
Member

Veykril commented Jun 17, 2022

Ah, okay we've seen this pop up for a few people already, see #12494 (comment). (Note the error isn't really new, the diagnostic is just more visible now).

@dreamerlzl
Copy link

I install the latest version (6.17) and my vscode works fine, but my neovim lsp still fails.
In my nvim lsp log ~/.cache/nvim/lsp.log, I really don't find anything useful...
BTW, I am using intel mac.

@Veykril
Copy link
Member

Veykril commented Jun 18, 2022

Heads up, #12584 fixed an issue where we potentially did misdiagnose derive helpers as being unresolved specifically.

@dreamerlzl your snippet seems to be hit by this, so the next release should fix your problem.

@KaoImin
Copy link

KaoImin commented Jun 20, 2022

Heads up, #12584 fixed an issue where we potentially did misdiagnose derive helpers as being unresolved specifically.

@dreamerlzl your snippet seems to be hit by this, so the next release should fix your problem.

The problem still occurs after updated the latest release today.

@Veykril
Copy link
Member

Veykril commented Jun 20, 2022

Then there is a set up problem for you, can you set the RA_LOG="warn,project_model=info" env var for the server (for example via the rust-analyzer.server.extraEn setting) and post the entire Rust-Analyzer Server Log after your rust-analyzer has finished loading your project?

@veber-alex
Copy link
Contributor

veber-alex commented Jun 20, 2022

I am also still seeing the issue with VSCode and the latest nightly extension.

rustc 1.63.0-nightly (ca122c7eb 2022-06-13)
rust-analyzer 0.0.0 (427061da1 2022-06-19)

image

Log shows just this:

[INFO project_model::build_scripts] Running build scripts: "cargo" "check" "--quiet" "--workspace" "--message-format=json" "--all-targets"
[INFO project_model::build_scripts] /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/bytemuck_derive-1.1.0: BuildScriptOutput { cfgs: [], envs: [], out_dir: None, proc_macro_dylib_path: Some(AbsPathBuf("/home/alex/projects/playground/target/debug/deps/libbytemuck_derive-d25dd7be040f083d.so")) }
[INFO project_model::build_scripts] /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.39: BuildScriptOutput { cfgs: [Atom("use_proc_macro"), Atom("wrap_proc_macro"), Atom("proc_macro_span")], envs: [], out_dir: Some(AbsPathBuf("/home/alex/projects/playground/target/debug/build/proc-macro2-03a6d138363ec831/out")), proc_macro_dylib_path: None }
[INFO project_model::build_scripts] /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.98: BuildScriptOutput { cfgs: [], envs: [], out_dir: Some(AbsPathBuf("/home/alex/projects/playground/target/debug/build/syn-b89e8b27c76020c5/out")), proc_macro_dylib_path: None }
[INFO project_model::build_scripts] /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-macros-1.8.0: BuildScriptOutput { cfgs: [], envs: [], out_dir: None, proc_macro_dylib_path: Some(AbsPathBuf("/home/alex/projects/playground/target/debug/deps/libtokio_macros-2fb0ecd2fb1cbd4b.so")) }

@flodiebold
Copy link
Member

That's #12450, you can add "tokio" and "tokio-macros" to rust-analyzer.cargo.unsetTest as a workaround.

@Veykril
Copy link
Member

Veykril commented Jun 20, 2022

Hmm, I guess a bunch of people will start reporting about the proc-macros that have the annoying #[cfg(not(test))] attribute used now... I guess we should downgrade the warning to weak again if there is no extra error message attached to the error for now?

@flodiebold
Copy link
Member

flodiebold commented Jun 20, 2022

Can we just unset test on crates.io dependencies?

Also maybe we can expand the troubleshooting documentation for these errors.

@Veykril
Copy link
Member

Veykril commented Jun 20, 2022

Probably?

@flodiebold
Copy link
Member

#12599

@ryo33
Copy link

ryo33 commented Jun 22, 2022

@brianbruggeman Is it resolved? I have the same issue.

@flodiebold
Copy link
Member

@ryo33 Make sure you have installed the aarch64 versions of both VSCode and Rust.

@ryo33
Copy link

ryo33 commented Jun 22, 2022

@flodiebold Thanks!

@brianbruggeman
Copy link

@ryo33 Not as far as I can tell. Just to make sure I was running an apple silicon binary, I uninstalled VSCode and Rust and then reinstalled explicit apple silicon binaries. I then reinstalled Rust Analyzer and I still see the same kinds of problems. From a DX perspective, it's sorta broken (I get real errors and then false positives): I don't know what the real errors are until I actually run a compile. It's not hard to find the real errors and fix them, but I can no longer glance at my file list and find the problem files.

@flodiebold
Copy link
Member

@brianbruggeman If you're still getting incompatible architecture errors, there has to be an x86 binary involved somewhere. Do you have rust-analyzer.server.path set? What does rustc -vV and rustup toolchain list say?

@brianbruggeman
Copy link

@flodiebold Thank you. My toolchain was defaulting to x86. After setting to arm and reloading, everything appears as expected.

Also for the curious:

    "rust-analyzer.server.path": null
rustup toolchain list
stable-aarch64-apple-darwin (default)
stable-x86_64-apple-darwin
nightly-2021-12-19-x86_64-apple-darwin
nightly-2022-01-01-x86_64-apple-darwin
nightly-x86_64-apple-darwin
1.56.0-x86_64-apple-darwin
rustc -vV
rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: aarch64-apple-darwin
release: 1.61.0
LLVM version: 14.0.0

@flodiebold
Copy link
Member

Since the new release is out which fixes some of these issues and provides better error messages for others, let's close this.

@saadjhk If you're still experiencing issues, feel free to reopen.

@wangjia184
Copy link

wangjia184 commented Aug 18, 2022

@flodiebold I still encounter the same issue on Mac M1
image

VSCode is arm64 edition
image

rustc -vV
rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: aarch64-apple-darwin
release: 1.63.0
LLVM version: 14.0.5

and I even tried to uninstall stable-x86_64-apple-darwin toolchain, but the error is still there. it keeps trying to seek x64 binary while I only have arm64

$ rustup toolchain list
stable-aarch64-apple-darwin (default)

tried the following setting and it does not help

"rust-analyzer.cargo.unsetTest": [
        "clap",
        "clap_derive",
        "clap-derive"
    ]

tried reinstall rust-analyzer, does not help

@flodiebold
Copy link
Member

@wangjia184 You're somehow running an x64 rust-analyzer. You need to install the arm64 version.

@wangjia184
Copy link

yep, I download t he visx file and install manually, it works. strange it does not work if installing from VSCode extension

@AnderUstarroz
Copy link

AnderUstarroz commented Aug 22, 2022

@wangjia184 How did you manage to solve this? I am using a Mac M1 but running rustc -vV shows:

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-apple-darwin
release: 1.63.0
LLVM version: 14.0.5

and rustup toolchain list

stable-x86_64-apple-darwin (default)
1.62-x86_64-apple-darwin

Can I get the arch64 version somehow using rustup ?

@flodiebold
Copy link
Member

@AnderUstarroz something like rustup install stable-aarch64-apple-darwin && rustup default stable-aarch64-apple-darwin should do it.

@wangjia184
Copy link

wangjia184 commented Aug 22, 2022

@AnderUstarroz both VSCode and rust-analyzer extension must be aarch64 edition, and set tool chain as @flodiebold told

@AnderUstarroz
Copy link

Thanks to both of you @flodiebold , @wangjia184
That fixed the issue, I have no macros errors anymore.

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
Projects
None yet
Development

No branches or pull requests