Skip to content

Commit 478ba59

Browse files
committed
Add some comments.
Explaining things that took me some time to work out.
1 parent d6ebbbf commit 478ba59

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/rustc_ast/src/tokenstream.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,14 @@ fn attrs_and_tokens_to_token_trees(
269269
/// with its attributes.
270270
///
271271
/// This is constructed during parsing when we need to capture
272-
/// tokens.
272+
/// tokens, for `cfg` and `cfg_attr` attributes.
273273
///
274274
/// For example, `#[cfg(FALSE)] struct Foo {}` would
275275
/// have an `attrs` field containing the `#[cfg(FALSE)]` attr,
276276
/// and a `tokens` field storing the (unparsed) tokens `struct Foo {}`
277+
///
278+
/// The `cfg`/`cfg_attr` processing occurs in
279+
/// `StripUnconfigured::configure_tokens`.
277280
#[derive(Clone, Debug, Encodable, Decodable)]
278281
pub struct AttrsTarget {
279282
/// Attributes, both outer and inner.

compiler/rustc_expand/src/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ impl<'a> StripUnconfigured<'a> {
187187
.iter()
188188
.filter_map(|tree| match tree.clone() {
189189
AttrTokenTree::AttrsTarget(mut target) => {
190+
// Expand any `cfg_attr` attributes.
190191
target.attrs.flat_map_in_place(|attr| self.process_cfg_attr(&attr));
191192

192193
if self.in_cfg(&target.attrs) {
@@ -195,6 +196,8 @@ impl<'a> StripUnconfigured<'a> {
195196
);
196197
Some(AttrTokenTree::AttrsTarget(target))
197198
} else {
199+
// Remove the target if there's a `cfg` attribute and
200+
// the condition isn't satisfied.
198201
None
199202
}
200203
}

0 commit comments

Comments
 (0)