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

Emit error on [target.'cfg(debug_assertions)'.dependencies] and similar #7660

Merged
merged 4 commits into from
Dec 9, 2019

Conversation

benediktwerner
Copy link
Contributor

@benediktwerner benediktwerner commented Dec 4, 2019

Closes #7634

Cargo now emits an error if an unsupported cfg key or name is used for specifying a target.

This PR also updates the docs to clarify this behavior.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 4, 2019
@benediktwerner benediktwerner changed the title Emit error on [target.cfg(debug_assertions).dependencies] and similar Emit error on [target.'cfg(debug_assertions)'.dependencies] and similar Dec 4, 2019
@benediktwerner
Copy link
Contributor Author

benediktwerner commented Dec 4, 2019

Ok, it looks like a few of the tests are using invalid keys. Is there a reason for this, like a way to provide custom cfg values? Should I fix the tests or should cargo maybe only error on debug_assertions etc. and feature = ...?

@alexcrichton
Copy link
Member

Thanks for the PR! I think we'll probably want a blacklist as opposed to a whitelist of names, since you can also affect dependency selection with RUSTFLAGS. That means that I don't think we can write down an exhaustive whitelist of names that can be included and matched on

@benediktwerner
Copy link
Contributor Author

Ok, makes sense, I changed it to only error on test, debug_assertions, proc_macro and feature = ....

@alexcrichton
Copy link
Member

Looks good to me! I'm curious though, I would suspect that this should start out as a warning, but @ehuss could you elaborate why you thought it should be an error?

@ehuss
Copy link
Contributor

ehuss commented Dec 5, 2019

why you thought it should be an error?

I don't feel strongly about it, it's just that it is an invalid configuration that is not going to work correctly. I'd be happy with a warning. I did a quick scan on crates.io, and found the following manifests that use one of these patterns:

debug_assertions:

  • rocket_contrib 0.4.2

test:

  • com_ptr 0.1.2
  • tokio-net-0.2.0-alpha.6

feature:

  • aes-0.3.2
  • aes-ctr-0.3.0
  • collision-0.20.1
  • font-rs-0.1.3
  • hyper-thread-random-0.4.2
  • iban_validate-3.0.0
  • instant-0.1.2
  • label_attribute-0.1.1
  • ldap3-0.6.1
  • lokacore-0.3.0
  • mgf-1.3.0
  • miscreant-0.4.2
  • orbclient-0.3.27
  • resid-rs-1.0.3
  • rhusics-core-0.7.0
  • rhusics-ecs-0.7.0
  • sacn-0.4.4
  • slice-deque-0.3.0
  • tokio-0.2.0-alpha.6
  • tracing-0.1.10
  • tracing-core-0.1.7
  • wasm-bindgen-futures-0.4.4
  • xplm-0.2.2
  • yew-0.10.0 (.cargo/config)

That's a fairly large number.

I'd also like if this could include more help in the error message, since "invalid" is a little terse. I'm not sure how to word it, but something along the lines to indicate that those keys are not supported by Cargo in target expressions. Particularly feature="…" could maybe use some guidance on what to do instead, though that is only relevant to dependencies. Config files don't have an alternative that I can think of.

@benediktwerner
Copy link
Contributor Author

Better error messages would definitely be good, but I wasn't quite sure about the best way to do this. It doesn't look like there is any more advanced error reporting mechanism in cargo, right? So should I just make the Display output for the error more explicit?

It might also be a good idea to link to the docs. Maybe something like this: Invalid cfg key: feature. This key is not supported in target configurations. Use the [features] section instead: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section and Invalid cfg value: debug_assertions. This value is not supported in target configurations. To learn more visit https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies

A warning would obviously work as well, but that would require some slight changes since I don't think it's possible to warn from cargo-platforms.

@alexcrichton
Copy link
Member

The manifest parsing section of Cargo has the ability to emit warnings, so perhaps that would be a good place to put informational messages?

@benediktwerner
Copy link
Contributor Author

Ok, I changed it so that it warns when parsing the manifest. Not sure if it makes sense to keep that code in cargo-platform but I also didn't find a better place and in the end, it is about the platform after all.

@alexcrichton
Copy link
Member

@bors: r+

Looks great to me, thanks!

@bors
Copy link
Contributor

bors commented Dec 9, 2019

📌 Commit aa93f61 has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 9, 2019
@bors
Copy link
Contributor

bors commented Dec 9, 2019

⌛ Testing commit aa93f61 with merge 774d949...

bors added a commit that referenced this pull request Dec 9, 2019
Emit error on [target.'cfg(debug_assertions)'.dependencies] and similar

Closes #7634

Cargo now emits an error if an unsupported cfg key or name is used for specifying a target.

This PR also updates the docs to clarify this behavior.
@bors
Copy link
Contributor

bors commented Dec 9, 2019

☀️ Test successful - checks-azure
Approved by: alexcrichton
Pushing 774d949 to master...

@bors bors merged commit aa93f61 into rust-lang:master Dec 9, 2019
bors added a commit that referenced this pull request Dec 10, 2019
Bump cargo-platform version.

Needed for changes from #7660.
Centril added a commit to Centril/rust that referenced this pull request Dec 15, 2019
Update cargo, books

Update nomicon, cargo, reference, book, rust-by-example, embedded-book

## nomicon

2 commits in 041c46e692a2592853aeca132c8dfe8eb5a79a9e..8be35b201f9cf0a4c3fcc96c83ac21671dcf3112
2019-11-20 16:46:45 +0100 to 2019-12-01 13:02:12 -0500
- Update unwinding.md
- ci: remove needless rust-docs component

## cargo

15 commits in 626f0f40efd32e6b3dbade50cd53fdfaa08446ba..5a139f7e6d67fd8a416a3f19d8e01581d24c0333
2019-12-03 16:53:04 +0000 to 2019-12-10 20:17:50 +0000
- Bump cargo-platform version. (rust-lang/cargo#7693)
- Add a test for `cargo locate-project` (rust-lang/cargo#7690)
- Emit error on [target.'cfg(debug_assertions)'.dependencies] and similar (rust-lang/cargo#7660)
- Update the layout of `Cargo Commands` in doc (rust-lang/cargo#7687)
- Features and dependencies can't have the same name (rust-lang/cargo#7682)
- Fix some typos in doc (rust-lang/cargo#7672)
- Add test for `NAME` environment variable when `cargo new` (rust-lang/cargo#7667)
- Add test for `GIT_COMMITTER_EMAIL` when `cargo new` (rust-lang/cargo#7666)
- document support for Bitbucket Pipelines badges (rust-lang/cargo#7663)
- Add cargo-vendor to the list of cargo commands in doc (rust-lang/cargo#7659)
- Fix typo in section 'Caching the Cargo home in CI' (rust-lang/cargo#7661)
- Docs: Add an appendix on git authentication. (rust-lang/cargo#7658)
- Remove --offline empty index error. (rust-lang/cargo#7655)
- Change the link destination of cargo book contribution (rust-lang/cargo#7657)
- Add a --offline hint. (rust-lang/cargo#7654)

## reference

2 commits in 9e843ae..787e8d8
2019-11-24 17:44:04 +0100 to 2019-12-10 10:01:29 -0800
- Update for visibility syntax changes. (rust-lang/reference#722)
- document `bind_by_move_pattern_guards` (rust-lang/reference#720)

## book

2 commits in 81ebaa2a3f88d4d106516c489682e64cacba4f60..ef8bb568035ded8ddfa30a9309026638cc3c8136
2019-11-15 08:30:04 -0800 to 2019-11-28 11:00:04 -0600
- Remove optional commas from match arms in ch18-03 (rust-lang/book#2176)
- Remove call_box() from ch20-03 (rust-lang/book#2177)

## rust-by-example

1 commits in 4835e025826729827a94fdeb7cb85fed288d08bb..b7ac1bc76b7d02a43c83b3a931d226f708aa1ff4
2019-11-14 09:20:43 -0300 to 2019-12-02 11:38:43 -0300
- Make TryFrom & TryInto example editable (rust-lang/rust-by-example#1297)

## embedded-book

1 commits in 5ca585c4a7552efb546e7681c3de0712f4ae4fdc..c26234930282210849256e4ecab925f0f2daf3be
2019-08-27 13:39:14 +0000 to 2019-12-07 17:25:11 +0000
- Fix `impl Gpio` -> `impl GpioConfig`  (rust-embedded/book#216)
Centril added a commit to Centril/rust that referenced this pull request Dec 15, 2019
Update cargo, books

Update nomicon, cargo, reference, book, rust-by-example, embedded-book

## nomicon

2 commits in 041c46e692a2592853aeca132c8dfe8eb5a79a9e..8be35b201f9cf0a4c3fcc96c83ac21671dcf3112
2019-11-20 16:46:45 +0100 to 2019-12-01 13:02:12 -0500
- Update unwinding.md
- ci: remove needless rust-docs component

## cargo

15 commits in 626f0f40efd32e6b3dbade50cd53fdfaa08446ba..5a139f7e6d67fd8a416a3f19d8e01581d24c0333
2019-12-03 16:53:04 +0000 to 2019-12-10 20:17:50 +0000
- Bump cargo-platform version. (rust-lang/cargo#7693)
- Add a test for `cargo locate-project` (rust-lang/cargo#7690)
- Emit error on [target.'cfg(debug_assertions)'.dependencies] and similar (rust-lang/cargo#7660)
- Update the layout of `Cargo Commands` in doc (rust-lang/cargo#7687)
- Features and dependencies can't have the same name (rust-lang/cargo#7682)
- Fix some typos in doc (rust-lang/cargo#7672)
- Add test for `NAME` environment variable when `cargo new` (rust-lang/cargo#7667)
- Add test for `GIT_COMMITTER_EMAIL` when `cargo new` (rust-lang/cargo#7666)
- document support for Bitbucket Pipelines badges (rust-lang/cargo#7663)
- Add cargo-vendor to the list of cargo commands in doc (rust-lang/cargo#7659)
- Fix typo in section 'Caching the Cargo home in CI' (rust-lang/cargo#7661)
- Docs: Add an appendix on git authentication. (rust-lang/cargo#7658)
- Remove --offline empty index error. (rust-lang/cargo#7655)
- Change the link destination of cargo book contribution (rust-lang/cargo#7657)
- Add a --offline hint. (rust-lang/cargo#7654)

## reference

2 commits in 9e843ae..787e8d8
2019-11-24 17:44:04 +0100 to 2019-12-10 10:01:29 -0800
- Update for visibility syntax changes. (rust-lang/reference#722)
- document `bind_by_move_pattern_guards` (rust-lang/reference#720)

## book

2 commits in 81ebaa2a3f88d4d106516c489682e64cacba4f60..ef8bb568035ded8ddfa30a9309026638cc3c8136
2019-11-15 08:30:04 -0800 to 2019-11-28 11:00:04 -0600
- Remove optional commas from match arms in ch18-03 (rust-lang/book#2176)
- Remove call_box() from ch20-03 (rust-lang/book#2177)

## rust-by-example

1 commits in 4835e025826729827a94fdeb7cb85fed288d08bb..b7ac1bc76b7d02a43c83b3a931d226f708aa1ff4
2019-11-14 09:20:43 -0300 to 2019-12-02 11:38:43 -0300
- Make TryFrom & TryInto example editable (rust-lang/rust-by-example#1297)

## embedded-book

1 commits in 5ca585c4a7552efb546e7681c3de0712f4ae4fdc..c26234930282210849256e4ecab925f0f2daf3be
2019-08-27 13:39:14 +0000 to 2019-12-07 17:25:11 +0000
- Fix `impl Gpio` -> `impl GpioConfig`  (rust-embedded/book#216)
bors added a commit to rust-lang/rust that referenced this pull request Dec 21, 2019
Update cargo, books

Update nomicon, cargo, reference, book, rust-by-example, embedded-book

## nomicon

2 commits in 041c46e692a2592853aeca132c8dfe8eb5a79a9e..8be35b201f9cf0a4c3fcc96c83ac21671dcf3112
2019-11-20 16:46:45 +0100 to 2019-12-01 13:02:12 -0500
- Update unwinding.md
- ci: remove needless rust-docs component

## cargo

15 commits in 626f0f40efd32e6b3dbade50cd53fdfaa08446ba..5a139f7e6d67fd8a416a3f19d8e01581d24c0333
2019-12-03 16:53:04 +0000 to 2019-12-10 20:17:50 +0000
- Bump cargo-platform version. (rust-lang/cargo#7693)
- Add a test for `cargo locate-project` (rust-lang/cargo#7690)
- Emit error on [target.'cfg(debug_assertions)'.dependencies] and similar (rust-lang/cargo#7660)
- Update the layout of `Cargo Commands` in doc (rust-lang/cargo#7687)
- Features and dependencies can't have the same name (rust-lang/cargo#7682)
- Fix some typos in doc (rust-lang/cargo#7672)
- Add test for `NAME` environment variable when `cargo new` (rust-lang/cargo#7667)
- Add test for `GIT_COMMITTER_EMAIL` when `cargo new` (rust-lang/cargo#7666)
- document support for Bitbucket Pipelines badges (rust-lang/cargo#7663)
- Add cargo-vendor to the list of cargo commands in doc (rust-lang/cargo#7659)
- Fix typo in section 'Caching the Cargo home in CI' (rust-lang/cargo#7661)
- Docs: Add an appendix on git authentication. (rust-lang/cargo#7658)
- Remove --offline empty index error. (rust-lang/cargo#7655)
- Change the link destination of cargo book contribution (rust-lang/cargo#7657)
- Add a --offline hint. (rust-lang/cargo#7654)

## reference

2 commits in 9e843ae..787e8d8
2019-11-24 17:44:04 +0100 to 2019-12-10 10:01:29 -0800
- Update for visibility syntax changes. (rust-lang/reference#722)
- document `bind_by_move_pattern_guards` (rust-lang/reference#720)

## book

2 commits in 81ebaa2a3f88d4d106516c489682e64cacba4f60..ef8bb568035ded8ddfa30a9309026638cc3c8136
2019-11-15 08:30:04 -0800 to 2019-11-28 11:00:04 -0600
- Remove optional commas from match arms in ch18-03 (rust-lang/book#2176)
- Remove call_box() from ch20-03 (rust-lang/book#2177)

## rust-by-example

1 commits in 4835e025826729827a94fdeb7cb85fed288d08bb..b7ac1bc76b7d02a43c83b3a931d226f708aa1ff4
2019-11-14 09:20:43 -0300 to 2019-12-02 11:38:43 -0300
- Make TryFrom & TryInto example editable (rust-lang/rust-by-example#1297)

## embedded-book

1 commits in 5ca585c4a7552efb546e7681c3de0712f4ae4fdc..c26234930282210849256e4ecab925f0f2daf3be
2019-08-27 13:39:14 +0000 to 2019-12-07 17:25:11 +0000
- Fix `impl Gpio` -> `impl GpioConfig`  (rust-embedded/book#216)
jebrosen added a commit to rwf2/Rocket that referenced this pull request Jan 19, 2020
….toml.

This is not supported and is the same as putting the contents in
[dependencies] anyway. It became a warning in rust-lang/cargo#7660.
jebrosen added a commit to jebrosen/Rocket that referenced this pull request Mar 6, 2020
….toml.

This is not supported and is the same as putting the contents in
[dependencies] anyway. It became a warning in rust-lang/cargo#7660.
RalfJung pushed a commit to RalfJung/Rocket that referenced this pull request Mar 8, 2020
….toml.

This is not supported and is the same as putting the contents in
[dependencies] anyway. It became a warning in rust-lang/cargo#7660.

Backport of 4151cd4.
@ehuss ehuss added this to the 1.42.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

target.'cfg(debug_assertions)'.dependencies doesn't work as expected
5 participants