From f6f31dd14382d207be8e08229ec783033e28bc0d Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 3 Sep 2015 21:10:48 +0200 Subject: [PATCH 1/6] book: improve paragraph on stack de-allocation --- src/doc/trpl/the-stack-and-the-heap.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/the-stack-and-the-heap.md b/src/doc/trpl/the-stack-and-the-heap.md index e7e98c5828c..91b892fccaa 100644 --- a/src/doc/trpl/the-stack-and-the-heap.md +++ b/src/doc/trpl/the-stack-and-the-heap.md @@ -41,8 +41,8 @@ and just consider the local variables we’re allocating. So in this case, when This is automatically handled for you, as you can see, we didn’t have to write any special Rust code or anything. -When the function is over, its stack frame gets deallocated. This happens -automatically, we didn’t have to do anything special here. +When the function exits, its stack frame gets deallocated. This happens +automatically as well. That’s all there is for this simple program. The key thing to understand here is that stack allocation is very, very fast. Since we know all the local From 64cc19d52059d73723c9b0354e7939f90960123d Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 24 Sep 2015 07:27:16 +0200 Subject: [PATCH 2/6] reference: "ffi" is normally in upper case --- src/doc/reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 83849574260..046462e0807 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3931,7 +3931,7 @@ initialized; this is enforced by the compiler. The Rust compiler supports various methods to link crates together both statically and dynamically. This section will explore the various methods to link Rust crates together, and more information about native libraries can be -found in the [ffi section of the book][ffi]. +found in the [FFI section of the book][ffi]. In one session of compilation, the compiler can generate multiple artifacts through the usage of either command line flags or the `crate_type` attribute. From 16244b884dd7716fbab8e7cd8a235567cee46229 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 24 Sep 2015 07:43:37 +0200 Subject: [PATCH 3/6] reference: make that less awkward to read --- src/doc/reference.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 83849574260..f187986ffb7 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3935,7 +3935,7 @@ found in the [ffi section of the book][ffi]. In one session of compilation, the compiler can generate multiple artifacts through the usage of either command line flags or the `crate_type` attribute. -If one or more command line flag is specified, all `crate_type` attributes will +If one or more command line flags are specified, all `crate_type` attributes will be ignored in favor of only building the artifacts specified by command line. * `--crate-type=bin`, `#[crate_type = "bin"]` - A runnable executable will be @@ -3981,7 +3981,7 @@ Note that these outputs are stackable in the sense that if multiple are specified, then the compiler will produce each form of output at once without having to recompile. However, this only applies for outputs specified by the same method. If only `crate_type` attributes are specified, then they will all -be built, but if one or more `--crate-type` command line flag is specified, +be built, but if one or more `--crate-type` command line flags are specified, then only those outputs will be built. With all these different kinds of outputs, if crate A depends on crate B, then From 4632ad889686006c6c52f165c360fe6d4d381f98 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Wed, 30 Sep 2015 11:46:33 -0400 Subject: [PATCH 4/6] Update no_std docs This is part of #28572, but doesn't complete it. Amongst other things, this patch: * Increases consistency in the way feature flags are used with other docs. * Removes the ignores, which is nice: we actually had some syntax errors in the examples :sob:. * Mentions #![no_core] Realistically, this document used to be in the order of least to most: nothing, then adding core. But with the changes in RFC 1184, this is backwards: it now shows stuff that uses core from the beginning. In the future, I'd like to revamp this to go from 'most to least', but I'd like to see the discussion in https://github.com/rust-lang/rust/issues/27701 goes before I write more. --- src/doc/trpl/no-stdlib.md | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/doc/trpl/no-stdlib.md b/src/doc/trpl/no-stdlib.md index 9abcd330989..5fca05d5340 100644 --- a/src/doc/trpl/no-stdlib.md +++ b/src/doc/trpl/no-stdlib.md @@ -4,14 +4,6 @@ By default, `std` is linked to every Rust crate. In some contexts, this is undesirable, and can be avoided with the `#![no_std]` attribute attached to the crate. -```ignore -// a minimal library -#![crate_type="lib"] -#![feature(no_std)] -#![no_std] -# // fn main() {} tricked you, rustdoc! -``` - Obviously there's more to life than just libraries: one can use `#[no_std]` with an executable, controlling the entry point is possible in two ways: the `#[start]` attribute, or overriding the @@ -21,7 +13,10 @@ The function marked `#[start]` is passed the command line parameters in the same format as C: ```rust -#![feature(lang_items, start, no_std, libc)] +# #![feature(libc)] +#![feature(lang_items)] +#![feature(start)] +#![feature(no_std)] #![no_std] // Pull in the system libc library for what crt0.o likely requires @@ -47,11 +42,13 @@ with `#![no_main]` and then create the appropriate symbol with the correct ABI and the correct name, which requires overriding the compiler's name mangling too: -```ignore +```rust +# #![feature(libc)] #![feature(no_std)] +#![feature(lang_items)] +#![feature(start)] #![no_std] #![no_main] -#![feature(lang_items, start)] extern crate libc; @@ -92,19 +89,24 @@ instead. The core library has very few dependencies and is much more portable than the standard library itself. Additionally, the core library has most of the -necessary functionality for writing idiomatic and effective Rust code. +necessary functionality for writing idiomatic and effective Rust code. When +using `#![no_std]`, Rust will automatically inject the `core` crate, just like +we do for `std` when we’re using it. As an example, here is a program that will calculate the dot product of two vectors provided from C, using idiomatic Rust practices. -```ignore -#![feature(lang_items, start, no_std, core, libc)] +```rust +# #![feature(libc)] +#![feature(lang_items)] +#![feature(start)] +#![feature(no_std)] +#![feature(core)] +#![feature(core_slice_ext)] +#![feature(raw)] #![no_std] -# extern crate libc; -extern crate core; - -use core::prelude::*; +extern crate libc; use core::mem; From 3e9b993925477a3c4506b02373c75605fe17c2f0 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Wed, 30 Sep 2015 13:24:28 -0400 Subject: [PATCH 5/6] Clarify logic instead of using 'vice versa' Fixes #28166 --- src/libcore/cmp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 3344d7ea5d7..fa1f4727bc0 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -218,7 +218,7 @@ impl PartialOrd for Ordering { /// /// The comparison must satisfy, for all `a`, `b` and `c`: /// -/// - antisymmetry: if `a < b` then `!(a > b)` and vice versa; and +/// - antisymmetry: if `a < b` then `!(a > b)`, as well as `a > b` implying `!(a < b)`; and /// - transitivity: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. /// /// Note that these requirements mean that the trait itself must be implemented symmetrically and From 2a787a23d1834398d5a945f83b54ccbd577d1d3b Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Wed, 30 Sep 2015 13:42:57 -0400 Subject: [PATCH 6/6] Improve identifier defintion in the reference Fixes #28706 --- src/doc/reference.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 8b95a2e539b..73700765b32 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -76,8 +76,13 @@ An identifier is any nonempty Unicode[^non_ascii_idents] string of the following [^non_ascii_idents]: Non-ASCII characters in identifiers are currently feature gated. This is expected to improve soon. -- The first character has property `XID_start` -- The remaining characters have property `XID_continue` +Either + * The first character has property `XID_start` + * The remaining characters have property `XID_continue` +Or + * The first character is `_` + * The identifier is more than one character, `_` alone is not an identifier + * The remaining characters have property `XID_continue` that does _not_ occur in the set of [keywords][keywords].