Skip to content

Start documenting name resolution. #937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updates to no_implicit_prelude and no_std.
* Fix: no_implicit_prelude behaves differently in 2015.
* Try to make it clearer how standard library stuff is injected into
  the crate.
  • Loading branch information
ehuss committed Jan 19, 2021
commit 0ce54e64e3c98d99862485c57087d0ab36f40ef0
3 changes: 2 additions & 1 deletion src/items/extern-crates.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ useful for crates that only need to be linked, but are never referenced, and
will avoid being reported as unused.

The [`macro_use` attribute] works as usual and import the macro names
into the macro-use prelude.
into the [`macro_use` prelude].

## The `no_link` attribute

Expand All @@ -77,6 +77,7 @@ crate to access only its macros.
[RFC 940]: https://github.com/rust-lang/rfcs/blob/master/text/0940-hyphens-considered-harmful.md
[`macro_use` attribute]: ../macros-by-example.md#the-macro_use-attribute
[extern prelude]: ../names/preludes.md#extern-prelude
[`macro_use` prelude]: ../names/preludes.md#macro_use-prelude

<script>
(function() {
Expand Down
17 changes: 15 additions & 2 deletions src/names/preludes.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,21 @@ alloc/test limitation.

### The `no_std` attribute

By default, the standard library is automatically included in the crate root
module. The [`std`] crate is added to the root, along with an implicit
[`macro_use` attribute] pulling in all macros exported from `std` into the
[`macro_use` prelude]. Both [`core`] and [`std`] are added to the [extern
prelude]. The [standard library prelude] includes everything from the
[`std::prelude::v1`] module.

The *`no_std` [attribute]* may be applied at the crate level to prevent the
[`std`] crate from being automatically added into scope. It does three things:

* Prevents `std` from being added to the [extern prelude](#extern-prelude).
* Uses [`core::prelude::v1`] in the [standard library prelude] instead of
[`std::prelude::v1`].
* Injects the [`core`] crate into the crate root instead of `std`.
* Injects the [`core`] crate into the crate root instead of [`std`], and pulls
in all macros exported from `core` in the [`macro_use` prelude].

> **Note**: Using the core prelude over the standard prelude is useful when
> either the crate is targeting a platform that does not support the standard
Expand Down Expand Up @@ -112,7 +120,12 @@ on a module to indicate that it should not automatically bring the [standard
library prelude], [extern prelude], or [tool prelude] into scope for that
module or any of its descendants.

This attribute does not affect the [language prelude] or [`macro_use` prelude].
This attribute does not affect the [language prelude].

> **Edition Differences**: In the 2015 edition, the `no_implicit_prelude`
> attribute does not affect the [`macro_use` prelude], and all macros exported
> from the standard library are still included in the `macro_use` prelude.
> Starting in the 2018 edition, it will remove the `macro_use` prelude.

[`alloc`]: ../../alloc/index.html
[`Box`]: ../../std/boxed/struct.Box.html
Expand Down