From 646046091b703621c4ba63adb76179c11a1dbb92 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Wed, 28 Feb 2024 21:00:08 -0500 Subject: [PATCH] Allow rustc_const_stable and rustc_const_unstable gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::builtin_transcribers): Add entries for "rustc_const_stable" and "rustc_const_unstable". * util/rust-attributes.cc (__definitions): Add entries for RUSTC_CONST_STABLE and RUSTC_CONST_UNSTABLE. * util/rust-attribute-values.h (Attributes::RUSTC_CONST_STABLE): New. (Attributes::RUSTC_CONST_UNSTABLE): New. gcc/testsuite/ChangeLog: * rust/compile/rustc_const_stable.rs: Enable feature rustc_attrs, expect no errors. * rust/compile/rustc_const_unstable.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/expand/rust-macro-builtins.cc | 2 ++ gcc/rust/util/rust-attribute-values.h | 2 ++ gcc/rust/util/rust-attributes.cc | 5 ++++- gcc/testsuite/rust/compile/rustc_const_stable.rs | 4 +++- gcc/testsuite/rust/compile/rustc_const_unstable.rs | 4 ++++ 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/rustc_const_unstable.rs diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index bc5bc944e772..a6816cf1603a 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -123,6 +123,8 @@ std::unordered_map {"test_case", MacroBuiltin::sorry}, {"global_allocator", MacroBuiltin::sorry}, {"cfg_accessible", MacroBuiltin::sorry}, + {"rustc_const_stable", MacroBuiltin::sorry}, + {"rustc_const_unstable", MacroBuiltin::sorry}, /* Derive builtins do not need a real transcriber, but still need one. It should however never be called since builtin derive macros get expanded differently, and benefit from knowing on what kind of items they are diff --git a/gcc/rust/util/rust-attribute-values.h b/gcc/rust/util/rust-attribute-values.h index a8551c07dba6..a7eaf9ffa70c 100644 --- a/gcc/rust/util/rust-attribute-values.h +++ b/gcc/rust/util/rust-attribute-values.h @@ -53,6 +53,8 @@ class Attributes = "rustc_inherit_overflow_checks"; static constexpr auto &STABLE = "stable"; static constexpr auto &UNSTABLE = "unstable"; + static constexpr auto &RUSTC_CONST_STABLE = "rustc_const_stable"; + static constexpr auto &RUSTC_CONST_UNSTABLE = "rustc_const_unstable"; }; } // namespace Values } // namespace Rust diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 84d1781d0b36..33166673c28a 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -61,7 +61,10 @@ static const BuiltinAttrDefinition __definitions[] {Attrs::RUSTC_DEPRECATED, STATIC_ANALYSIS}, {Attrs::RUSTC_INHERIT_OVERFLOW_CHECKS, CODE_GENERATION}, {Attrs::STABLE, STATIC_ANALYSIS}, - {Attrs::UNSTABLE, STATIC_ANALYSIS}}; + {Attrs::UNSTABLE, STATIC_ANALYSIS}, + // assuming we keep these for static analysis + {Attrs::RUSTC_CONST_STABLE, STATIC_ANALYSIS}, + {Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS}}; BuiltinAttributeMappings * BuiltinAttributeMappings::get () diff --git a/gcc/testsuite/rust/compile/rustc_const_stable.rs b/gcc/testsuite/rust/compile/rustc_const_stable.rs index 9208b1ab3b62..a45355de6b37 100644 --- a/gcc/testsuite/rust/compile/rustc_const_stable.rs +++ b/gcc/testsuite/rust/compile/rustc_const_stable.rs @@ -1,2 +1,4 @@ +#![feature(rustc_attrs)] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] -pub fn foo() {} // { dg-error "macro not found" "" { target *-*-* } .-1 } +pub fn foo() {} diff --git a/gcc/testsuite/rust/compile/rustc_const_unstable.rs b/gcc/testsuite/rust/compile/rustc_const_unstable.rs new file mode 100644 index 000000000000..6cedefade720 --- /dev/null +++ b/gcc/testsuite/rust/compile/rustc_const_unstable.rs @@ -0,0 +1,4 @@ +#![feature(rustc_attrs)] + +#[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "1234")] +pub fn foo() {}