Add some comments.
Explaining things that took me some time to work out.
This commit is contained in:
parent
d6ebbbfcb2
commit
478ba59026
@ -269,11 +269,14 @@ fn attrs_and_tokens_to_token_trees(
|
|||||||
/// with its attributes.
|
/// with its attributes.
|
||||||
///
|
///
|
||||||
/// This is constructed during parsing when we need to capture
|
/// This is constructed during parsing when we need to capture
|
||||||
/// tokens.
|
/// tokens, for `cfg` and `cfg_attr` attributes.
|
||||||
///
|
///
|
||||||
/// For example, `#[cfg(FALSE)] struct Foo {}` would
|
/// For example, `#[cfg(FALSE)] struct Foo {}` would
|
||||||
/// have an `attrs` field containing the `#[cfg(FALSE)]` attr,
|
/// have an `attrs` field containing the `#[cfg(FALSE)]` attr,
|
||||||
/// and a `tokens` field storing the (unparsed) tokens `struct Foo {}`
|
/// and a `tokens` field storing the (unparsed) tokens `struct Foo {}`
|
||||||
|
///
|
||||||
|
/// The `cfg`/`cfg_attr` processing occurs in
|
||||||
|
/// `StripUnconfigured::configure_tokens`.
|
||||||
#[derive(Clone, Debug, Encodable, Decodable)]
|
#[derive(Clone, Debug, Encodable, Decodable)]
|
||||||
pub struct AttrsTarget {
|
pub struct AttrsTarget {
|
||||||
/// Attributes, both outer and inner.
|
/// Attributes, both outer and inner.
|
||||||
|
@ -187,6 +187,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter_map(|tree| match tree.clone() {
|
.filter_map(|tree| match tree.clone() {
|
||||||
AttrTokenTree::AttrsTarget(mut target) => {
|
AttrTokenTree::AttrsTarget(mut target) => {
|
||||||
|
// Expand any `cfg_attr` attributes.
|
||||||
target.attrs.flat_map_in_place(|attr| self.process_cfg_attr(&attr));
|
target.attrs.flat_map_in_place(|attr| self.process_cfg_attr(&attr));
|
||||||
|
|
||||||
if self.in_cfg(&target.attrs) {
|
if self.in_cfg(&target.attrs) {
|
||||||
@ -195,6 +196,8 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
);
|
);
|
||||||
Some(AttrTokenTree::AttrsTarget(target))
|
Some(AttrTokenTree::AttrsTarget(target))
|
||||||
} else {
|
} else {
|
||||||
|
// Remove the target if there's a `cfg` attribute and
|
||||||
|
// the condition isn't satisfied.
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user