Skip to content

Commit d2fe6c4

Browse files
committed
Update the error message for a missing global allocator
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.
1 parent a9a0f4c commit d2fe6c4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/librustc_metadata/creader.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,10 @@ impl<'a> CrateLoader<'a> {
986986
},
987987
None => {
988988
if !attr::contains_name(&krate.attrs, "default_lib_allocator") {
989-
self.sess.err("no #[default_lib_allocator] found but one is \
990-
required; is libstd not linked?");
989+
self.sess.err("no global memory allocator found but one is \
990+
required; link to std or \
991+
add #[global_allocator] to a static item \
992+
that implements the GlobalAlloc trait.");
991993
return;
992994
}
993995
self.sess.allocator_kind.set(Some(AllocatorKind::DefaultLib));

src/test/ui/missing-allocator.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no #[default_lib_allocator] found but one is required; is libstd not linked?
1+
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.
22

33
error: aborting due to previous error
44

0 commit comments

Comments
 (0)