Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bdd480a

Browse files
committedApr 23, 2023
Reintroduce alloc_error_handler as deprecated
1 parent 3462f79 commit bdd480a

File tree

12 files changed

+101
-4
lines changed

12 files changed

+101
-4
lines changed
 
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use rustc_expand::base::{Annotatable, ExtCtxt};
2+
use rustc_span::Span;
3+
4+
pub fn expand(
5+
_ecx: &mut ExtCtxt<'_>,
6+
_span: Span,
7+
_meta_item: &rustc_ast::MetaItem,
8+
item: Annotatable,
9+
) -> Vec<Annotatable> {
10+
11+
vec![item.clone()]
12+
}
13+

‎compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use rustc_expand::proc_macro::BangProcMacro;
2727
use rustc_fluent_macro::fluent_messages;
2828
use rustc_span::symbol::sym;
2929

30+
mod alloc_error_handler;
3031
mod assert;
3132
mod cfg;
3233
mod cfg_accessible;
@@ -103,6 +104,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
103104
}
104105

105106
register_attr! {
107+
alloc_error_handler: alloc_error_handler::expand,
106108
bench: test::expand_bench,
107109
cfg_accessible: cfg_accessible::Expander,
108110
cfg_eval: cfg_eval::expand,

‎compiler/rustc_feature/src/active.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ declare_features! (
291291
(active, abi_x86_interrupt, "1.17.0", Some(40180), None),
292292
/// Allows additional const parameter types, such as `&'static str` or user defined types
293293
(incomplete, adt_const_params, "1.56.0", Some(95174), None),
294+
/// Deprecated feature; exists for smooth transitions
295+
(active, alloc_error_handler, "1.29.0", Some(51540), None),
294296
/// Allows trait methods with arbitrary self types.
295297
(active, arbitrary_self_types, "1.23.0", Some(44874), None),
296298
/// Allows using `const` operands in inline assembly.

‎compiler/rustc_feature/src/removed.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ declare_features! (
4747

4848
(removed, advanced_slice_patterns, "1.0.0", Some(62254), None,
4949
Some("merged into `#![feature(slice_patterns)]`")),
50-
/// Allows defining an `#[alloc_error_handler]`.
51-
(removed, alloc_error_handler, "CURRENT_RUSTC_VERSION", Some(51540), None, Some("now handled by panic handler")),
5250
(removed, allocator, "1.0.0", None, None, None),
5351
/// Allows a test to fail without failing the whole suite.
5452
(removed, allow_fail, "1.19.0", Some(46488), None, Some("removed due to no clear use cases")),

‎library/core/src/macros/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,15 @@ pub(crate) mod builtin {
15311531
/* compiler built-in */
15321532
}
15331533

1534+
/// Deprecated attribute for functionality now handled by panic_handler
1535+
#[unstable(feature = "alloc_error_handler", issue = "51540")]
1536+
#[deprecated(since = "1.71", note = "Please use #[panic_handler] instead")]
1537+
#[allow_internal_unstable(rustc_attrs)]
1538+
#[rustc_builtin_macro]
1539+
pub macro alloc_error_handler($item:item) {
1540+
/* compiler built-in */
1541+
}
1542+
15341543
/// Keeps the item it's applied to if the passed path is accessible, and removes it otherwise.
15351544
#[unstable(
15361545
feature = "cfg_accessible",

‎library/core/src/prelude/v1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ pub use crate::macros::builtin::{RustcDecodable, RustcEncodable};
7676
// Do not `doc(no_inline)` so that they become doc items on their own
7777
// (no public module for them to be re-exported from).
7878
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
79-
pub use crate::macros::builtin::{bench, derive, global_allocator, test, test_case};
79+
#[allow(deprecated)]
80+
pub use crate::macros::builtin::{alloc_error_handler, bench, derive, global_allocator, test, test_case};
8081

8182
#[unstable(feature = "derive_const", issue = "none")]
8283
pub use crate::macros::builtin::derive_const;

‎library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
//
237237
// Language features:
238238
// tidy-alphabetical-start
239+
#![feature(alloc_error_handler)]
239240
#![feature(allocator_internals)]
240241
#![feature(allow_internal_unsafe)]
241242
#![feature(allow_internal_unstable)]

‎library/std/src/prelude/v1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ pub use core::prelude::v1::{RustcDecodable, RustcEncodable};
6060
// Do not `doc(no_inline)` so that they become doc items on their own
6161
// (no public module for them to be re-exported from).
6262
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
63-
pub use core::prelude::v1::{bench, derive, global_allocator, test, test_case};
63+
#[allow(deprecated)]
64+
pub use core::prelude::v1::{alloc_error_handler, bench, derive, global_allocator, test, test_case};
6465

6566
#[unstable(feature = "derive_const", issue = "none")]
6667
pub use core::prelude::v1::derive_const;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(alloc_error_handler)]
2+
#![deny(deprecated)]
3+
4+
5+
extern crate alloc;
6+
use alloc::layout::Layout;
7+
8+
#[alloc_error_handler]
9+
fn alloc_error(_l: Layout) -> ! {
10+
loop {}
11+
}
12+
13+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0432]: unresolved import `alloc::layout`
2+
--> $DIR/alloc-error-handler-deprecated.rs:6:12
3+
|
4+
LL | use alloc::layout::Layout;
5+
| ^^^^^^ could not find `layout` in `alloc`
6+
7+
error: use of deprecated macro `alloc_error_handler`: Please use #[panic_handler] instead
8+
--> $DIR/alloc-error-handler-deprecated.rs:8:3
9+
|
10+
LL | #[alloc_error_handler]
11+
| ^^^^^^^^^^^^^^^^^^^
12+
|
13+
note: the lint level is defined here
14+
--> $DIR/alloc-error-handler-deprecated.rs:2:9
15+
|
16+
LL | #![deny(deprecated)]
17+
| ^^^^^^^^^^
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0432`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-flags:-C panic=abort
2+
3+
#![no_std]
4+
#![no_main]
5+
6+
use core::alloc::Layout;
7+
8+
#[alloc_error_handler] //~ ERROR use of unstable library feature 'alloc_error_handler'
9+
fn oom(info: Layout) -> ! {
10+
loop {}
11+
}
12+
13+
#[panic_handler]
14+
fn panic(_: &core::panic::PanicInfo) -> ! {
15+
loop {}
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0658]: use of unstable library feature 'alloc_error_handler'
2+
--> $DIR/feature-gate-alloc-error-handler.rs:8:3
3+
|
4+
LL | #[alloc_error_handler]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #51540 <https://github.com/rust-lang/rust/issues/51540> for more information
8+
= help: add `#![feature(alloc_error_handler)]` to the crate attributes to enable
9+
10+
warning: use of deprecated macro `alloc_error_handler`: Please use #[panic_handler] instead
11+
--> $DIR/feature-gate-alloc-error-handler.rs:8:3
12+
|
13+
LL | #[alloc_error_handler]
14+
| ^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: `#[warn(deprecated)]` on by default
17+
18+
error: aborting due to previous error; 1 warning emitted
19+
20+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)
Please sign in to comment.