about summary refs log tree commit diff
path: root/src/test/ui/allocator
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-25 23:21:00 +0200
committerGitHub <noreply@github.com>2019-07-25 23:21:00 +0200
commite1de70b04548b2e899fcf0da09c29600cc05325e (patch)
treea74148f96104c5972f121069a0cfcab089d8082e /src/test/ui/allocator
parent6f0e57fb1dc3b30126e6ec6c9dd2ad0309da2c0c (diff)
parenta0c2c640d54fa1622c2fea4accae1025bf109c47 (diff)
downloadrust-e1de70b04548b2e899fcf0da09c29600cc05325e.tar.gz
rust-e1de70b04548b2e899fcf0da09c29600cc05325e.zip
Rollup merge of #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 https://github.com/rust-lang/rust/issues/44113
Fixes https://github.com/rust-lang/rust/issues/58072
Diffstat (limited to 'src/test/ui/allocator')
-rw-r--r--src/test/ui/allocator/allocator-args.rs13
-rw-r--r--src/test/ui/allocator/allocator-args.stderr8
-rw-r--r--src/test/ui/allocator/two-allocators.rs2
-rw-r--r--src/test/ui/allocator/two-allocators.stderr8
4 files changed, 29 insertions, 2 deletions
diff --git a/src/test/ui/allocator/allocator-args.rs b/src/test/ui/allocator/allocator-args.rs
new file mode 100644
index 00000000000..1033f947c5f
--- /dev/null
+++ b/src/test/ui/allocator/allocator-args.rs
@@ -0,0 +1,13 @@
+use std::alloc::{GlobalAlloc, Layout};
+
+struct A;
+
+unsafe impl GlobalAlloc for A {
+    unsafe fn alloc(&self, _: Layout) -> *mut u8 { panic!() }
+    unsafe fn dealloc(&self, _: *mut u8, _: Layout) { panic!() }
+}
+
+#[global_allocator(malloc)] //~ ERROR malformed `global_allocator` attribute input
+static S: A = A;
+
+fn main() {}
diff --git a/src/test/ui/allocator/allocator-args.stderr b/src/test/ui/allocator/allocator-args.stderr
new file mode 100644
index 00000000000..dfff2a7e709
--- /dev/null
+++ b/src/test/ui/allocator/allocator-args.stderr
@@ -0,0 +1,8 @@
+error: malformed `global_allocator` attribute input
+  --> $DIR/allocator-args.rs:10:1
+   |
+LL | #[global_allocator(malloc)]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[global_allocator]`
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/allocator/two-allocators.rs b/src/test/ui/allocator/two-allocators.rs
index 0f81fc41823..aa1291e77ae 100644
--- a/src/test/ui/allocator/two-allocators.rs
+++ b/src/test/ui/allocator/two-allocators.rs
@@ -4,6 +4,6 @@ use std::alloc::System;
 static A: System = System;
 #[global_allocator]
 static B: System = System;
-//~^ ERROR: cannot define more than one `#[global_allocator]`
+//~^ ERROR: cannot define multiple global allocators
 
 fn main() {}
diff --git a/src/test/ui/allocator/two-allocators.stderr b/src/test/ui/allocator/two-allocators.stderr
index 6b0c2b2a25d..ed0aa13eb80 100644
--- a/src/test/ui/allocator/two-allocators.stderr
+++ b/src/test/ui/allocator/two-allocators.stderr
@@ -1,8 +1,14 @@
-error: cannot define more than one `#[global_allocator]`
+error: cannot define multiple global allocators
   --> $DIR/two-allocators.rs:6:1
    |
 LL | static B: System = System;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: the previous global allocator is defined here
+  --> $DIR/two-allocators.rs:4:1
+   |
+LL | static A: System = System;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to previous error