Skip to content

Commit

Permalink
Allow rustc_const_stable and rustc_const_unstable
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
powerboat9 authored and P-E-P committed May 29, 2024
1 parent 9ade15d commit 6460460
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions gcc/rust/expand/rust-macro-builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ std::unordered_map<std::string, AST::MacroTranscriberFunc>
{"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
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/util/rust-attribute-values.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion gcc/rust/util/rust-attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
4 changes: 3 additions & 1 deletion gcc/testsuite/rust/compile/rustc_const_stable.rs
Original file line number Diff line number Diff line change
@@ -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() {}
4 changes: 4 additions & 0 deletions gcc/testsuite/rust/compile/rustc_const_unstable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![feature(rustc_attrs)]

#[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "1234")]
pub fn foo() {}

0 comments on commit 6460460

Please sign in to comment.