cargo: Improve `cargo add -F crate/invalid_feat` error discovery

Problem

When using cargo add -F crate/feat, if the feat feature does not exist, the error is not presented until the end.

image

This can be easy to miss, as most cargo warnings are presented with more context/text around them. cargo add however spits out a features table as if everything is ok and then presents an error.

Proposed Solution

Attach more context in the output to clearly signal that “hey, this is not correct, check the error message”

image

Notes

this has been implemented in #11098, creating this per request.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 20 (20 by maintainers)

Most upvoted comments

We should either merge the lists of rename it to “disabled features”.

The thing I like about separate lists is that the disabled list is most likely what people will want to search through so this provides a way to shrink it down.

…when things are long like this.

You made me recall this auto-generated feature list. 1505 features in a Cargo.toml

https://github.com/rustwasm/wasm-bindgen/blob/564ce74168904e95a7905a828488ec3029bcaad4/crates/web-sys/Cargo.toml#L31-L1535

This may deserve a new issue if we want to address, along with other places with similar issues.

While the long list is less cluttered, I feel like it undoes the goal of this Issue which is to draw more attention to the error itself. I would prefer the comma-separated list when things are long like this.

so something like this?

There are 3 scenarios

  • A close match is found, suggest that
  • No close matches found but features exist, so list them all
  • No features exist

I don’t see how to do multiple errors from cargo add, is it possible?

In what way are you wanting to do multiple errors?