diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 337a338f9a3..7a9c1085bed 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -4179,10 +4179,11 @@ Attribute::check_cfg_predicate (const Session &session) const auto &meta_item = static_cast (*attr_input); if (meta_item.get_items ().empty () - && string_path == Values::Attributes::CFG_ATTR) + && (string_path == Values::Attributes::CFG + || string_path == Values::Attributes::CFG_ATTR)) { - rust_error_at (path.get_locus (), - "malformed % attribute input"); + rust_error_at (path.get_locus (), "malformed %<%s%> attribute input", + string_path.c_str ()); return false; } return meta_item.get_items ().front ()->check_cfg_predicate (session); diff --git a/gcc/testsuite/rust/compile/issue-4261.rs b/gcc/testsuite/rust/compile/issue-4261.rs new file mode 100644 index 00000000000..32beafade54 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4261.rs @@ -0,0 +1,3 @@ +#[cfg()] +// { dg-error "malformed .cfg. attribute input" "" { target *-*-* } .-1 } +fn a() {}