Rollup merge of #154442 - nik-contrib:derive-root, r=jhpratt

Export `derive` at the crate root: `core::derive` and `std::derive`

This PR makes the `derive` macro available at the crate root:

```rust
#[std::derive(Clone)]
#[core::derive(Copy)]
struct X;
```

ACP: https://github.com/rust-lang/libs-team/issues/766

Tracking issue: https://github.com/rust-lang/rust/issues/154645
This commit is contained in:
Jonathan Brouwer
2026-04-02 22:13:54 +02:00
committed by GitHub
6 changed files with 25 additions and 3 deletions
+2
View File
@@ -236,6 +236,8 @@ pub mod autodiff {
#[unstable(feature = "contracts", issue = "128044")]
pub mod contracts;
#[unstable(feature = "derive_macro_global_path", issue = "154645")]
pub use crate::macros::builtin::derive;
#[stable(feature = "cfg_select", since = "1.95.0")]
pub use crate::macros::cfg_select;
+1 -1
View File
@@ -1720,7 +1720,7 @@ macro_rules! trace_macros {
///
/// See [the reference] for more info.
///
/// [the reference]: ../../../reference/attributes/derive.html
/// [the reference]: ../reference/attributes/derive.html
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
pub macro derive($item:item) {
+5 -1
View File
@@ -120,9 +120,13 @@ mod panic {}
// (no public module for them to be re-exported from).
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
pub use crate::macros::builtin::{
alloc_error_handler, bench, derive, global_allocator, test, test_case,
alloc_error_handler, bench, global_allocator, test, test_case,
};
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[doc(no_inline)]
pub use crate::macros::builtin::derive;
#[unstable(feature = "derive_const", issue = "118304")]
pub use crate::macros::builtin::derive_const;
+2
View File
@@ -706,6 +706,8 @@ pub mod arch {
reason = "`concat_bytes` is not stable enough for use and is subject to change"
)]
pub use core::concat_bytes;
#[unstable(feature = "derive_macro_global_path", issue = "154645")]
pub use core::derive;
#[stable(feature = "matches_macro", since = "1.42.0")]
#[allow(deprecated, deprecated_in_future)]
pub use core::matches;
+5 -1
View File
@@ -115,9 +115,13 @@ mod panic {}
// (no public module for them to be re-exported from).
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
pub use core::prelude::v1::{
alloc_error_handler, bench, derive, global_allocator, test, test_case,
alloc_error_handler, bench, global_allocator, test, test_case,
};
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[doc(no_inline)]
pub use core::prelude::v1::derive;
#[unstable(feature = "derive_const", issue = "118304")]
pub use core::prelude::v1::derive_const;
+10
View File
@@ -0,0 +1,10 @@
//@ edition: 2024
//@ check-pass
#![crate_type = "lib"]
#![feature(derive_macro_global_path)]
#[::core::derive(Clone)]
struct Y;
#[::std::derive(Clone)]
struct X;