From d2fe6c452790b8d9e986777694390f2f378c58cb Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 19 Jun 2018 20:10:56 +0200 Subject: [PATCH] Update the error message for a missing global allocator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don’t mention `#[default_lib_allocator]` (which is an implementation detail irrelevant to most users) and instead suggest using `#[global_allocator]`, which is often the correct fix. --- src/librustc_metadata/creader.rs | 6 ++++-- src/test/ui/missing-allocator.stderr | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index e41b3f5f53b2..6c1991457433 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -986,8 +986,10 @@ impl<'a> CrateLoader<'a> { }, None => { if !attr::contains_name(&krate.attrs, "default_lib_allocator") { - self.sess.err("no #[default_lib_allocator] found but one is \ - required; is libstd not linked?"); + self.sess.err("no global memory allocator found but one is \ + required; link to std or \ + add #[global_allocator] to a static item \ + that implements the GlobalAlloc trait."); return; } self.sess.allocator_kind.set(Some(AllocatorKind::DefaultLib)); diff --git a/src/test/ui/missing-allocator.stderr b/src/test/ui/missing-allocator.stderr index 6fd21d850e96..11e0085d1ce2 100644 --- a/src/test/ui/missing-allocator.stderr +++ b/src/test/ui/missing-allocator.stderr @@ -1,4 +1,4 @@ -error: no #[default_lib_allocator] found but one is required; is libstd not linked? +error: no global memory allocator found but one is required; link to std or add #[global_allocator] to a static item that implements the GlobalAlloc trait. error: aborting due to previous error