rust-analyzer: Rust analyzer marks proc macros as errors

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 13
  • Comments: 44 (23 by maintainers)

Most upvoted comments

@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

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

@tommyip Try updating rustc. There was a proc macro abi breaking change on nightly recently You are using a rustc version from before this change, while rust-analyzer attempts to use the abi from after this change.

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")) }

I use a number of proc macros (e.g. serde::{Serialize,Deserialize}, rstest, clap, etc.) and over the past week or so, they’ve all been flagged as not expanded because the proc macro is not found.

(CMD + SHIFT + P: Show RA Version) rust-analyzer version: 0.0.0 (7322a982f 2022-06-16)

I did not see a convenient way to set RA_LOG, but I did try RA_LOG="warn,project_model=info" code . I saw a number of these in the Output > Rust Analyzer Language Server window: [WARN mbe::expander::transcriber] expand_tt in repeat pattern exceed limit => MetaTemplate(

I’ve included one example below:

[WARN mbe::expander::transcriber] expand_tt in repeat pattern exceed limit => MetaTemplate(
    [
        Leaf(
            Punct(
                Punct {
                    char: '#',
                    spacing: Alone,
                    id: TokenId(
                        14,
                    ),
                },
            ),
        ),
        Subtree {
            tokens: MetaTemplate(
                [
                    Leaf(
                        Ident(
                            Ident {
                                text: "cfg",
                                id: TokenId(
                                    16,
                                ),
                            },
                        ),
                    ),
                    Subtree {
                        tokens: MetaTemplate(
                            [
                                Leaf(
                                    Ident(
                                        Ident {
                                            text: "feature",
                                            id: TokenId(
                                                18,
                                            ),
                                        },
                                    ),
                                ),
                                Leaf(
                                    Punct(
                                        Punct {
                                            char: '=',
                                            spacing: Alone,
                                            id: TokenId(
                                                19,
                                            ),
                                        },
                                    ),
                                ),
                                Leaf(
                                    Literal(
                                        Literal {
                                            text: "\"use_std\"",
                                            id: TokenId(
                                                20,
                                            ),
                                        },
                                    ),
                                ),
                            ],
                        ),
                        delimiter: Some(
                            Delimiter {
                                id: TokenId(
                                    17,
                                ),
                                kind: Parenthesis,
                            },
                        ),
                    },
                ],
            ),
            delimiter: Some(
                Delimiter {
                    id: TokenId(
                        15,
                    ),
                    kind: Bracket,
                },
            ),
        },
        Var {
            name: "i",
            kind: None,
            id: TokenId(
                22,
            ),
        },
    ],
)
ExpandCtx {
    bindings: Bindings {
        inner: {
            "i": Fragment(
                Tokens(
                    Subtree(
                        SUBTREE $
                          PUNCH   # [alone] 4294967295
                          SUBTREE [] 4294967295
                            IDENT   doc 4294967295
                            PUNCH   = [alone] 4294967295
                            LITERAL " A type alias for `Box<Sink + Send>`" 178
                          IDENT   pub 179
                          IDENT   type 180
                          IDENT   BoxSink 181
                          PUNCH   < [alone] 182
                          IDENT   T 183
                          PUNCH   , [alone] 184
                          IDENT   E 185
                          PUNCH   > [alone] 186
                          PUNCH   = [alone] 187
                          PUNCH   : [joint] 188
                          PUNCH   : [alone] 189
                          IDENT   std 190
                          PUNCH   : [joint] 191
                          PUNCH   : [alone] 192
                          IDENT   boxed 193
                          PUNCH   : [joint] 194
                          PUNCH   : [alone] 195
                          IDENT   Box 196
                          PUNCH   < [alone] 197
                          IDENT   Sink 198
                          PUNCH   < [alone] 199
                          IDENT   SinkItem 200
                          PUNCH   = [alone] 201
                          IDENT   T 202
                          PUNCH   , [alone] 203
                          IDENT   SinkError 204
                          PUNCH   = [alone] 205
                          IDENT   E 206
                          PUNCH   > [alone] 207
                          PUNCH   + [alone] 208
                          PUNCH   : [joint] 209
                          PUNCH   : [alone] 210
                          IDENT   core 211
                          PUNCH   : [joint] 212
                          PUNCH   : [alone] 213
                          IDENT   marker 214
                          PUNCH   : [joint] 215
                          PUNCH   : [alone] 216
                          IDENT   Send 217,
                    ),
                ),
            ),
        },
    },
    nesting: [
        NestingState {
            idx: 65536,
            hit: false,
            at_end: false,
        },
    ],
}

@tommyip Try updating rustc. There was a proc macro abi breaking change on nightly recently You are using a rustc version from before this change, while rust-analyzer attempts to use the abi from after this change.

Fixed after updating rustc to rustc 1.63.0-nightly (1f34da9ec 2022-06-14). Thanks @bjorn3.

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

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

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

Heads up, https://github.com/rust-lang/rust-analyzer/pull/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.

@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 (7322a982f 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  }}

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