Support #[derive_const(Trait)]
This commit is contained in:
parent
70a01fead5
commit
f53f9230f0
@ -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]
|
#[test]
|
||||||
fn test_partial_ord_expand() {
|
fn test_partial_ord_expand() {
|
||||||
check(
|
check(
|
||||||
|
@ -35,7 +35,7 @@ macro_rules! register_builtin {
|
|||||||
|
|
||||||
impl BuiltinAttrExpander {
|
impl BuiltinAttrExpander {
|
||||||
pub fn is_derive(self) -> bool {
|
pub fn is_derive(self) -> bool {
|
||||||
matches!(self, BuiltinAttrExpander::Derive)
|
matches!(self, BuiltinAttrExpander::Derive | BuiltinAttrExpander::DeriveConst)
|
||||||
}
|
}
|
||||||
pub fn is_test(self) -> bool {
|
pub fn is_test(self) -> bool {
|
||||||
matches!(self, BuiltinAttrExpander::Test)
|
matches!(self, BuiltinAttrExpander::Test)
|
||||||
@ -50,6 +50,8 @@ register_builtin! {
|
|||||||
(cfg_accessible, CfgAccessible) => dummy_attr_expand,
|
(cfg_accessible, CfgAccessible) => dummy_attr_expand,
|
||||||
(cfg_eval, CfgEval) => dummy_attr_expand,
|
(cfg_eval, CfgEval) => dummy_attr_expand,
|
||||||
(derive, Derive) => derive_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,
|
(global_allocator, GlobalAllocator) => dummy_attr_expand,
|
||||||
(test, Test) => dummy_attr_expand,
|
(test, Test) => dummy_attr_expand,
|
||||||
(test_case, TestCase) => dummy_attr_expand
|
(test_case, TestCase) => dummy_attr_expand
|
||||||
|
@ -365,6 +365,7 @@ pub mod known {
|
|||||||
cfg_eval,
|
cfg_eval,
|
||||||
crate_type,
|
crate_type,
|
||||||
derive,
|
derive,
|
||||||
|
derive_const,
|
||||||
global_allocator,
|
global_allocator,
|
||||||
no_core,
|
no_core,
|
||||||
no_std,
|
no_std,
|
||||||
|
@ -300,6 +300,7 @@ struct Foo;
|
|||||||
at deprecated
|
at deprecated
|
||||||
at derive macro derive
|
at derive macro derive
|
||||||
at derive(…)
|
at derive(…)
|
||||||
|
at derive_const macro derive_const
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
@ -1311,6 +1311,11 @@ mod macros {
|
|||||||
pub macro derive($item:item) {
|
pub macro derive($item:item) {
|
||||||
/* compiler built-in */
|
/* compiler built-in */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
pub macro derive_const($item:item) {
|
||||||
|
/* compiler built-in */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// endregion:derive
|
// endregion:derive
|
||||||
|
|
||||||
@ -1385,7 +1390,7 @@ pub mod prelude {
|
|||||||
convert::{From, Into}, // :from
|
convert::{From, Into}, // :from
|
||||||
default::Default, // :default
|
default::Default, // :default
|
||||||
iter::{IntoIterator, Iterator}, // :iterator
|
iter::{IntoIterator, Iterator}, // :iterator
|
||||||
macros::builtin::derive, // :derive
|
macros::builtin::{derive, derive_const}, // :derive
|
||||||
marker::Copy, // :copy
|
marker::Copy, // :copy
|
||||||
marker::Send, // :send
|
marker::Send, // :send
|
||||||
marker::Sized, // :sized
|
marker::Sized, // :sized
|
||||||
|
Loading…
x
Reference in New Issue
Block a user