-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Implement --check-cfg option (RFC 3013) #89346
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It would be useful, I think, it catches issues like The code lives around Line 222 in 6f608ce
|
You can use rust/compiler/rustc_codegen_ssa/src/back/link.rs Line 2445 in 50f9f78
you could either avoid linting, or continue to use |
+1 |
This option doesn't affect expansion at all, though — the only effect is that lints are emitted. I also don't see why we need specifically rustdoc to catch
Wait, this seems like rustdoc specifically disables all lints except for this short list? Are the "unknown condition" lints somehow special enough to warrant adding here? |
Could you add one more non-error test as well - making sure that |
I actually implemented this, last year, when I wrote the RFC. Let me dust off this old branch and see if there's anything worth rescuing from it... |
Btw, you're welcome to grab anything useful from my old branch: https://github.com/sivadeilra/rust/tree/user/ardavis/check_cfg If you do, just credit me. I had it mostly working, but had to set it down for some other work. By the time I returned to this work, |
☔ The latest upstream changes (presumably #89629) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage: |
Ping from triage: @rustbot label: +S-inactive |
Implement --check-cfg option (RFC 3013), take 2 This pull-request implement RFC 3013: Checking conditional compilation at compile time (rust-lang/rfcs#3013) and is based on the previous attempt rust-lang#89346 by `@mwkmwkmwk` that was closed due to inactivity. I have address all the review comments from the previous attempt and added some more tests. cc rust-lang#82450 r? `@petrochenkov`
…eGomez Wire up unstable rustc --check-cfg to rustdoc This pull-request wire up the new unstable `--check-cfg` option from `rustc` to `rustdoc` as [requested](rust-lang#93915 (comment)) in the [pull-request](rust-lang#93915) that introduce `--check-cfg`. The motivation was describe in the original PR by `@jyn514` who wrote rust-lang#89346 (comment): > > add plumbing to pass --check-cfg from rustdoc (do we want this one?) > > It would be useful, I think, it catches issues like cfg(doctst) or something (and in general I would like expansion to match rustc as closely as possible).
…eGomez Wire up unstable rustc --check-cfg to rustdoc This pull-request wire up the new unstable `--check-cfg` option from `rustc` to `rustdoc` as [requested](rust-lang#93915 (comment)) in the [pull-request](rust-lang#93915) that introduce `--check-cfg`. The motivation was describe in the original PR by ``@jyn514`` who wrote rust-lang#89346 (comment): > > add plumbing to pass --check-cfg from rustdoc (do we want this one?) > > It would be useful, I think, it catches issues like cfg(doctst) or something (and in general I would like expansion to match rustc as closely as possible).
This is my attempt at implementing rust-lang/rfcs#3013. I'm not quite sure I'm doing this right, so I'd appreciate some feedback.
One major problem I hit in implementation is finding a good node_id to attach the early lint to: neither the config condition itself nor (for
#[cfg]
) the item that it guards is suitable, because they won't survive the expansion. For now I've attached the lint to crate root, but this is clearly suboptimal — I think the best we can do is using the parent item'snode_id
, but this seems to require a lot of plumbing to get the node_id down to the place where the lint is emitted. Is there some better way to handle this?Also, I haven't implemented the
-Z check-cfg
option specified in the RFC — it seems-Z unstable-options
already works as a feature gate well enough, so there's not much point?Other TODOs:
--check-cfg
from rustdoc (do we want this one?)--check-cfg
(or is this something to be done on stabilization?)target_os
, ...) — perhaps we can even enable the lint by default for those?cc #82450