Skip to content

Cargo.toml dependencies: avoid caret requirements #13307

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
Marcondiro opened this issue Aug 26, 2024 · 5 comments
Open

Cargo.toml dependencies: avoid caret requirements #13307

Marcondiro opened this issue Aug 26, 2024 · 5 comments
Labels
A-lint Area: New lints

Comments

@Marcondiro
Copy link

What it does

Hello,
It would be nice to have a lint that highlights the presence of dependencies having the version specified with a ^ (caret) in the Cargo.toml. For example foo="^1.2.3".
As for Cargo docs:

Leaving off the caret is a simplified equivalent syntax to using caret requirements. While caret requirements are the default, it is recommended to use the simplified syntax when possible.

Advantage

This lint helps in having a uniform Cargo.toml where simplified syntax and explicit carets are not mixed, following Cargo docs suggestion.

Drawbacks

None I am aware of

Example

[dependencies]
foo="^1.2.3"
bar="9.8.7"

Could be written as:

[dependencies]
foo="1.2.3"
bar="9.8.7"
@weihanglo
Copy link
Member

IMHO, this lint is a better fit in Cargo its own lint system:

@Marcondiro
Copy link
Author

@weihanglo are you aware of any policy about what sould go there and what in clippy?
A similar lint is already present in Clippy: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies

@weihanglo
Copy link
Member

From @flip1995's last comment

Re: Move lints to the cargo repo

cargo lints in Clippy are not the usual Clippy style lints. And I think the cargo team would have a way easier time reviewing cargo lints than the Clippy team.

Should cargo implement the infrastructure to add lints for cargo itself, IMO it should maintain all of the available cargo lints. This includes documentation. Documenting cargo lints on the Clippy website doesn't really make sense to me.

Personally I look forward to the direction, though not sure if it was the decision.
(I am not on Clippy team but Cargo team BTW.)

cc @Muscraft (diagnostics magician on t-cargo)

@Marcondiro
Copy link
Author

@weihanglo thanks for the info!
So, if I understand correctly, as for today cargo lints are still a future goal and not something I can use right now to address this issue

@weihanglo
Copy link
Member

weihanglo commented Mar 14, 2025

AFAIK, the only remaining task of stabilizing [lints.cargo] feature is finding a good lint candidate together with the stabilization. This one might be the one. Of course the lint infrastructure is not as polished as clippy's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants