diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index e41b3f5f53b25..6c1991457433f 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.rs b/src/test/ui/missing-allocator.rs new file mode 100644 index 0000000000000..24282631b7eea --- /dev/null +++ b/src/test/ui/missing-allocator.rs @@ -0,0 +1,26 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -C panic=abort +// no-prefer-dynamic + +#![no_std] +#![crate_type = "staticlib"] +#![feature(panic_implementation, lang_items, alloc)] + +#[panic_implementation] +fn panic(_: &core::panic::PanicInfo) -> ! { + loop {} +} + +#[lang = "oom"] +fn oom() {} + +extern crate alloc; diff --git a/src/test/ui/missing-allocator.stderr b/src/test/ui/missing-allocator.stderr new file mode 100644 index 0000000000000..11e0085d1ce2e --- /dev/null +++ b/src/test/ui/missing-allocator.stderr @@ -0,0 +1,4 @@ +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 +