Skip to content

Warn when feature is not required explicitly, but required by a transitive dependency #14375

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

Open
antoniofunnel opened this issue Aug 9, 2024 · 1 comment
Labels
A-features Area: features — conditional compilation A-new-lint Area: new lint C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.

Comments

@antoniofunnel
Copy link

antoniofunnel commented Aug 9, 2024

Problem

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Task {
    pub created_at: DateTime<Utc>,

}

this compiles with a cargo.toml that looks like this:

[package]
name = "testing"
version = "0.1.0"
authors = ["antonio"]
edition = "2021"
[dependencies]
chrono = "0.4.38"
serde_json = "1.0.120"
serde = { version = "1.0.202", features = ["derive"] }
rusoto_credential = "0.44.0"

When removing rusoto_credential from cargo.toml I get this error:

The trait bound DateTime<Utc>: Deserialize<'_> is not satisfied [E0277] the trait Deserialize<'_> is not implemented for DateTime<Utc>

This is because rusoto_credential also depends on chrono with the feature serde.

So adding that feature to my import of chrono solves it.

Proposed Solution

A warning about used features thats not explicitly imported would be nice, or something smarter that I cant think off <3

Notes

No response

@antoniofunnel antoniofunnel added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Aug 9, 2024
@epage epage added the A-features Area: features — conditional compilation label Aug 9, 2024
@epage
Copy link
Contributor

epage commented Aug 9, 2024

This is closely related to #14021 but I suspect the actual solution might have some small differences that we might need to track both concepts somehow.

@epage epage changed the title Warn when feature is not imported explicitly Warn when feature is not required explicitly, but required by a transitive dependency Aug 9, 2024
@epage epage added the A-diagnostics Area: Error and warning messages generated by Cargo itself. label Aug 9, 2024
@epage epage added A-new-lint Area: new lint and removed A-diagnostics Area: Error and warning messages generated by Cargo itself. labels May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features Area: features — conditional compilation A-new-lint Area: new lint C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants