]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: add outer attributes
authorMason Pike <m@sonpike.net>
Fri, 26 Dec 2025 15:06:51 +0000 (16:06 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 27 Feb 2026 14:57:08 +0000 (15:57 +0100)
gcc/rust/ChangeLog:
* util/rust-attributes.cc: add attributes to the __outer_attributes set.
This prevents some inconsistent behavior, like: https://godbolt.org/z/Eq1GE7xxY

Signed-off-by: Mason Pike <m@sonpike.net>
gcc/rust/util/rust-attributes.cc
gcc/testsuite/rust/compile/no-crate-level-outer-attr.rs [new file with mode: 0644]

index 8c7e0639b857aec844770819f4199509f1c4ea1c..1f465f2bda1673bb8f084c49e886c75f2398326c 100644 (file)
@@ -124,9 +124,23 @@ static const BuiltinAttrDefinition __definitions[]
      {Attrs::TEST, CODE_GENERATION}};
 
 static const std::set<std::string> __outer_attributes
-  = {Attrs::INLINE,        Attrs::DERIVE_ATTR, Attrs::ALLOW_INTERNAL_UNSTABLE,
-     Attrs::LANG,          Attrs::REPR,        Attrs::PATH,
-     Attrs::TARGET_FEATURE, Attrs::TEST};
+  = {Attrs::INLINE,
+     Attrs::DERIVE_ATTR,
+     Attrs::ALLOW_INTERNAL_UNSTABLE,
+     Attrs::LANG,
+     Attrs::REPR,
+     Attrs::PATH,
+     Attrs::TARGET_FEATURE,
+     Attrs::TEST,
+     Attrs::COLD,
+     Attrs::MACRO_USE,
+     Attrs::MACRO_EXPORT,
+     Attrs::PROC_MACRO_ATTRIBUTE,
+     Attrs::PROC_MACRO_DERIVE,
+     Attrs::DEPRECATED,
+     Attrs::MUST_USE,
+     Attrs::LINK_NAME,
+     Attrs::LINK_SECTION};
 
 BuiltinAttributeMappings *
 BuiltinAttributeMappings::get ()
diff --git a/gcc/testsuite/rust/compile/no-crate-level-outer-attr.rs b/gcc/testsuite/rust/compile/no-crate-level-outer-attr.rs
new file mode 100644 (file)
index 0000000..a238c28
--- /dev/null
@@ -0,0 +1,2 @@
+#![cold] // { dg-error "attribute cannot be used at crate level" }
+pub fn test() {}