# \[Pre-RFC\] Crate-wide imports?

**URL:** https://internals.rust-lang.org/t/pre-rfc-crate-wide-imports/8934
**Category:** language design
**Created:** [November 30, 2018, 1:46pm UTC](https://internals.rust-lang.org/t/pre-rfc-crate-wide-imports/8934 "2018-11-30T13:46:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![alexheretic](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/alexheretic/32/4800_2.png) [@alexheretic](https://internals.rust-lang.org/u/alexheretic)
#### Post date: [November 30, 2018, 1:46pm UTC](https://internals.rust-lang.org/t/pre-rfc-crate-wide-imports/8934/1 "2018-11-30T13:46:32Z")

</div>

I feel that we could treat most complaints with the built-in prelude by allowing crate-wide imports. You’d declare these in your main.rs/lib.rs only and they’d be equivalent to being in the built-in prelude.

```rust
// main.rs
use(crate) std::collections::{HashMap, HashSet};

```

Forbidding collisions with the built-in prelude will avoid surprising single-file editors. Also forbidding use of privacy stuff before a `use(crate)` it as it wouldn’t apply.

As an alternative to [rfc-890](https://github.com/rust-lang/rfcs/pull/890) I suppose it has similar drawbacks, but to me the syntax is lighter as it’s close to `pub(crate)`. Forbidding collision with the std prelude also avoids a bunch of issues.

I read the comments on that rfc and I’m not currently convinced my version would be bad. Please help 🙂

---

<div class="post-metadata">

### Author: ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)
#### Post date: [November 30, 2018, 3:14pm UTC](https://internals.rust-lang.org/t/pre-rfc-crate-wide-imports/8934/2 "2018-11-30T15:14:38Z")

</div>

The biggest advantage of “custom preludes” over ad-hoc `use(crate)` is only having one _known_ location to look for for these implicitly-in-scope names. Restricting `use(crate)` to only be used at the root is surprising itself, as code in `lib.rs` cannot be indiscriminately moved to a different module (which was a part of the motivator for the edition changes to paths).

That said, the reason said proposal is a hard sell is that it’s not too hard to write `use crate::prelude::*` or even `use crate::*` in modules that want to bring common names into scope to work with, and that gives more local information about the presence of names.

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)
#### Post date: [March 25, 2019, 8:31am UTC](https://internals.rust-lang.org/t/pre-rfc-crate-wide-imports/8934/3 "2019-03-25T08:31:14Z")

</div>

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