Skip to content

Confusing error message when proc macro not built due to allTargets: false #18528

@bjorn3

Description

@bjorn3
Member

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

rustc version: rustc 1.82.0 (f6e511eec 2024-10-15)

editor or extension: VSCode

relevant settings:

{
    "rust-analyzer.cargo.allTargets": false
}

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

#- Cargo.toml
[package]
name = "rust_analyzer_reproducer"
version = "0.1.0"
edition = "2021"

[dev-dependencies]
serde = { version = "1.0.215", features = ["derive"] }
//- tests/foo.rs
#[derive(serde::Serialize)]
struct Foo;

and then after rust-analyzer has started make any change to struct Foo;. This will result in a "proc-macro crate build data is missing dylib path" error. This doesn't make it clear that this is because disabling --all-targets prevents serde_derive from getting built as it is a dev-dependency. It also shouldn't show up as an error, but closer to the diagnostic that is shown when build script building is disabled entirely though preferably also explaining why the proc-macro wasn't built.

Activity

ChayimFriedman2

ChayimFriedman2 commented on Nov 18, 2024

@ChayimFriedman2
Contributor

I'm not sure how we could detect that if --all-targets will be enabled the proc macro will be available. The downgrade in severity is possible, though.

bjorn3

bjorn3 commented on Nov 18, 2024

@bjorn3
MemberAuthor

We can detect that the proc macro dependency is a dev-dependency, right? All proc macros that are only reachable through a dev-dependency edge in the dependency graph are only available when --all-targets or similar is passed.

ChayimFriedman2

ChayimFriedman2 commented on Nov 18, 2024

@ChayimFriedman2
Contributor

I don't think we can detect that, we don't know about dev dependencies, only about dependencies in the current configuration. Maybe we can add this but I don't know if this information is available to us from Cargo.

bjorn3

bjorn3 commented on Nov 18, 2024

@bjorn3
MemberAuthor

cargo metadata most certainly reports dev-dependencies. Otherwise rust-analyzer wouldn't even know to expect a proc macro here and thus complain about missing data for the proc macro. Not setting --all-targets only causes the cargo check invocation that rust-analyzer does to run build script amd build proc macro to omit artifact notifications for proc macros that are dev-dependencies.

Veykril

Veykril commented on Dec 2, 2024

@Veykril
Member

Our HIR layer doesn't know about dev dependencies (intentionally) iirc

jerusdp

jerusdp commented on Jan 14, 2025

@jerusdp

If you are loading the dependencies from a workspace you don't know whether how they are used.

Veykril

Veykril commented on Jul 3, 2025

@Veykril
Member

I think thanks to --compile-time-deps we can ignore that setting for build scripts entirely and always pass --all-targets. We never try to build artifacts that may not built for the target with that flag anyways: #20159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Veykril@bjorn3@ChayimFriedman2@jerusdp

        Issue actions

          Confusing error message when proc macro not built due to allTargets: false · Issue #18528 · rust-lang/rust-analyzer