Skip to content

Commit 1680b79

Browse files
committed
Simplify CfgEval.
It can contain an owned value instead of a reference.
1 parent 7d97c59 commit 1680b79

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

compiler/rustc_builtin_macros/src/cfg_eval.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ pub(crate) fn cfg_eval(
3838
lint_node_id: NodeId,
3939
) -> Annotatable {
4040
let features = Some(features);
41-
CfgEval { cfg: &mut StripUnconfigured { sess, features, config_tokens: true, lint_node_id } }
41+
CfgEval(StripUnconfigured { sess, features, config_tokens: true, lint_node_id })
4242
.configure_annotatable(annotatable)
4343
// Since the item itself has already been configured by the `InvocationCollector`,
4444
// we know that fold result vector will contain exactly one element.
4545
.unwrap()
4646
}
4747

48-
struct CfgEval<'a, 'b> {
49-
cfg: &'a mut StripUnconfigured<'b>,
50-
}
48+
struct CfgEval<'a>(StripUnconfigured<'a>);
5149

5250
fn flat_map_annotatable(
5351
vis: &mut impl MutVisitor,
@@ -125,9 +123,9 @@ fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
125123
res.is_break()
126124
}
127125

128-
impl CfgEval<'_, '_> {
126+
impl CfgEval<'_> {
129127
fn configure<T: HasAttrs + HasTokens>(&mut self, node: T) -> Option<T> {
130-
self.cfg.configure(node)
128+
self.0.configure(node)
131129
}
132130

133131
fn configure_annotatable(&mut self, mut annotatable: Annotatable) -> Option<Annotatable> {
@@ -196,7 +194,7 @@ impl CfgEval<'_, '_> {
196194
// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
197195
// to the captured `AttrTokenStream` (specifically, we capture
198196
// `AttrTokenTree::AttributesData` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
199-
let mut parser = Parser::new(&self.cfg.sess.psess, orig_tokens, None);
197+
let mut parser = Parser::new(&self.0.sess.psess, orig_tokens, None);
200198
parser.capture_cfg = true;
201199
match parse_annotatable_with(&mut parser) {
202200
Ok(a) => annotatable = a,
@@ -212,16 +210,16 @@ impl CfgEval<'_, '_> {
212210
}
213211
}
214212

215-
impl MutVisitor for CfgEval<'_, '_> {
213+
impl MutVisitor for CfgEval<'_> {
216214
#[instrument(level = "trace", skip(self))]
217215
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
218-
self.cfg.configure_expr(expr, false);
216+
self.0.configure_expr(expr, false);
219217
mut_visit::noop_visit_expr(expr, self);
220218
}
221219

222220
#[instrument(level = "trace", skip(self))]
223221
fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) {
224-
self.cfg.configure_expr(expr, true);
222+
self.0.configure_expr(expr, true);
225223
mut_visit::noop_visit_expr(expr, self);
226224
}
227225

0 commit comments

Comments
 (0)