Support #[derive_const(Trait)]

This commit is contained in:
hkalbasi 2023-06-29 20:58:35 +03:30
parent 70a01fead5
commit f53f9230f0
5 changed files with 66 additions and 19 deletions

View file

@ -278,6 +278,44 @@ impl < > core::cmp::Eq for Command< > where {}"#]],
);
}
#[test]
fn test_partial_eq_expand_with_derive_const() {
// FIXME: actually expand with const
check(
r#"
//- minicore: derive, eq
#[derive_const(PartialEq, Eq)]
enum Command {
Move { x: i32, y: i32 },
Do(&'static str),
Jump,
}
"#,
expect![[r#"
#[derive_const(PartialEq, Eq)]
enum Command {
Move { x: i32, y: i32 },
Do(&'static str),
Jump,
}
impl < > core::cmp::PartialEq for Command< > where {
fn eq(&self , other: &Self ) -> bool {
match (self , other) {
(Command::Move {
x: x_self, y: y_self,
}
, Command::Move {
x: x_other, y: y_other,
}
)=>x_self.eq(x_other) && y_self.eq(y_other), (Command::Do(f0_self, ), Command::Do(f0_other, ))=>f0_self.eq(f0_other), (Command::Jump, Command::Jump)=>true , _unused=>false
}
}
}
impl < > core::cmp::Eq for Command< > where {}"#]],
);
}
#[test]
fn test_partial_ord_expand() {
check(

View file

@ -35,7 +35,7 @@ macro_rules! register_builtin {
impl BuiltinAttrExpander {
pub fn is_derive(self) -> bool {
matches!(self, BuiltinAttrExpander::Derive)
matches!(self, BuiltinAttrExpander::Derive | BuiltinAttrExpander::DeriveConst)
}
pub fn is_test(self) -> bool {
matches!(self, BuiltinAttrExpander::Test)
@ -50,6 +50,8 @@ register_builtin! {
(cfg_accessible, CfgAccessible) => dummy_attr_expand,
(cfg_eval, CfgEval) => dummy_attr_expand,
(derive, Derive) => derive_attr_expand,
// derive const is equivalent to derive for our proposes.
(derive_const, DeriveConst) => derive_attr_expand,
(global_allocator, GlobalAllocator) => dummy_attr_expand,
(test, Test) => dummy_attr_expand,
(test_case, TestCase) => dummy_attr_expand

View file

@ -365,6 +365,7 @@ pub mod known {
cfg_eval,
crate_type,
derive,
derive_const,
global_allocator,
no_core,
no_std,

View file

@ -300,6 +300,7 @@ struct Foo;
at deprecated
at derive macro derive
at derive()
at derive_const macro derive_const
at doc = ""
at doc(alias = "")
at doc(hidden)

View file

@ -1311,6 +1311,11 @@ mod macros {
pub macro derive($item:item) {
/* compiler built-in */
}
#[rustc_builtin_macro]
pub macro derive_const($item:item) {
/* compiler built-in */
}
}
// endregion:derive
@ -1385,7 +1390,7 @@ pub mod prelude {
convert::{From, Into}, // :from
default::Default, // :default
iter::{IntoIterator, Iterator}, // :iterator
macros::builtin::derive, // :derive
macros::builtin::{derive, derive_const}, // :derive
marker::Copy, // :copy
marker::Send, // :send
marker::Sized, // :sized