Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b9c3d09

Browse files
committed
Auto merge of rust-lang#15172 - HKalbasi:mir, r=HKalbasi
Support #[derive_const(Trait)] This is a nightly feature used in the standard library.
2 parents 70a01fe + f53f923 commit b9c3d09

File tree

5 files changed

+66
-19
lines changed

5 files changed

+66
-19
lines changed

crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,44 @@ impl < > core::cmp::Eq for Command< > where {}"#]],
278278
);
279279
}
280280

281+
#[test]
282+
fn test_partial_eq_expand_with_derive_const() {
283+
// FIXME: actually expand with const
284+
check(
285+
r#"
286+
//- minicore: derive, eq
287+
#[derive_const(PartialEq, Eq)]
288+
enum Command {
289+
Move { x: i32, y: i32 },
290+
Do(&'static str),
291+
Jump,
292+
}
293+
"#,
294+
expect![[r#"
295+
#[derive_const(PartialEq, Eq)]
296+
enum Command {
297+
Move { x: i32, y: i32 },
298+
Do(&'static str),
299+
Jump,
300+
}
301+
302+
impl < > core::cmp::PartialEq for Command< > where {
303+
fn eq(&self , other: &Self ) -> bool {
304+
match (self , other) {
305+
(Command::Move {
306+
x: x_self, y: y_self,
307+
}
308+
, Command::Move {
309+
x: x_other, y: y_other,
310+
}
311+
)=>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
312+
}
313+
}
314+
}
315+
impl < > core::cmp::Eq for Command< > where {}"#]],
316+
);
317+
}
318+
281319
#[test]
282320
fn test_partial_ord_expand() {
283321
check(

crates/hir-expand/src/builtin_attr_macro.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro_rules! register_builtin {
3535

3636
impl BuiltinAttrExpander {
3737
pub fn is_derive(self) -> bool {
38-
matches!(self, BuiltinAttrExpander::Derive)
38+
matches!(self, BuiltinAttrExpander::Derive | BuiltinAttrExpander::DeriveConst)
3939
}
4040
pub fn is_test(self) -> bool {
4141
matches!(self, BuiltinAttrExpander::Test)
@@ -50,6 +50,8 @@ register_builtin! {
5050
(cfg_accessible, CfgAccessible) => dummy_attr_expand,
5151
(cfg_eval, CfgEval) => dummy_attr_expand,
5252
(derive, Derive) => derive_attr_expand,
53+
// derive const is equivalent to derive for our proposes.
54+
(derive_const, DeriveConst) => derive_attr_expand,
5355
(global_allocator, GlobalAllocator) => dummy_attr_expand,
5456
(test, Test) => dummy_attr_expand,
5557
(test_case, TestCase) => dummy_attr_expand

crates/hir-expand/src/name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ pub mod known {
365365
cfg_eval,
366366
crate_type,
367367
derive,
368+
derive_const,
368369
global_allocator,
369370
no_core,
370371
no_std,

crates/ide-completion/src/tests/attribute.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ struct Foo;
300300
at deprecated
301301
at derive macro derive
302302
at derive(…)
303+
at derive_const macro derive_const
303304
at doc = "…"
304305
at doc(alias = "…")
305306
at doc(hidden)

crates/test-utils/src/minicore.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,11 @@ mod macros {
13111311
pub macro derive($item:item) {
13121312
/* compiler built-in */
13131313
}
1314+
1315+
#[rustc_builtin_macro]
1316+
pub macro derive_const($item:item) {
1317+
/* compiler built-in */
1318+
}
13141319
}
13151320
// endregion:derive
13161321

@@ -1378,24 +1383,24 @@ pub mod error {
13781383
pub mod prelude {
13791384
pub mod v1 {
13801385
pub use crate::{
1381-
clone::Clone, // :clone
1382-
cmp::{Eq, PartialEq}, // :eq
1383-
cmp::{Ord, PartialOrd}, // :ord
1384-
convert::AsRef, // :as_ref
1385-
convert::{From, Into}, // :from
1386-
default::Default, // :default
1387-
iter::{IntoIterator, Iterator}, // :iterator
1388-
macros::builtin::derive, // :derive
1389-
marker::Copy, // :copy
1390-
marker::Send, // :send
1391-
marker::Sized, // :sized
1392-
marker::Sync, // :sync
1393-
mem::drop, // :drop
1394-
ops::Drop, // :drop
1395-
ops::{Fn, FnMut, FnOnce}, // :fn
1396-
option::Option::{self, None, Some}, // :option
1397-
panic, // :panic
1398-
result::Result::{self, Err, Ok}, // :result
1386+
clone::Clone, // :clone
1387+
cmp::{Eq, PartialEq}, // :eq
1388+
cmp::{Ord, PartialOrd}, // :ord
1389+
convert::AsRef, // :as_ref
1390+
convert::{From, Into}, // :from
1391+
default::Default, // :default
1392+
iter::{IntoIterator, Iterator}, // :iterator
1393+
macros::builtin::{derive, derive_const}, // :derive
1394+
marker::Copy, // :copy
1395+
marker::Send, // :send
1396+
marker::Sized, // :sized
1397+
marker::Sync, // :sync
1398+
mem::drop, // :drop
1399+
ops::Drop, // :drop
1400+
ops::{Fn, FnMut, FnOnce}, // :fn
1401+
option::Option::{self, None, Some}, // :option
1402+
panic, // :panic
1403+
result::Result::{self, Err, Ok}, // :result
13991404
};
14001405
}
14011406

0 commit comments

Comments
 (0)