Skip to content

Commit a0ad29e

Browse files
lucasly-baCohenArthur
authored andcommitted
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 87936c8 commit a0ad29e

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

gcc/rust/ast/rust-ast.cc

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

@@ -4181,9 +4175,7 @@ Attribute::check_cfg_predicate (const Session &session) const
41814175
return false;
41824176

41834177
auto &meta_item = static_cast<AttrInputMetaItemContainer &> (*attr_input);
4184-
if (meta_item.get_items ().empty ()
4185-
&& (string_path == Values::Attributes::CFG
4186-
|| string_path == Values::Attributes::CFG_ATTR))
4178+
if (meta_item.get_items ().empty ())
41874179
{
41884180
rust_error_at (path.get_locus (), "malformed %<%s%> attribute input",
41894181
string_path.c_str ());
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)