# Pre-RFC: Expressive Standard Library Paths

**URL:** <https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238>\
**Category:** libs\
**Created:** [October 20, 2020, 10:47am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238 "2020-10-20T10:47:09Z")\
**Posts on this page:** 19\
**Page:** 2

<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:** [October 20, 2020, 8:59pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/21 "2020-10-20T20:59:25Z")

</div>

> [@H2CO3](#):
>
> when does one _actually_ need to write such code outside of a proc-macro

You have to for resilient `macro_rules!` macros as well, because item names are resolved at the call site. [Example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=08d9c195fa3bcc50ab452b6ad9a30199):

```rust
macro_rules! m {
    () => {Vec::<u8>::new()};
}

mod ok {
    fn f() {
        m!();
    }
}

mod nok {
    type Vec = u8;
    fn f() {
        m!(); // ~ Error: no function or associated item named `new` found for type `u8`
    }
}

```

> [@H2CO3](#):
>
> (where it's invisible to human consumers of the code)

This is not a great argument. Someone still has to write the macro, and that someone has to maintain the code the macro outputs. It's much easier to do so the less namespace noise that is present.

* * *

A "perfect"ly implemented `macro_rules!` macro that wanted to use the `std`'s `Vec` would use `$crate::_reexports::alloc::vec::Vec`. A more prepared one night use `$crate::_reexports::Vec`, if they make their hidden `_reexports` module directly reëxport the types they are using.

A less paranoid macro would just use `::alloc::vec::Vec`, or maybe `::std::vec::Vec`. (If you're using std, there's no reason for your downstream to be `#![no_std]`, and renaming not-`std` to be used at `::std` is just asking for things to not work.)

The "proper" solution for the macro (decl or proc) is full def-site hygeine for all items, not just local bindings ("macros 2.0"). But reëxporting items at their shortest reasonable path would be an improvement for macros in the short term, where full hygeine is decidedly long-term.

---

<div class="post-metadata">

**Author:** ![withoutboats](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/withoutboats/32/4560_2.png) [@withoutboats](https://internals.rust-lang.org/u/withoutboats)\
**Post date:** [October 20, 2020, 10:56pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/22 "2020-10-20T22:56:53Z")

</div>

> [@mjbshaw](#):
>
> New traits in the prelude are an allowed breaking change. They don't require an edition boundary. For example, see `Unpin` .

Adding a marker trait like Unpin to the prelude is specifically not a breaking change because it doesn't contain any new associated items like methods, which could conflict with the items of other traits the user has already brought into scope and cause a compile failure in existing code.

---

<div class="post-metadata">

**Author:** ![Mart-Bogdan](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mart-bogdan/32/5104_2.png) [@Mart-Bogdan](https://internals.rust-lang.org/u/Mart-Bogdan)\
**Post date:** [October 26, 2020, 12:20am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/23 "2020-10-26T00:20:28Z")

</div>

> [@comex](#):
>
> When writing new code, I _hate_ that whenever I mention a new std type for the first time, I have to break my flow, jump up to the top of the file, and type out a wordy `use` statement. (I have the same issue in C/C++ with `#include`s.)

But that is easily solvable by IDE, at least by Intlij Rust plugin, just hit Alt+Enter and it generates `use`. I'm not sure if it works with Rust Analyzer.

---

<div class="post-metadata">

**Author:** ![Mart-Bogdan](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mart-bogdan/32/5104_2.png) [@Mart-Bogdan](https://internals.rust-lang.org/u/Mart-Bogdan)\
**Post date:** [October 26, 2020, 12:22am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/24 "2020-10-26T00:22:04Z")

</div>

Me personally is more pissed by warnings from unused imports, when you actively change code and remove some bits for sake of experimentation.

But I agree that unused ones should not go into final commit.

---

<div class="post-metadata">

**Author:** ![johnthagen](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/johnthagen/32/2005_2.png) [@johnthagen](https://internals.rust-lang.org/u/johnthagen)\
**Post date:** [October 26, 2020, 12:49am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/25 "2020-10-26T00:49:30Z")

</div>

> [@Mart-Bogdan](#):
>
> warnings from unused imports

I haven't used IntelliJ Rust in a little while, but other IntelliJ products have Ctrl+Alt+O (Optimize Imports) which can automatically remove unused imports.

---

<div class="post-metadata">

**Author:** ![Mart-Bogdan](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mart-bogdan/32/5104_2.png) [@Mart-Bogdan](https://internals.rust-lang.org/u/Mart-Bogdan)\
**Post date:** [October 26, 2020, 12:52am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/26 "2020-10-26T00:52:06Z")

</div>

> [@johnthagen](#):
>
> I haven't used IntelliJ Rust in a little while, but other IntelliJ products have Ctrl+Alt+O (Optimize Imports) which can automatically remove unused imports.

Indeed. I haven't used hotkey, but manual way on unused imports with a tooltip. But my point was that when you experiment with code, you comment some lines out, then uncomment and import is useful again. It's a bit of annoyance.

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [October 26, 2020, 8:06am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/27 "2020-10-26T08:06:24Z")

</div>

If you're just experimenting, you can ignore the warning, and then fix the `use` lines before you commit.

---

<div class="post-metadata">

**Author:** ![birkenfeld](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/birkenfeld/32/1150_2.png) [@birkenfeld](https://internals.rust-lang.org/u/birkenfeld)\
**Post date:** [October 26, 2020, 10:18am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/28 "2020-10-26T10:18:20Z")

</div>

And if you have this situation a lot, and want to silence the warnings, you can also temporarily add `#[allow(unused)]` or `#[allow(unused_imports)]` to the module you're working on.

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [October 26, 2020, 5:36pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/29 "2020-10-26T17:36:53Z")

</div>

> [@birkenfeld](#):
>
> temporarily add `#[allow(unused)]` or `#[allow(unused_imports)]` to the module

I'm a big fan of things like `#![cfg_attr(test, allow(unused, dead_code))]`.

---

<div class="post-metadata">

**Author:** ![comex](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/comex/32/2587_2.png) [@comex](https://internals.rust-lang.org/u/comex)\
**Post date:** [October 26, 2020, 6:08pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/30 "2020-10-26T18:08:30Z")

</div>

> [@Mart-Bogdan](#):
>
> But that is easily solvable by IDE, at least by Intlij Rust plugin, just hit Alt+Enter and it generates `use` . I'm not sure if it works with Rust Analyzer.

As I said, I don't use an IDE, and I don't think Rust should require an IDE to be present for it to be ergonomic.

---

<div class="post-metadata">

**Author:** ![Mart-Bogdan](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mart-bogdan/32/5104_2.png) [@Mart-Bogdan](https://internals.rust-lang.org/u/Mart-Bogdan)\
**Post date:** [October 26, 2020, 8:33pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/31 "2020-10-26T20:33:50Z")

</div>

> [@scottmcm](#):
>
> I'm a big fan of things like `#![cfg_attr(test, allow(unused, dead_code))]` .

Indeed, so you could test that the following code actually typecheck and compiles, but you don't care to run a particular code.

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [October 26, 2020, 9:39pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/32 "2020-10-26T21:39:36Z")

</div>

> [@comex](#):
>
> As I said, I don't use an IDE, and I don't think Rust should require an IDE to be present for it to be ergonomic.

I think I feel differently depending on how big and complicated the work to integrate into a editor it is. I agree you shouldn't need some nontrivial-startup-time IDE like Eclipse or VS. But where's that line? I generally don't consider Sublime Text to be "an IDE", but it can still give me buttons to apply structured suggestions from rust(c|ls|a|whatever). And that's a huge help that I would encourage everyone to setup. Note that [even the playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=36f4b8e87dfffc1911223e14598f5025) has click-to-add-use.

Overall, though, I feel like if the problem is the `use`s, then changing `use std::time::Instant;` to `use std::Instant;` doesn't really move the needle to me. Similarly for the non-use version of `std::time::Instant::now()` vs `std::Instant::now()`.

Everything in the root also feels like it's just asking for more `use std::*;`, too -- which C++ learned (from `using namespace std;` is not a good thing.

I think the answer here is prelude(s), not reexporting in the root of crates.

---

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matklad/32/12266_2.png) [@matklad](https://internals.rust-lang.org/u/matklad)\
**Post date:** [October 26, 2020, 9:48pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/33 "2020-10-26T21:48:48Z")

</div>

> [@scottmcm](#):
>
> which C++ learned (from `using namespace std;` is not a good thing.

While I also think that `use *` is usually wrong, I don't think this particular argument is applicable in Rust. `using namespace std;` is problematic in C++ primarily because of C++ specific concerns, like dumping symbols into the global namespace (especially if done in header files) or adding a lot of overload resolutions. Start imports are much less problematic (and idiomatic) in Kotlin&Java.

To be clear, I don't have a position I want to argue for in this discussion, I just want to nitpick sightly flawed reasoning 🙂

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [October 27, 2020, 5:16am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/34 "2020-10-27T05:16:52Z")

</div>

> [@matklad](#):
>
> `using namespace std;` is problematic in C++ primarily because of C++ specific concerns, like dumping symbols into the global namespace (especially if done in header files) or adding a lot of overload resolutions.

That's fair, `using namespace std;` is more like `pub use std::*;`, and the `pub` makes it much worse.

Pulling in arbitrary traits using `*` does do rust's form of "adding lots of overloads", though.

---

<div class="post-metadata">

**Author:** ![Mart-Bogdan](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mart-bogdan/32/5104_2.png) [@Mart-Bogdan](https://internals.rust-lang.org/u/Mart-Bogdan)\
**Post date:** [October 27, 2020, 9:35am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/35 "2020-10-27T09:35:48Z")

</div>

> [@matklad](#):
>
> Start imports are much less problematic (and idiomatic) in Kotlin&Java.

I'm not sure about Kotlin, but in Java star imports are considered bad, beside importing from standard runtime with widely known classes.

Motivation is to be able to distinguish imported classes/static method when viewing code without IDE, like in Github, for code-review.

---

<div class="post-metadata">

**Author:** ![dhm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dhm/32/4879_2.png) [@dhm](https://internals.rust-lang.org/u/dhm)\
**Post date:** [October 27, 2020, 12:09pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/36 "2020-10-27T12:09:58Z")

</div>

> [@scottmcm](#):
>
> `allow(unused`

Don't forget to attach a `warn(unused_must_use)` (I wish there was a group lint for all the `unused` but `must_use`).

---

<div class="post-metadata">

**Author:** ![Tom-Phinney](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tom-phinney/32/3299_2.png) [@Tom-Phinney](https://internals.rust-lang.org/u/Tom-Phinney)\
**Post date:** [October 27, 2020, 2:24pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/37 "2020-10-27T14:24:24Z")

</div>

> [@dhm](#):
>
> (I wish there was a group lint for all the `unused` but `must_use` )

Why not propose that yourself, either here or to the appropriate tools team?

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [October 27, 2020, 4:23pm UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/38 "2020-10-27T16:23:08Z")

</div>

> [@scottmcm](#):
>
> Overall, though, I feel like if the problem is the `use` s, then changing `use std::time::Instant;` to `use std::Instant;` doesn't really move the needle to me.

But being able to write `fn func(t: std::Instant)` seems like an improvement. Most of the proposed additions are types.

---

<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:** [January 28, 2021, 8:26am UTC](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238/40 "2021-01-28T08:26:31Z")

</div>

Closed on January 28, 2021, 8:26am UTC

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

[Previous page](https://internals.rust-lang.org/t/pre-rfc-expressive-standard-library-paths/13238.md?page=1)
