Skip to content

Commit c1f0321

Browse files
committed
Use an attribute whitelist
1 parent 895011d commit c1f0321

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

src/libsyntax/feature_gate.rs

+55
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,59 @@ fn contains_novel_literal(item: &ast::MetaItem) -> bool {
14121412
}
14131413

14141414
impl<'a> PostExpansionVisitor<'a> {
1415+
fn check_modular_attr(&mut self, attr: &ast::Attribute) {
1416+
if !self.context.parse_sess.combine_tests {
1417+
return;
1418+
}
1419+
if let Some(name) = attr.name() {
1420+
let whitelist = &[
1421+
"feature",
1422+
"path",
1423+
"deny",
1424+
"allow",
1425+
"forbid",
1426+
"doc",
1427+
"repr",
1428+
"derive",
1429+
"automatically_derived",
1430+
"rustc_copy_clone_marker",
1431+
"structural_match",
1432+
"unsafe_destructor_blind_to_params",
1433+
"cfg",
1434+
"macro_use",
1435+
"inline",
1436+
"used",
1437+
"thread_local",
1438+
"macro_export",
1439+
"may_dangle",
1440+
"unwind",
1441+
"link",
1442+
"link_name",
1443+
"link_section",
1444+
"export_name",
1445+
"no_mangle",
1446+
"non_exhaustive",
1447+
"target_feature",
1448+
"prelude_import"];
1449+
if !whitelist.iter().any(|a| &*name.as_str() == *a) &&
1450+
!attr.is_sugared_doc {
1451+
let mut err = self.context.parse_sess.span_diagnostic.struct_span_err(
1452+
attr.span,
1453+
&format!("combined test has unknown attribute `{}`", name)
1454+
);
1455+
err.help("add `// no-combine` at the top of the test file");
1456+
err.emit();
1457+
}
1458+
} else {
1459+
let mut err = self.context.parse_sess.span_diagnostic.struct_span_err(
1460+
attr.span,
1461+
&format!("combined test has unnamed attribute")
1462+
);
1463+
err.help("add `// no-combine` at the top of the test file");
1464+
err.emit();
1465+
}
1466+
}
1467+
14151468
fn visit_module_item(&mut self, item: &'a ast::Item) {
14161469
let is_module = match item.node {
14171470
ast::ItemKind::Mod(ast::Mod { inner, .. }) => Some(inner),
@@ -1488,6 +1541,8 @@ impl<'a> PostExpansionVisitor<'a> {
14881541

14891542
impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
14901543
fn visit_attribute(&mut self, attr: &ast::Attribute) {
1544+
self.check_modular_attr(attr);
1545+
14911546
if !attr.span.allows_unstable() {
14921547
// check for gated attributes
14931548
self.context.check_attribute(attr, false);

src/test/codegen/stack-probes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
// compile-flags: -C no-prepopulate-passes
2121

2222
#![crate_type = "lib"]
23-
23+
struct A;
24+
use $crate::A; // FIXME
2425
#[no_mangle]
2526
pub fn foo() {
2627
// CHECK: @foo() unnamed_addr #0

src/tools/compiletest/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ pub fn make_test(config: &Arc<Config>, testpaths: &TestPaths) -> test::TestDescA
648648
// FIXME: Parse and group by `recursion_limit`
649649
// FIXME: Parse and group by crate attributes?
650650

651-
let feature_blacklist = ["main", "start", "no_std", "no_core"];
651+
let feature_blacklist = ["main", "custom_attribute", "rustc_attrs", "start", "no_std", "no_core"];
652652

653653
let combine = config.combine &&
654654
props.aux_builds.is_empty() &&

0 commit comments

Comments
 (0)