From a3942e73e523ebdc2281717351266ed7969ffd05 Mon Sep 17 00:00:00 2001 From: Lucas Ly Ba Date: Thu, 6 Nov 2025 16:26:12 +0000 Subject: [PATCH] gccrs: fix cfg attribute error with literal predicate gcc/rust/ChangeLog: * ast/rust-ast.cc (MetaItemLitExpr::check_cfg_predicate): Make error. gcc/testsuite/ChangeLog: * rust/compile/issue-4222.rs: New test. Signed-off-by: Lucas Ly Ba --- gcc/rust/ast/rust-ast.cc | 3 +++ gcc/testsuite/rust/compile/issue-4222.rs | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-4222.rs diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 337a338f9a3..6b79f7b70d8 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -3834,6 +3834,9 @@ MetaItemLitExpr::check_cfg_predicate (const Session &) const { /* as far as I can tell, a literal expr can never be a valid cfg body, so * false */ + rust_error_at (this->get_locus (), "'%s' predicate key cannot be a literal", + this->as_string ().c_str ()); + return false; } diff --git a/gcc/testsuite/rust/compile/issue-4222.rs b/gcc/testsuite/rust/compile/issue-4222.rs new file mode 100644 index 00000000000..b829c6f6f54 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4222.rs @@ -0,0 +1,3 @@ +#![cfg(false)] +// { dg-error ".false. predicate key cannot be a literal" "" { target *-*-* } .-1 } +fn a() {}