Skip to content

tracing::instrument: proc-macro crate build data is missing dylib pathΒ #18508

@frank-king

Description

@frank-king

The problem is: in a crate with the rustc_private feature enabled, I imported the tracing crate by #[macro_use] extern crate tracing; that uses the tracing inside rustc, and wrote a function attributed by #[instrument], and edit it. Then hover on that function, which resulted in the whole function being highlighted with annoying red tildes.

I'm not sure which I should blame, rustc, rust-analyzer, tracing, or proc-macro.

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rust-analyzer version: 0.4.2183-standalone [/home/whjpji/.vscode/extensions/rust-lang.rust-analyzer-0.4.2183-linux-x64/server/rust-analyzer]

rustc version: (eg. output of rustc -V)

rustc 1.84.0-nightly (86d69c705 2024-10-22)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)

Version: 1.93.1
Commit: 38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40
Date: 2024-09-11T17:20:05.685Z
Electron: 30.4.0
ElectronBuildId: 10073054
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Linux x64 6.8.0-48-generic

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

% echo $CARGO

% echo $RUSTUP_HOME
/home/whjpji/.cargo
% echo $RUSTC

% echo $CARGO_HOME
/home/whjpji/.cargo

screenshots:
Image
Image

logs:

Rust-Analyzer Language Server
2024-11-14T14:43:33.626439515+08:00 ERROR Position LineCol { line: 0, col: 1 } column exceeds line length 0, clamping it
2024-11-14T14:45:16.700340054+08:00 ERROR flycheck 0: File with cargo diagnostic not found in VFS: file not found: /rust/deps/tracing-0.1.37/src/macros.rs
2024-11-14T14:45:16.700425501+08:00 ERROR flycheck 0: File with cargo diagnostic not found in VFS: file not found: /rust/deps/tracing-0.1.37/src/macros.rs
[Error - 2:45:28 PM] Server process exited with code 0.
Rust-Analyzer Client
2024-11-14 14:43:28.169 [info] Extension version: 0.4.2183
2024-11-14 14:43:28.169 [info] Using configuration {
  restartServerOnConfigChange: false,
  showUnlinkedFileNotification: true,
  showRequestFailedErrorNotification: true,
  showDependenciesExplorer: true,
  testExplorer: false,
  initializeStopped: false,
  runnables: {
    extraEnv: null,
    problemMatcher: [ '$rustc' ],
    command: null,
    extraArgs: [],
    extraTestBinaryArgs: [ '--show-output' ]
  },
  statusBar: { clickAction: 'openLogs' },
  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,
    buildBeforeRestart: false,
    engineSettings: {}
  },
  typing: {
    continueCommentsOnNewline: true,
    autoClosingAngleBrackets: { enable: false }
  },
  diagnostics: {
    previewRustcOutput: false,
    useRustcErrorCode: false,
    disabled: [],
    enable: true,
    experimental: { enable: false },
    remapPrefix: {},
    styleLints: { enable: false },
    warningsAsHint: [],
    warningsAsInfo: []
  },
  assist: {
    emitMustUse: false,
    expressionFillDefault: 'todo',
    termSearch: { borrowcheck: true, fuel: 1800 }
  },
  cachePriming: { enable: true, numThreads: 'physical' },
  cargo: {
    allTargets: true,
    autoreload: true,
    buildScripts: {
      enable: true,
      invocationStrategy: 'per_workspace',
      overrideCommand: null,
      rebuildOnSave: true,
      useRustcWrapper: true
    },
    cfgs: { miri: null, debug_assertions: null },
    extraArgs: [],
    extraEnv: {},
    features: [],
    noDefaultFeatures: false,
    sysroot: 'discover',
    sysrootSrc: null,
    target: null,
    targetDir: null
  },
  cfg: { setTest: true },
  checkOnSave: true,
  check: {
    allTargets: null,
    command: 'check',
    extraArgs: [],
    extraEnv: {},
    features: null,
    ignore: [],
    invocationStrategy: 'per_workspace',
    noDefaultFeatures: null,
    overrideCommand: null,
    targets: null,
    workspace: true
  },
  completion: {
    addSemicolonToUnit: true,
    autoimport: { enable: true },
    autoself: { enable: true },
    callable: { snippets: 'fill_arguments' },
    fullFunctionSignatures: { enable: false },
    hideDeprecated: false,
    limit: null,
    postfix: { enable: true },
    privateEditable: { enable: false },
    snippets: {
      custom: {
        Ok: {
          postfix: 'ok',
          body: 'Ok(${receiver})',
          description: 'Wrap the expression in a `Result::Ok`',
          scope: 'expr'
        },
        'Box::pin': {
          postfix: 'pinbox',
          body: 'Box::pin(${receiver})',
          requires: 'std::boxed::Box',
          description: 'Put the expression into a pinned `Box`',
          scope: 'expr'
        },
        'Arc::new': {
          postfix: 'arc',
          body: 'Arc::new(${receiver})',
          requires: 'std::sync::Arc',
          description: 'Put the expression into an `Arc`',
          scope: 'expr'
        },
        Some: {
          postfix: 'some',
          body: 'Some(${receiver})',
          description: 'Wrap the expression in an `Option::Some`',
          scope: 'expr'
        },
        Err: {
          postfix: 'err',
          body: 'Err(${receiver})',
          description: 'Wrap the expression in a `Result::Err`',
          scope: 'expr'
        },
        'Rc::new': {
          postfix: 'rc',
          body: 'Rc::new(${receiver})',
          requires: 'std::rc::Rc',
          description: 'Put the expression into an `Rc`',
          scope: 'expr'
        }
      }
    },
    termSearch: { enable: false, fuel: 1000 }
  },
  files: { excludeDirs: [], watcher: 'client' },
  highlightRelated: {
    breakPoints: { enable: true },
    closureCaptures: { enable: true },
    exitPoints: { enable: true },
    references: { enable: true },
    yieldPoints: { enable: true }
  },
  hover: {
    actions: {
      debug: { enable: true },
      enable: true,
      gotoTypeDef: { enable: true },
      implementations: { enable: true },
      references: { enable: false },
      run: { enable: true }
    },
    documentation: { enable: true, keywords: { enable: true } },
    links: { enable: true },
    memoryLayout: {
      alignment: 'hexadecimal',
      enable: true,
      niches: false,
      offset: 'hexadecimal',
      size: 'both'
    },
    show: { enumVariants: 5, fields: 5, traitAssocItems: null }
  },
  imports: {
    granularity: { enforce: false, group: 'crate' },
    group: { enable: true },
    merge: { glob: true },
    preferNoStd: false,
    preferPrelude: false,
    prefix: 'plain',
    prefixExternPrelude: false
  },
  inlayHints: {
    bindingModeHints: { enable: false },
    chainingHints: { enable: true },
    closingBraceHints: { enable: true, minLines: 25 },
    closureCaptureHints: { enable: false },
    closureReturnTypeHints: { enable: 'never' },
    closureStyle: 'impl_fn',
    discriminantHints: { enable: 'never' },
    expressionAdjustmentHints: { enable: 'never', hideOutsideUnsafe: false, mode: 'prefix' },
    genericParameterHints: {
      const: { enable: true },
      lifetime: { enable: false },
      type: { enable: false }
    },
    implicitDrops: { enable: false },
    lifetimeElisionHints: { enable: 'never', useParameterNames: false },
    maxLength: 25,
    parameterHints: { enable: true },
    rangeExclusiveHints: { enable: false },
    reborrowHints: { enable: 'never' },
    renderColons: true,
    typeHints: {
      enable: true,
      hideClosureInitialization: false,
      hideNamedConstructor: false
    }
  },
  interpret: { tests: false },
  joinLines: {
    joinAssignments: true,
    joinElseIf: true,
    removeTrailingComma: true,
    unwrapTrivialBlock: true
  },
  lens: {
    debug: { enable: true },
    enable: true,
    implementations: { enable: true },
    location: 'above_name',
    references: {
      adt: { enable: false },
      enumVariant: { enable: false },
      method: { enable: false },
      trait: { enable: false }
    },
    run: { enable: true }
  },
  linkedProjects: [ './Cargo.toml' ],
  lru: { capacity: 64, query: { capacities: {} } },
  notifications: { cargoTomlNotFound: true },
  numThreads: null,
  procMacro: {
    attributes: { enable: true },
    enable: true,
    ignored: {},
    server: null
  },
  references: { excludeImports: false, excludeTests: false },
  rustc: { source: 'discover' },
  rustfmt: {
    extraArgs: [],
    overrideCommand: null,
    rangeFormatting: { enable: false }
  },
  semanticHighlighting: {
    doc: { comment: { inject: { enable: true } } },
    nonStandardTokens: true,
    operator: { enable: true, specialization: { enable: false } },
    punctuation: {
      enable: false,
      separate: { macro: { bang: false } },
      specialization: { enable: false }
    },
    strings: { enable: true }
  },
  signatureInfo: { detail: 'full', documentation: { enable: true } },
  workspace: {
    discoverConfig: null,
    symbol: { search: { kind: 'only_types', limit: 128, scope: 'workspace' } }
  }
}
2024-11-14 14:43:28.169 [info] PersistentState: { serverVersion: '0.3.1983' }
2024-11-14 14:43:28.169 [info] Starting language client
2024-11-14 14:43:28.215 [info] Using server binary at /home/whjpji/.vscode/extensions/rust-lang.rust-analyzer-0.4.2183-linux-x64/server/rust-analyzer
2024-11-14 14:43:28.240 [info] /home/whjpji/.vscode/extensions/rust-lang.rust-analyzer-0.4.2183-linux-x64/server/rust-analyzer --version: {
  stdout: 'rust-analyzer 0.4.2183-standalone\n',
  stderr: '',
  status: 0
}
2024-11-14 14:45:26.768 [info] Disposing language client
2024-11-14 14:45:26.770 [info] Starting language client
2024-11-14 14:45:26.789 [info] Using server binary at /home/whjpji/.vscode/extensions/rust-lang.rust-analyzer-0.4.2183-linux-x64/server/rust-analyzer
2024-11-14 14:45:26.805 [info] /home/whjpji/.vscode/extensions/rust-lang.rust-analyzer-0.4.2183-linux-x64/server/rust-analyzer --version: {
  stdout: 'rust-analyzer 0.4.2183-standalone\n',
  stderr: '',
  status: 0
}

repository link (if public, optional) No

code snippet to reproduce:

Here is a minimal reproducible code setup
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..0f82d84
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,7 @@
+{
+    "rust-analyzer.rustc.source": "discover",
+    "rust-analyzer.linkedProjects": [
+        "./Cargo.toml",
+    ],
+    "rust-analyzer.procMacro.enable": true,
+}
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..8174c5b
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "ra-test"
+version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..46d8b2a
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "ra-test"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+
+[package.metadata.rust-analyzer]
+# This crate uses #[feature(rustc_private)]
+rustc_private = true
diff --git a/rust-toolchain b/rust-toolchain
new file mode 100644
index 0000000..a66953d
--- /dev/null
+++ b/rust-toolchain
@@ -0,0 +1,3 @@
+[toolchain]
+channel = "nightly-2024-10-23"
+components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..fe7c7c7
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,9 @@
+#![feature(rustc_private)]
+
+#[macro_use]
+extern crate tracing;
+
+#[instrument]
+fn test() {
+    info!("Hello, world!");
+}

EDIT: I've tested with this toolchain specification, and it doesn't work either.

[toolchain]
channel = "nightly-2024-11-13"
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt", "rust-analyzer"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions