From: Lucas Ly Ba Date: Thu, 6 Nov 2025 16:26:12 +0000 (+0000) Subject: gccrs: fix cfg attribute error with literal predicate X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63d2fbc4d105e4bd58394217a1a0db869fa5ff10;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 7c6a1d215af..6d37ef7e22f 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() {}