Skip to content

Bad error message when a weak dep features's depedency is an unused optional dependency #14015

@epage

Description

@epage
Contributor

Problem

If nothing can activate an optional dependency, cargo acts as if the dependency doesn't exist which creates poor error messages.

Also, with how things are arranged, the unused optional dependency lint doesn't get reported which could at least reduce the burden on the error message.

Steps

Baseline Cargo.toml:

cargo-features = ["edition2024"]
[package]
name = "cargo-14010"
version = "0.1.0"
edition = "2024"

[dependencies]
serde = { version = "1.0.203", optional = true }
$ cargo +nightly check -Zcargo-lints
warning: unused optional dependency
 --> Cargo.toml:8:1
  |
8 | serde = { version = "1.0.203", optional = true }
  | -----
  |
  = note: `cargo::unused_optional_dependency` is set to `warn` by default
  = help: remove the dependency or activate it in a feature with `dep:serde`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s

Add the following to Cargo.toml:

[features]
serde = ["serde?/derive"]
$ cargo +nightly check -Zcargo-lints
error: failed to parse manifest at `/home/epage/src/personal/dump/cargo-14010-1/Cargo.toml`

Caused by:
  feature `serde` includes `serde?/derive`, but `serde` is not a dependency

Possible Solution(s)

  • Improve the error message
  • Show the lint (which might be more difficult)

Notes

This came up in discussion in #14010

#14016 covers strong dep features as we likely will want a different solution.

Version

No response

Activity

added
C-bugCategory: bug
A-featuresArea: features — conditional compilation
A-editionsArea: edition-specific issues
S-triageStatus: This issue is waiting on initial triage.
on Jun 5, 2024
added
S-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review
and removed
S-triageStatus: This issue is waiting on initial triage.
on Jun 5, 2024
linyihai

linyihai commented on Jun 6, 2024

@linyihai
Contributor

@rustbot claim
I have a unpolish improvement need to try.

added a commit that references this issue on Jun 17, 2024

3 remaining items

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

Metadata

Metadata

Assignees

Labels

A-editionsArea: edition-specific issuesA-featuresArea: features — conditional compilationC-bugCategory: bugS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @epage@linyihai

    Issue actions

      Bad error message when a weak dep features's depedency is an unused optional dependency · Issue #14015 · rust-lang/cargo