Skip to content

Commit e09c812

Browse files
authored
Rollup merge of rust-lang#62735 - petrochenkov:galloc, r=alexcrichton
Turn `#[global_allocator]` into a regular attribute macro It was a 99% macro with exception of some diagnostic details. As a result of the change, `#[global_allocator]` now works in nested modules and even in nameless blocks. Fixes rust-lang#44113 Fixes rust-lang#58072
2 parents d3730a9 + a0c2c64 commit e09c812

40 files changed

+513
-593
lines changed

Cargo.lock

-18
Original file line numberDiff line numberDiff line change
@@ -2751,20 +2751,6 @@ dependencies = [
27512751
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
27522752
]
27532753

2754-
[[package]]
2755-
name = "rustc_allocator"
2756-
version = "0.0.0"
2757-
dependencies = [
2758-
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
2759-
"rustc 0.0.0",
2760-
"rustc_data_structures 0.0.0",
2761-
"rustc_errors 0.0.0",
2762-
"rustc_target 0.0.0",
2763-
"smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
2764-
"syntax 0.0.0",
2765-
"syntax_pos 0.0.0",
2766-
]
2767-
27682754
[[package]]
27692755
name = "rustc_apfloat"
27702756
version = "0.0.0"
@@ -2822,7 +2808,6 @@ dependencies = [
28222808
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
28232809
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
28242810
"rustc 0.0.0",
2825-
"rustc_allocator 0.0.0",
28262811
"rustc_apfloat 0.0.0",
28272812
"rustc_codegen_utils 0.0.0",
28282813
"rustc_data_structures 0.0.0",
@@ -2883,7 +2868,6 @@ dependencies = [
28832868
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
28842869
"rustc 0.0.0",
28852870
"rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
2886-
"rustc_allocator 0.0.0",
28872871
"rustc_ast_borrowck 0.0.0",
28882872
"rustc_codegen_utils 0.0.0",
28892873
"rustc_data_structures 0.0.0",
@@ -2904,7 +2888,6 @@ dependencies = [
29042888
"serialize 0.0.0",
29052889
"smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
29062890
"syntax 0.0.0",
2907-
"syntax_ext 0.0.0",
29082891
"syntax_pos 0.0.0",
29092892
]
29102893

@@ -2948,7 +2931,6 @@ dependencies = [
29482931
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
29492932
"rustc 0.0.0",
29502933
"rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
2951-
"rustc_allocator 0.0.0",
29522934
"rustc_ast_borrowck 0.0.0",
29532935
"rustc_codegen_ssa 0.0.0",
29542936
"rustc_codegen_utils 0.0.0",

src/libcore/macros.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,13 @@ mod builtin {
12811281
#[rustc_macro_transparency = "semitransparent"]
12821282
pub macro test_case($item:item) { /* compiler built-in */ }
12831283

1284+
/// Attribute macro applied to a static to register it as a global allocator.
1285+
#[stable(feature = "global_allocator", since = "1.28.0")]
1286+
#[allow_internal_unstable(rustc_attrs)]
1287+
#[rustc_builtin_macro]
1288+
#[rustc_macro_transparency = "semitransparent"]
1289+
pub macro global_allocator($item:item) { /* compiler built-in */ }
1290+
12841291
/// Derive macro generating an impl of the trait `Clone`.
12851292
#[rustc_builtin_macro]
12861293
#[rustc_macro_transparency = "semitransparent"]

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ pub mod infer;
112112
pub mod lint;
113113

114114
pub mod middle {
115-
pub mod allocator;
116115
pub mod borrowck;
117116
pub mod expr_use_visitor;
118117
pub mod cstore;

src/librustc/middle/allocator.rs

-16
This file was deleted.

src/librustc/middle/dead.rs

-5
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,6 @@ fn has_allow_dead_code_or_lang_attr(
320320
return true;
321321
}
322322

323-
// Don't lint about global allocators
324-
if attr::contains_name(attrs, sym::global_allocator) {
325-
return true;
326-
}
327-
328323
let def_id = tcx.hir().local_def_id(id);
329324
let cg_attrs = tcx.codegen_fn_attrs(def_id);
330325

src/librustc/session/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_data_structures::fingerprint::Fingerprint;
77

88
use crate::lint;
99
use crate::lint::builtin::BuiltinLintDiagnostics;
10-
use crate::middle::allocator::AllocatorKind;
1110
use crate::middle::dependency_format;
1211
use crate::session::config::{OutputType, PrintRequest, SwitchWithOptPath};
1312
use crate::session::search_paths::{PathKind, SearchPath};
@@ -27,6 +26,7 @@ use errors::emitter::HumanReadableErrorType;
2726
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
2827
use syntax::ast::{self, NodeId};
2928
use syntax::edition::Edition;
29+
use syntax::ext::allocator::AllocatorKind;
3030
use syntax::feature_gate::{self, AttributeType};
3131
use syntax::json::JsonEmitter;
3232
use syntax::source_map;

src/librustc_allocator/Cargo.toml

-19
This file was deleted.

0 commit comments

Comments
 (0)