Skip to content
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

Panic on use of libraries with proc-macro examples #13726

Open
OliverKillane opened this issue Apr 9, 2024 · 7 comments · May be fixed by #13892
Open

Panic on use of libraries with proc-macro examples #13726

OliverKillane opened this issue Apr 9, 2024 · 7 comments · May be fixed by #13892
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-crate-types Area: crate-type declaration (lib, staticlib, dylib, cdylib, etc.) A-features2 Area: issues specifically related to the v2 feature resolver A-proc-macro Area: compiling proc-macros C-bug Category: bug S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.

Comments

@OliverKillane
Copy link

OliverKillane commented Apr 9, 2024

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 git@github.com: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]
@OliverKillane OliverKillane added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Apr 9, 2024
@ehuss
Copy link
Contributor

ehuss commented Apr 9, 2024

The linked repository is 404. Is it perhaps private?

What is the output you are seeing?

@OliverKillane
Copy link
Author

OliverKillane commented Apr 9, 2024

The linked repository is 404. Is it perhaps private?

Fixed!

@heisen-li
Copy link
Contributor

heisen-li commented Apr 10, 2024

@rustbot label A-features2 A-crate-types

@rustbot rustbot added A-features2 Area: issues specifically related to the v2 feature resolver Z-bindeps Nightly: binary artifact dependencies A-crate-types Area: crate-type declaration (lib, staticlib, dylib, cdylib, etc.) labels Apr 10, 2024
@ehuss ehuss removed the Z-bindeps Nightly: binary artifact dependencies label Apr 10, 2024
@torhovland
Copy link
Contributor

Reproduced on master.

@rustbot label +Command-check, +S-needs-mentor, -S-triage

@rustbot rustbot added Command-check S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. and removed S-triage Status: This issue is waiting on initial triage. labels May 8, 2024
@torhovland
Copy link
Contributor

torhovland commented May 8, 2024

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();
}

@weihanglo
Copy link
Member

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.

@weihanglo weihanglo added A-proc-macro Area: compiling proc-macros A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) and removed Command-check labels May 9, 2024
@weihanglo
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-crate-types Area: crate-type declaration (lib, staticlib, dylib, cdylib, etc.) A-features2 Area: issues specifically related to the v2 feature resolver A-proc-macro Area: compiling proc-macros C-bug Category: bug S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants