Skip to content

Commit b04de2d

Browse files
committed
gccrs: fix cfg attribute without parentheses error
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 <lucas.ly-ba@outlook.com>
1 parent 7699f7f commit b04de2d

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

gcc/rust/ast/rust-ast.cc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4160,16 +4160,10 @@ Attribute::check_cfg_predicate (const Session &session) const
41604160
auto string_path = path.as_string ();
41614161
/* assume that cfg predicate actually can exist, i.e. attribute has cfg or
41624162
* cfg_attr path */
4163-
if (!has_attr_input ()
4164-
|| (string_path != Values::Attributes::CFG
4165-
&& string_path != Values::Attributes::CFG_ATTR))
4163+
if (!has_attr_input ())
41664164
{
4167-
// DEBUG message
4168-
rust_debug (
4169-
"tried to check cfg predicate on attr that either has no input "
4170-
"or invalid path. attr: '%s'",
4171-
as_string ().c_str ());
4172-
4165+
rust_error_at (path.get_locus (), "%qs is not followed by parentheses",
4166+
string_path.c_str ());
41734167
return false;
41744168
}
41754169

@@ -4178,8 +4172,7 @@ Attribute::check_cfg_predicate (const Session &session) const
41784172
return false;
41794173

41804174
auto &meta_item = static_cast<AttrInputMetaItemContainer &> (*attr_input);
4181-
if (meta_item.get_items ().empty ()
4182-
&& string_path == Values::Attributes::CFG_ATTR)
4175+
if (meta_item.get_items ().empty ())
41834176
{
41844177
rust_error_at (path.get_locus (),
41854178
"malformed %<cfg_attr%> attribute input");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[cfg]
2+
// { dg-error ".cfg. is not followed by parentheses" "" { target *-*-* } .-1 }
3+
fn a() {}

0 commit comments

Comments
 (0)