Skip to content

unresolved-proc-macro error on all proc macro usages #11150

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
dbeckwith opened this issue Jan 1, 2022 · 22 comments
Closed

unresolved-proc-macro error on all proc macro usages #11150

dbeckwith opened this issue Jan 1, 2022 · 22 comments

Comments

@dbeckwith
Copy link

dbeckwith commented Jan 1, 2022

rust-analyzer version: 3d63abf1d 2022-01-01 nightly

rustc version: rustc 1.57.0 (f1edd0429 2021-11-29)

I've verified that proc macro support is enabled by looking at the client logs:

INFO [1/1/2022, 4:49:27 AM]: Extension version: 0.3.886
INFO [1/1/2022, 4:49:27 AM]: Using configuration {
  cargoRunner: null,
  runnableEnv: null,
  inlayHints: {
    enable: false,
    smallerHints: true,
    chainingHints: true,
    maxLength: 25,
    parameterHints: true,
    typeHints: true,
    hideNamedConstructorHints: false
  },
  server: { path: null, extraEnv: null },
  trace: { server: 'off', extension: false },
  debug: {
    engine: 'auto',
    sourceFileMap: {
      '/rustc/<id>': '${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust'
    },
    openDebugPane: false,
    engineSettings: {}
  },
  assist: {
    importGranularity: 'crate',
    importEnforceGranularity: false,
    importPrefix: 'crate',
    importGroup: true,
    allowMergingIntoGlobImports: true
  },
  cache: { warmup: true },
  callInfo: { full: true },
  cargo: {
    autoreload: true,
    allFeatures: false,
    unsetTest: [ 'core' ],
    features: [],
    runBuildScripts: true,
    useRustcWrapperForBuildScripts: true,
    noDefaultFeatures: false,
    target: null,
    noSysroot: false
  },
  checkOnSave: {
    enable: true,
    allFeatures: null,
    allTargets: true,
    command: 'clippy',
    noDefaultFeatures: null,
    target: null,
    extraArgs: [],
    features: null,
    overrideCommand: null
  },
  completion: {
    addCallArgumentSnippets: true,
    addCallParenthesis: true,
    snippets: {
      'Arc::new': {
        postfix: 'arc',
        body: 'Arc::new(${receiver})',
        requires: 'std::sync::Arc',
        description: 'Put the expression into an `Arc`',
        scope: 'expr'
      },
      'Rc::new': {
        postfix: 'rc',
        body: 'Rc::new(${receiver})',
        requires: 'std::rc::Rc',
        description: 'Put the expression into an `Rc`',
        scope: 'expr'
      },
      'Box::pin': {
        postfix: 'pinbox',
        body: 'Box::pin(${receiver})',
        requires: 'std::boxed::Box',
        description: 'Put the expression into a pinned `Box`',
        scope: 'expr'
      },
      Ok: {
        postfix: 'ok',
        body: 'Ok(${receiver})',
        description: 'Wrap the expression in a `Result::Ok`',
        scope: 'expr'
      },
      Err: {
        postfix: 'err',
        body: 'Err(${receiver})',
        description: 'Wrap the expression in a `Result::Err`',
        scope: 'expr'
      },
      Some: {
        postfix: 'some',
        body: 'Some(${receiver})',
        description: 'Wrap the expression in an `Option::Some`',
        scope: 'expr'
      }
    },
    postfix: { enable: true },
    autoimport: { enable: true },
    autoself: { enable: true }
  },
  diagnostics: {
    enable: true,
    enableExperimental: true,
    disabled: [],
    remapPrefix: {},
    warningsAsHint: [],
    warningsAsInfo: []
  },
  experimental: { procAttrMacros: true },
  files: { watcher: 'client', excludeDirs: [] },
  highlightRelated: {
    references: true,
    exitPoints: true,
    breakPoints: true,
    yieldPoints: true
  },
  highlighting: { strings: true },
  hover: { documentation: true, linksInHover: true },
  hoverActions: {
    debug: true,
    enable: true,
    gotoTypeDef: true,
    implementations: true,
    references: false,
    run: true
  },
  joinLines: {
    joinElseIf: true,
    removeTrailingComma: true,
    unwrapTrivialBlock: true,
    joinAssignments: true
  },
  lens: {
    debug: true,
    enable: false,
    implementations: true,
    run: true,
    methodReferences: false,
    references: false,
    enumVariantReferences: false,
    forceCustomCommands: true
  },
  linkedProjects: [],
  lruCapacity: null,
  notifications: { cargoTomlNotFound: true },
  procMacro: { enable: true, server: null },
  runnables: { overrideCargo: null, cargoExtraArgs: [] },
  rustcSource: null,
  rustfmt: {
    extraArgs: [],
    overrideCommand: [ 'rustfmt' ],
    enableRangeFormatting: false
  },
  workspace: { symbol: { search: { scope: 'workspace', kind: 'only_types' } } }
}
INFO [1/1/2022, 4:49:27 AM]: PersistentState: { serverVersion: '0.3.886' }

However, I'm still getting the unresolved-proc-macro error that macros are not being expanded. Is there something else that has to be enabled or installed to turn this on? The User Manual doesn't mention anything else. It does say "can also indicate project setup problems" but doesn't indicate what those might be.

@lnicola
Copy link
Member

lnicola commented Jan 1, 2022

No, it should be enough. Is that your macro, or a public crate?

@dbeckwith
Copy link
Author

I'm seeing the error from the derive macros from serde and thiserror, as well as function-like macros from sqlx.

@dbeckwith
Copy link
Author

It might be worth mentioning that I'm on NixOS, using the mozilla/nixpkgs-mozilla overlay for my Rust environment, and I notice that the rust-analyzer VS Code extension sometimes does some NixOS-specific setup when it starts up.

@lnicola
Copy link
Member

lnicola commented Jan 1, 2022

CC @matklad -- I'm not sure, maybe we can't load the compiled proc macro because of unresolved libraries?

@dbeckwith
Copy link
Author

I found this in the "Log (Extension Host)" output panel:

[2022-01-01 15:13:46.756] [exthost] [error] Canceled: Canceled
    at Object.R [as canceled] (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:5:1157)
    at t._remoteCall (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:99:13876)
    at Proxy.O.<computed>.F.charCodeAt.O.<computed> (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:99:10271)
    at r._doExecuteCommand (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:95:30473)
    at r.executeCommand (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:95:29874)
    at Object.executeCommand (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:104:22022)
    at Ca ($HOME/.vscode/extensions/matklad.rust-analyzer-0.3.886/out/main.js:39:35807)
    at Object.Eg ($HOME/.vscode/extensions/matklad.rust-analyzer-0.3.886/out/main.js:85:1555)
    at v._deactivate (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:100:11513)
    at /nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:100:10061
    at Array.map (<anonymous>)
    at v.deactivateAll (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:100:10049)
    at p.terminate (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:104:735)
    at r (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:114:36400)
    at Socket.<anonymous> (/nix/store/78lswy0av2y6zdfv7vjrlpdz74ha1pi4-vscode-1.63.2/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:114:34012)
    at Socket.emit (events.js:327:22)
    at Pipe.<anonymous> (net.js:673:12)

@lnicola
Copy link
Member

lnicola commented Jan 1, 2022

That's harmless. You you search for a libserde_derive-*.so in your target directory and run ldd on it, what does it say?

@dbeckwith
Copy link
Author

dbeckwith commented Jan 1, 2022

$ ldd target/debug/deps/libserde_derive-6408565b4f8262d0.so
	linux-vdso.so.1 (0x00007ffd7afea000)
	libgcc_s.so.1 => /nix/store/wl60dr9p15rwf53gxz61ijgisc1zdjc7-glibc-2.33-59/lib/libgcc_s.so.1 (0x00007f5704035000)
	libpthread.so.0 => /nix/store/wl60dr9p15rwf53gxz61ijgisc1zdjc7-glibc-2.33-59/lib/libpthread.so.0 (0x00007f5704015000)
	libm.so.6 => /nix/store/wl60dr9p15rwf53gxz61ijgisc1zdjc7-glibc-2.33-59/lib/libm.so.6 (0x00007f5703ed4000)
	libdl.so.2 => /nix/store/wl60dr9p15rwf53gxz61ijgisc1zdjc7-glibc-2.33-59/lib/libdl.so.2 (0x00007f5703ecf000)
	libc.so.6 => /nix/store/wl60dr9p15rwf53gxz61ijgisc1zdjc7-glibc-2.33-59/lib/libc.so.6 (0x00007f5703d0a000)
	/nix/store/wl60dr9p15rwf53gxz61ijgisc1zdjc7-glibc-2.33-59/lib64/ld-linux-x86-64.so.2 (0x00007f57047ea000)

@dbeckwith
Copy link
Author

Just want to make it clear that the problem doesn't seem specific to any particular proc-macro, it seems to be affecting all of them. The attribute macro from async-trait is another example.

@matklad
Copy link
Member

matklad commented Jan 1, 2022

Things to check:

image

(this tab will be present only if there are some logs)

@dbeckwith
Copy link
Author

dbeckwith commented Jan 1, 2022

I have verbose logging enabled according to the manual. In my original project, I see lots of output in the "Rust Analyzer Language Server" logs but no errors.

I made a new test project with the same Rust version and configuration, added serde as a dependency, and a struct with #[derive(Serialize)]. When RA first started up, it was giving an error status:

rust-analyzer failed to run build scripts:
error: could not compile serde_derive due to 2 previous errors
error: build failed

Click to reload.

cargo check in my terminal showed no issue, and I was getting unresolved-proc-macro on the derive. Clicking to reload the extension gave the same status. I still didn't see any other errors in the "Rust Analyzer Language Server" logs besides:

[ERROR rust_analyzer::reload] failed to switch build data: rust-analyzer failed to run build scripts:
error: could not compile `serde_derive` due to 2 previous errors
error: build failed

And no other errors in "Rust Analyzer Language Server Trace" or "Rust Analyzer Client".

After reloading the VS Code window, the RA extension no longer shows an error status, but I'm still getting unresolved-proc-macro on the derive.

@yezuochang

This comment has been minimized.

@lnicola

This comment has been minimized.

@yezuochang

This comment has been minimized.

@lnicola

This comment has been minimized.

@yezuochang

This comment has been minimized.

@lnicola

This comment has been minimized.

@dbeckwith
Copy link
Author

If there's any additional information or investigation I can provide to help diagnose this issue please let me know.

@rinconjc
Copy link

rinconjc commented Mar 4, 2022

I have the same issue with spacemacs + lsp RA

@onichandame
Copy link

I am experiencing the same issue

@lnicola
Copy link
Member

lnicola commented Mar 18, 2022

Does anyone have a test case they make public?

@onichandame
Copy link

@lnicola I have filed another issue with reproduction repo. My case is slightly different as proc-macros from serde and all functional macros are working fine for me.

@dbeckwith
Copy link
Author

I'm unable to reproduce my original issue, so I think this has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants