Skip to content

Commit 63ee3fe

Browse files
author
Keegan McAllister
committed
Consolidate ExpansionConfig feature tests
1 parent 4d716de commit 63ee3fe

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,19 @@ pub struct ExpansionConfig<'feat> {
14471447
pub recursion_limit: usize,
14481448
}
14491449

1450+
macro_rules! feature_tests {
1451+
($( fn $getter:ident = $field:ident, )*) => {
1452+
$(
1453+
pub fn $getter(&self) -> bool {
1454+
match self.features {
1455+
Some(&Features { $field: true, .. }) => true,
1456+
_ => false,
1457+
}
1458+
}
1459+
)*
1460+
}
1461+
}
1462+
14501463
impl<'feat> ExpansionConfig<'feat> {
14511464
pub fn default(crate_name: String) -> ExpansionConfig<'static> {
14521465
ExpansionConfig {
@@ -1456,46 +1469,13 @@ impl<'feat> ExpansionConfig<'feat> {
14561469
}
14571470
}
14581471

1459-
pub fn enable_quotes(&self) -> bool {
1460-
match self.features {
1461-
Some(&Features { allow_quote: true, .. }) => true,
1462-
_ => false,
1463-
}
1464-
}
1465-
1466-
pub fn enable_asm(&self) -> bool {
1467-
match self.features {
1468-
Some(&Features { allow_asm: true, .. }) => true,
1469-
_ => false,
1470-
}
1471-
}
1472-
1473-
pub fn enable_log_syntax(&self) -> bool {
1474-
match self.features {
1475-
Some(&Features { allow_log_syntax: true, .. }) => true,
1476-
_ => false,
1477-
}
1478-
}
1479-
1480-
pub fn enable_concat_idents(&self) -> bool {
1481-
match self.features {
1482-
Some(&Features { allow_concat_idents: true, .. }) => true,
1483-
_ => false,
1484-
}
1485-
}
1486-
1487-
pub fn enable_trace_macros(&self) -> bool {
1488-
match self.features {
1489-
Some(&Features { allow_trace_macros: true, .. }) => true,
1490-
_ => false,
1491-
}
1492-
}
1493-
1494-
pub fn enable_allow_internal_unstable(&self) -> bool {
1495-
match self.features {
1496-
Some(&Features { allow_internal_unstable: true, .. }) => true,
1497-
_ => false
1498-
}
1472+
feature_tests! {
1473+
fn enable_quotes = allow_quote,
1474+
fn enable_asm = allow_asm,
1475+
fn enable_log_syntax = allow_log_syntax,
1476+
fn enable_concat_idents = allow_concat_idents,
1477+
fn enable_trace_macros = allow_trace_macros,
1478+
fn enable_allow_internal_unstable = allow_internal_unstable,
14991479
}
15001480
}
15011481

0 commit comments

Comments
 (0)