You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No global memory allocator error when testing no_std crate that does link to std #54010
error: no global memory allocator found but one is required; link to std or add #[global_allocator] t
o a static item that implements the GlobalAlloc trait.
Allocating on the heap during testing does appear to work, so I'm assuming this is just a case of the warning still being emitted.
Reacted by Rodolphe Marques, Elichai Turkel, Zihan Liu, Maximilian Roos, Lukas Kalbertodt, Martin Habovštiak, Cedric Hutchings, Ellen Emilia Anna Zscheile, Davids Paskevics, Spike O'Carroll and 1 more
cargo test builds the crate both as a library (for doctests) and as a test executable. You only pull in std for the test executable, so the error message could be coming from building as a library.
Yeah, the error message is emitted when building the doctest library. Funnily enough, it does not cause the build to fail. That is, cargo test still continues running and then exits with success (0).
Sadly, there is currently no way to link in a default allocator (or std for that matter) for doctests. There is the unstable doc_cfg feature that provides cfg(rustdoc), but I don't see how to achieve something similar without relying on unstable features.
Sadly, there is currently no way to link in a default allocator (or std for that matter) for doctests.
If you don't put #[no_std] inside the doctest it will be linked against std even when testing a #[no_std] crate, you can think of each doctest as a separate crate. If you do want a different allocator you can add a #[global_allocator] static like in a normal binary. Even though this error message is printed the doc tests should still be running.
Activity
zesterer commentedon Oct 9, 2018
I have the same issue. Any update?
sfackler commentedon Oct 9, 2018
cargo testbuilds the crate both as a library (for doctests) and as a test executable. You only pull in std for the test executable, so the error message could be coming from building as a library.cbeck88 commentedon Jan 15, 2019
I have the same issue, error message seems to be spurious
dvdhrm commentedon Apr 16, 2019
Yeah, the error message is emitted when building the
doctestlibrary. Funnily enough, it does not cause the build to fail. That is,cargo teststill continues running and then exits with success (0).Sadly, there is currently no way to link in a default allocator (or
stdfor that matter) for doctests. There is the unstabledoc_cfgfeature that providescfg(rustdoc), but I don't see how to achieve something similar without relying on unstable features.I simply use
doctest = falseuntil this is fixed.RalfJung commentedon Apr 18, 2019
Related: #52243
Auto merge of #96 - jethrogb:patch-1, r=Amanieu
jethrogb commentedon Jul 3, 2019
@rustbot modify labels: +T-rustdoc
rustbot commentedon Jul 3, 2019
Error: Parsing label command in comment failed: ...ify labels|error: must have : or to as label starter at >| +T-rustdo...
Please let
@rust-lang/releaseknow if you're having trouble with this bot.Bump min rust version to 1.36.0; simplify features
Bump min rust version to 1.36.0; simplify features
Bump min rust version to 1.36.0; simplify features
Disable doctest to get rid of allocator message
Nemo157 commentedon Aug 11, 2019
If you don't put
#[no_std]inside the doctest it will be linked againststdeven when testing a#[no_std]crate, you can think of each doctest as a separate crate. If you do want a different allocator you can add a#[global_allocator]static like in a normal binary. Even though this error message is printed the doc tests should still be running.RalfJung commentedon Aug 11, 2019
Also see #52243 (comment): the error is basically spurious.
Make crate `no_std` compatible
Disable doctest to get rid of allocator message
Rollup merge of rust-lang#68357 - ollie27:rustdoc_test_errors, r=Guil…
Make crate depend on core and alloc only
Make crate depend on core and alloc only
dev-support: add some tests for Fifo