"Module `once` is private" from inside libstd

While trying to do something about bug #39798 I added a use of sync::once to libstd/net/test.rs, after which, running x.py test src/libstd --stage 0 produces very strange errors:

error[E0603]: module `once` is private
  --> src/libstd/net/test.rs:16:18
   |
16 | use sync::once::{Once, ONCE_INIT};
   |                  ^^^^

error[E0603]: module `once` is private
  --> src/libstd/net/test.rs:16:24
   |
16 | use sync::once::{Once, ONCE_INIT};
   |                        ^^^^^^^^^

error: the #[global_allocator] in this crate conflicts with global allocator in: std

error: aborting due to 3 previous errors

error: Could not compile `std`.

I don’t see why it thinks std::sync::once is private - inside std, even - and I also don’t see how std's choice of global allocator can possibly conflict with itself. Anyone have a clue?

EDIT: If I use --stage 1 instead, the complaint about the global allocator goes away, but the other errors don’t.

In libstd/sync/mod.rs:

// ...

pub mod mpsc;

mod barrier;
mod condvar;
mod mutex;
mod once;
mod rwlock;

It says mod once;, not pub(crate) mod once;, so what’s so unusual about this? std::sync publically reexports those things as a façade, so you ought to just be able to write use sync::{Once, ONCE_INIT};.


Also, from what I remember being told on IRC, you cannot run tests on stage0. You need at least stage1 for most things, and stage2 for compiler plugins.

1 Like

Well, this is embarrassing: I misread the documentation as saying you were supposed to use std::sync::once::Once and I didn’t actually look at sync/mod.rs. With use std::sync::Once it works fine. Never mind.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.