cargo
cargo copied to clipboard
Panic on use of libraries with proc-macro examples
Problem
Cargo is panicking on valid examples targets.
Minimised example is here
thread 'main' panicked at src/cargo/core/resolver/features.rs:323:14:
activated_features for invalid package: features did not find PackageId { name: "library", version: "0.1.0", source: "/home/oliverkillane/files/bug-reports/cargo-proc-macro-examples/library" } NormalOrDev
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Discovered in the wild when using @CraftSpider 's chumsky-proc
Steps
git clone [email protected]:OliverKillane/bug-reports.git
cd bug-reports/cargo-proc-macro-examples/application/
cargo check
Possible Solution(s)
No response
Notes
Similar error to #10593 but different cause.
Version
cargo 1.77.1 (e52e36006 2024-03-26)
release: 1.77.1
commit-hash: e52e360061cacbbeac79f7f1215a7a90b6f08442
commit-date: 2024-03-26
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.5.0-DEV (sys:0.4.70+curl-8.5.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Ubuntu 22.04 (jammy) [64-bit]
The linked repository is 404. Is it perhaps private?
What is the output you are seeing?
The linked repository is 404. Is it perhaps private?
Fixed!
@rustbot label A-features2 A-crate-types
Reproduced on master.
@rustbot label +Command-check, +S-needs-mentor, -S-triage
Here's a minimal test case:
use cargo_test_support::project;
#[cargo_test]
fn issue_13726() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "application"
edition = "2021"
[dependencies]
library = { path = "library" }
"#,
)
.file("src/main.rs", "fn main() {}")
.file(
"library/Cargo.toml",
r#"
[package]
name = "library"
[[example]]
name = "foo"
proc-macro = true
crate-type = ["proc-macro"]
"#,
)
.file("library/src/lib.rs", "")
.file("library/examples/foo.rs", "")
.build();
p.cargo("check").run();
}
Thanks for the minimal test case. I went ahead and edited it a bit. According to The Cargo Book, only [lib] can have proc-macro set. However, there is no warning if set. This discrepancy should belong to another issue though. I honestly don't know why it was designed like that.
Anyway, the updated version aligns to the original reproduction from the issue author, and they have the same bad behavior.
Hmm… I am seeing odd behavior. Maybe we should add both proc-macro = true and crate-type = ["proc-macro"] for the minimal reproduction for completeness.