]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix cfg attribute error with literal predicate
authorLucas Ly Ba <lucas.ly-ba@outlook.com>
Thu, 6 Nov 2025 16:26:12 +0000 (16:26 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Nov 2025 14:58:18 +0000 (15:58 +0100)
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 <lucas.ly-ba@outlook.com>
gcc/rust/ast/rust-ast.cc
gcc/testsuite/rust/compile/issue-4222.rs [new file with mode: 0644]

index 7c6a1d215af8e91b309160743f451cc4b3bd35c1..6d37ef7e22fb8ab3d60955cd2d27111f8dc2dd7a 100644 (file)
@@ -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 (file)
index 0000000..b829c6f
--- /dev/null
@@ -0,0 +1,3 @@
+#![cfg(false)]
+// { dg-error ".false. predicate key cannot be a literal" "" { target *-*-* } .-1 }
+fn a() {}