diff --git a/src/attributes.md b/src/attributes.md index 7294de6e2..abf36d415 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -107,6 +107,9 @@ names have meaning. ## Crate-only attributes +> **Note**: This section is in the process of being removed, with specific +> sections for each attribute. It is not the full list of crate-root attributes. + - `crate_name` - specify the crate's crate name. - `crate_type` - see [linkage](linkage.html). - `no_builtins` - disable optimizing certain code patterns to invocations of @@ -115,7 +118,6 @@ names have meaning. object being linked to defines `main`. - `no_start` - disable linking to the `native` crate, which specifies the "start" language item. -- `no_std` - disable linking to the `std` crate. - `recursion_limit` - Sets the maximum depth for potentially infinitely-recursive compile-time operations like auto-dereference or macro expansion. The default is @@ -130,14 +132,6 @@ names have meaning. [subsystem]: https://msdn.microsoft.com/en-us/library/fcc1zstk.aspx -## Module-only attributes - -- `no_implicit_prelude` - disable injecting `use std::prelude::*` in this - module. -- `path` - specifies the file to load the module from. `#[path="foo.rs"] mod - bar;` is equivalent to `mod bar { /* contents of foo.rs */ }`. The path is - taken relative to the directory that the current module is in. - ## FFI attributes On an `extern` block, the following attributes are interpreted: @@ -245,6 +239,17 @@ are transformed into `doc` attributes. See [The Rustdoc Book] for reference material on this attribute. +### `path` + +The `path` attribute says where a [module]'s source file is. See [modules] for +more information. + +### Preludes + +The [prelude] behavior can be modified with attributes. The [`no_std`] attribute +changes the prelude to the core prelude while the [`no_implicit_prelude`] +prevents the prelude from being added to the module. + ### Testing The compiler comes with a default test framework. It works by attributing @@ -527,8 +532,12 @@ You can implement `derive` for your own traits through [procedural macros]. [_LiteralExpression_]: expressions/literal-expr.html [_SimplePath_]: paths.html#simple-paths +[`no_implicit_prelude`]: items/modules.html +[`no_std`]: crates-and-source-files.html#preludes-and-no_std [Doc comments]: comments.html#doc-comments [The Rustdoc Book]: ../rustdoc/the-doc-attribute.html +[module]: items/modules.html +[prelude]: crates-and-source-files.html#preludes-and-no_std [procedural macros]: procedural-macros.html [struct]: items/structs.html [enum]: items/enumerations.html diff --git a/src/crates-and-source-files.md b/src/crates-and-source-files.md index 656ae574c..b2dd4f03f 100644 --- a/src/crates-and-source-files.md +++ b/src/crates-and-source-files.md @@ -20,9 +20,8 @@ Rust's semantics obey a *phase distinction* between compile-time and run-time.[^phase-distinction] Semantic rules that have a *static interpretation* govern the success or failure of compilation, while -semantic rules -that have a *dynamic interpretation* govern the behavior of the program at -run-time. +semantic rules that have a *dynamic interpretation* govern the behavior of the +program at run-time. The compilation model centers on artifacts called _crates_. Each compilation processes a single crate in source form, and if successful, produces a single @@ -66,22 +65,6 @@ apply to the crate as a whole. #![warn(non_camel_case_types)] ``` -A crate that contains a `main` [function] can be compiled to an executable. If a -`main` function is present, it must take no arguments, must not declare any -[trait or lifetime bounds], must not have any [where clauses], and its return -type must be one of the following: - -* `()` -* `Result<(), E> where E: Error` - - - -> Note: The implementation of which return types are allowed is determined by -> the unstable [`Termination`] trait. - - - The optional [_UTF8 byte order mark_] (UTF8BOM production) indicates that the file is encoded in UTF8. It can only occur at the beginning of the file and is ignored by the compiler. @@ -100,6 +83,48 @@ fn main() { } ``` +## Preludes and `no_std` + +All crates have a *prelude* that automatically inserts names from a specific +module, the *prelude module*, into scope of each [module] and an [`extern +crate]` into the crate root module. By default, the *standard prelude* is used. +The linked crate is [`std`] and the prelude module is [`std::prelude::v1`]. + +The prelude can be changed to the *core prelude* by using the `no_std` +[attribute] on the root crate module. The linked crate is [`core`] and the +prelude module is [`core::prelude::v1`]. Using the core prelude over the +standard prelude is useful when either the crate is targeting a platform that +does not support the standard library or is purposefully not using the +capabilities of the standard library. Those capabilities are mainly dynamic +memory allocation (e.g. `Box` and `Vec`) and file and network capabilities (e.g. +`std::fs` and `std::io`). + +