From: Lucas Ly Ba <[email protected]>
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Attribute::check_cfg_predicate): Make error when
attribute has no input.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4262.rs: New test.
Signed-off-by: Lucas Ly Ba <[email protected]>
---
gcc/rust/ast/rust-ast.cc | 16 ++++------------
gcc/testsuite/rust/compile/issue-4262.rs | 3 +++
2 files changed, 7 insertions(+), 12 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-4262.rs
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index f3ad2fe5da0..d8713071c4c 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4163,16 +4163,10 @@ Attribute::check_cfg_predicate (const Session &session)
const
auto string_path = path.as_string ();
/* assume that cfg predicate actually can exist, i.e. attribute has cfg or
* cfg_attr path */
- if (!has_attr_input ()
- || (string_path != Values::Attributes::CFG
- && string_path != Values::Attributes::CFG_ATTR))
+ if (!has_attr_input ())
{
- // DEBUG message
- rust_debug (
- "tried to check cfg predicate on attr that either has no input "
- "or invalid path. attr: '%s'",
- as_string ().c_str ());
-
+ rust_error_at (path.get_locus (), "%qs is not followed by parentheses",
+ string_path.c_str ());
return false;
}
@@ -4181,9 +4175,7 @@ Attribute::check_cfg_predicate (const Session &session)
const
return false;
auto &meta_item = static_cast<AttrInputMetaItemContainer &> (*attr_input);
- if (meta_item.get_items ().empty ()
- && (string_path == Values::Attributes::CFG
- || string_path == Values::Attributes::CFG_ATTR))
+ if (meta_item.get_items ().empty ())
{
rust_error_at (path.get_locus (), "malformed %<%s%> attribute input",
string_path.c_str ());
diff --git a/gcc/testsuite/rust/compile/issue-4262.rs
b/gcc/testsuite/rust/compile/issue-4262.rs
new file mode 100644
index 00000000000..2ce1cb49afa
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4262.rs
@@ -0,0 +1,3 @@
+#[cfg]
+// { dg-error ".cfg. is not followed by parentheses" "" { target *-*-* } .-1 }
+fn a() {}
--
2.50.1