-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Port #[cfg]
to the new attribute parsing infrastructure
#143460
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
base: master
Are you sure you want to change the base?
Conversation
I don't understand what is the point of this, at high level. |
Or is this is going to be only about cfg predicates that live inside |
@jdonszelmann might be able to explain better, she has been supporting me, but I'll try my best. We already have some infrastructure for parsing attributes in the early stage, before the HIR, and this is already used for the Furthermore as you mentioned some attributes like |
2da5a4c
to
433025a
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #143526) made this pull request unmergeable. Please resolve the merge conflicts. |
433025a
to
8a1e8fb
Compare
8a1e8fb
to
60e69b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rustbot ready
r? @jdonszelmann
@@ -0,0 +1,247 @@ | |||
use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NodeId}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is temporarily still needed for the following things: #[doc]
, #[link]
, cfg!()
, #[cfg_attr]
.
In the future this file, as well as a few others, should no longer be needed, but making these attributes use the new cfg parser is sadly not easily possible without parsing the entire attributes.
As well as this file, there is also the Cfg
type in rustdoc and all errors associated with this file. All in all this PR could have a significantly negative diff (all of this is like ~600 lines of code) if not for this
pub(crate) fn cfg_true(&self, attr: &Attribute, node: NodeId) -> EvalConfigResult { | ||
// We need to run this to do basic validation of the attribute, such as that lits are valid, etc | ||
// FIXME(jdonszelmann) this should not be necessary in the future | ||
match validate_attr::parse_meta(&self.sess.psess, attr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly this is needed, @jdonszelmann are you aware of this / do you have any plans to fix this?
We're also still parsing all the other attributes using both the old and new parser for this, probably not performance sensitive but a bit weird
pub fn main() {} | ||
pub fn main() { | ||
if cfg!(not()) { } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error code will not be needed in the future (as wel as many others), but needed a new example for now
/// Whether to emit errors or delay them as a bug | ||
/// For most attributes, the attribute will be parsed again in the `Late` stage and in this case the errors should be delayed | ||
/// But for some, such as `cfg`, the attribute will be removed before the `Late` stage so errors must be emitted | ||
pub emit_errors: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is needed because #[cfg]
will not be parsed in the Late
stage, so we need to emit all errors/warnings now
|
Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_attr_data_structures Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
| | ||
LL | #[cfg(false)] | ||
| ^^^^^^^^^^^^^ | ||
| ^^^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a small change here, this error will now always point to the exact part of the cfg
attribute that makes the attribute false
Ports
#[cfg]
to the new attribute parsing infrastructure for #131229 (comment)I've split this PR into commits for reviewability, and left some comments to clarify things