Auto merge of #24758 - Manishearth:rollup, r=Manishearth
- Successful merges: #24523, #24698, #24699, #24700, #24706, #24717, #24718, #24721, #24727 - Failed merges:
This commit is contained in:
commit
f191f92421
@ -271,7 +271,7 @@ cases mentioned in [Number literals](#number-literals) below.
|
|||||||
##### Suffixes
|
##### Suffixes
|
||||||
| Integer | Floating-point |
|
| Integer | Floating-point |
|
||||||
|---------|----------------|
|
|---------|----------------|
|
||||||
| `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `is` (`isize`), `us` (`usize`) | `f32`, `f64` |
|
| `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `isize`, `usize` | `f32`, `f64` |
|
||||||
|
|
||||||
#### Character and string literals
|
#### Character and string literals
|
||||||
|
|
||||||
@ -738,15 +738,26 @@ Rust syntax is restricted in two ways:
|
|||||||
|
|
||||||
# Crates and source files
|
# Crates and source files
|
||||||
|
|
||||||
Rust is a *compiled* language. Its semantics obey a *phase distinction* between
|
Although Rust, like any other language, can be implemented by an interpreter as
|
||||||
compile-time and run-time. Those semantic rules that have a *static
|
well as a compiler, the only existing implementation is a compiler —
|
||||||
|
from now on referred to as *the* Rust compiler — and the language has
|
||||||
|
always been designed to be compiled. For these reasons, this section assumes a
|
||||||
|
compiler.
|
||||||
|
|
||||||
|
Rust's semantics obey a *phase distinction* between compile-time and
|
||||||
|
run-time.[^phase-distinction] Those semantic rules that have a *static
|
||||||
interpretation* govern the success or failure of compilation. Those semantics
|
interpretation* govern the success or failure of compilation. Those semantics
|
||||||
that have a *dynamic interpretation* govern the behavior of the program at
|
that have a *dynamic interpretation* govern the behavior of the program at
|
||||||
run-time.
|
run-time.
|
||||||
|
|
||||||
|
[^phase-distinction]: This distinction would also exist in an interpreter.
|
||||||
|
Static checks like syntactic analysis, type checking, and lints should
|
||||||
|
happen before the program is executed regardless of when it is executed.
|
||||||
|
|
||||||
The compilation model centers on artifacts called _crates_. Each compilation
|
The compilation model centers on artifacts called _crates_. Each compilation
|
||||||
processes a single crate in source form, and if successful, produces a single
|
processes a single crate in source form, and if successful, produces a single
|
||||||
crate in binary form: either an executable or a library.[^cratesourcefile]
|
crate in binary form: either an executable or some sort of
|
||||||
|
library.[^cratesourcefile]
|
||||||
|
|
||||||
[^cratesourcefile]: A crate is somewhat analogous to an *assembly* in the
|
[^cratesourcefile]: A crate is somewhat analogous to an *assembly* in the
|
||||||
ECMA-335 CLI model, a *library* in the SML/NJ Compilation Manager, a *unit*
|
ECMA-335 CLI model, a *library* in the SML/NJ Compilation Manager, a *unit*
|
||||||
@ -767,21 +778,25 @@ extension `.rs`.
|
|||||||
A Rust source file describes a module, the name and location of which —
|
A Rust source file describes a module, the name and location of which —
|
||||||
in the module tree of the current crate — are defined from outside the
|
in the module tree of the current crate — are defined from outside the
|
||||||
source file: either by an explicit `mod_item` in a referencing source file, or
|
source file: either by an explicit `mod_item` in a referencing source file, or
|
||||||
by the name of the crate itself.
|
by the name of the crate itself. Every source file is a module, but not every
|
||||||
|
module needs its own source file: [module definitions](#modules) can be nested
|
||||||
|
within one file.
|
||||||
|
|
||||||
Each source file contains a sequence of zero or more `item` definitions, and
|
Each source file contains a sequence of zero or more `item` definitions, and
|
||||||
may optionally begin with any number of `attributes` that apply to the
|
may optionally begin with any number of [attributes](#Items and attributes)
|
||||||
containing module. Attributes on the anonymous crate module define important
|
that apply to the containing module, most of which influence the behavior of
|
||||||
metadata that influences the behavior of the compiler.
|
the compiler. The anonymous crate module can have additional attributes that
|
||||||
|
apply to the crate as a whole.
|
||||||
|
|
||||||
```no_run
|
```no_run
|
||||||
// Crate name
|
// Specify the crate name.
|
||||||
#![crate_name = "projx"]
|
#![crate_name = "projx"]
|
||||||
|
|
||||||
// Specify the output type
|
// Specify the type of output artifact.
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
// Turn on a warning
|
// Turn on a warning.
|
||||||
|
// This can be done in any module, not just the anonymous crate module.
|
||||||
#![warn(non_camel_case_types)]
|
#![warn(non_camel_case_types)]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
* [Learn Rust](learn-rust.md)
|
* [Learn Rust](learn-rust.md)
|
||||||
* [Effective Rust](effective-rust.md)
|
* [Effective Rust](effective-rust.md)
|
||||||
* [The Stack and the Heap](the-stack-and-the-heap.md)
|
* [The Stack and the Heap](the-stack-and-the-heap.md)
|
||||||
* [Debug and Display](debug-and-display.md)
|
|
||||||
* [Testing](testing.md)
|
* [Testing](testing.md)
|
||||||
* [Conditional Compilation](conditional-compilation.md)
|
* [Conditional Compilation](conditional-compilation.md)
|
||||||
* [Documentation](documentation.md)
|
* [Documentation](documentation.md)
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
% Debug and Display
|
|
||||||
|
|
||||||
Coming soon!
|
|
@ -80,7 +80,7 @@ impl<T> Clone for Slice<T> {
|
|||||||
/// `TraitObject` is guaranteed to match layouts, but it is not the
|
/// `TraitObject` is guaranteed to match layouts, but it is not the
|
||||||
/// type of trait objects (e.g. the fields are not directly accessible
|
/// type of trait objects (e.g. the fields are not directly accessible
|
||||||
/// on a `&SomeTrait`) nor does it control that layout (changing the
|
/// on a `&SomeTrait`) nor does it control that layout (changing the
|
||||||
/// definition will not change the layout of a `&SometTrait`). It is
|
/// definition will not change the layout of a `&SomeTrait`). It is
|
||||||
/// only designed to be used by unsafe code that needs to manipulate
|
/// only designed to be used by unsafe code that needs to manipulate
|
||||||
/// the low-level details.
|
/// the low-level details.
|
||||||
///
|
///
|
||||||
|
@ -75,11 +75,13 @@ the following is invalid as it requires the entire Option<String> to be moved
|
|||||||
into a variable called `op_string` while simultaneously requiring the inner
|
into a variable called `op_string` while simultaneously requiring the inner
|
||||||
String to be moved into a variable called `s`.
|
String to be moved into a variable called `s`.
|
||||||
|
|
||||||
|
```
|
||||||
let x = Some("s".to_string());
|
let x = Some("s".to_string());
|
||||||
match x {
|
match x {
|
||||||
op_string @ Some(s) => ...
|
op_string @ Some(s) => ...
|
||||||
None => ...
|
None => ...
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
See also Error 303.
|
See also Error 303.
|
||||||
"##,
|
"##,
|
||||||
@ -90,10 +92,12 @@ name is bound by move in a pattern, it should also be moved to wherever it is
|
|||||||
referenced in the pattern guard code. Doing so however would prevent the name
|
referenced in the pattern guard code. Doing so however would prevent the name
|
||||||
from being available in the body of the match arm. Consider the following:
|
from being available in the body of the match arm. Consider the following:
|
||||||
|
|
||||||
|
```
|
||||||
match Some("hi".to_string()) {
|
match Some("hi".to_string()) {
|
||||||
Some(s) if s.len() == 0 => // use s.
|
Some(s) if s.len() == 0 => // use s.
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
The variable `s` has type String, and its use in the guard is as a variable of
|
The variable `s` has type String, and its use in the guard is as a variable of
|
||||||
type String. The guard code effectively executes in a separate scope to the body
|
type String. The guard code effectively executes in a separate scope to the body
|
||||||
@ -102,11 +106,13 @@ become unavailable in the body of the arm. Although this example seems
|
|||||||
innocuous, the problem is most clear when considering functions that take their
|
innocuous, the problem is most clear when considering functions that take their
|
||||||
argument by value.
|
argument by value.
|
||||||
|
|
||||||
|
```
|
||||||
match Some("hi".to_string()) {
|
match Some("hi".to_string()) {
|
||||||
Some(s) if { drop(s); false } => (),
|
Some(s) if { drop(s); false } => (),
|
||||||
Some(s) => // use s.
|
Some(s) => // use s.
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
The value would be dropped in the guard then become unavailable not only in the
|
The value would be dropped in the guard then become unavailable not only in the
|
||||||
body of that arm but also in all subsequent arms! The solution is to bind by
|
body of that arm but also in all subsequent arms! The solution is to bind by
|
||||||
@ -219,8 +225,10 @@ them yourself.
|
|||||||
You can build a free-standing crate by adding `#![no_std]` to the crate
|
You can build a free-standing crate by adding `#![no_std]` to the crate
|
||||||
attributes:
|
attributes:
|
||||||
|
|
||||||
|
```
|
||||||
#![feature(no_std)]
|
#![feature(no_std)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
```
|
||||||
|
|
||||||
See also https://doc.rust-lang.org/book/no-stdlib.html
|
See also https://doc.rust-lang.org/book/no-stdlib.html
|
||||||
"##,
|
"##,
|
||||||
@ -236,11 +244,13 @@ mutex can be declared `static` as well.
|
|||||||
|
|
||||||
If you want to match against a `static`, consider using a guard instead:
|
If you want to match against a `static`, consider using a guard instead:
|
||||||
|
|
||||||
|
```
|
||||||
static FORTY_TWO: i32 = 42;
|
static FORTY_TWO: i32 = 42;
|
||||||
match Some(42) {
|
match Some(42) {
|
||||||
Some(x) if x == FORTY_TWO => ...
|
Some(x) if x == FORTY_TWO => ...
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
E0161: r##"
|
E0161: r##"
|
||||||
@ -256,6 +266,7 @@ An if-let pattern attempts to match the pattern, and enters the body if the
|
|||||||
match was succesful. If the match is irrefutable (when it cannot fail to match),
|
match was succesful. If the match is irrefutable (when it cannot fail to match),
|
||||||
use a regular `let`-binding instead. For instance:
|
use a regular `let`-binding instead. For instance:
|
||||||
|
|
||||||
|
```
|
||||||
struct Irrefutable(i32);
|
struct Irrefutable(i32);
|
||||||
let irr = Irrefutable(0);
|
let irr = Irrefutable(0);
|
||||||
|
|
||||||
@ -268,6 +279,7 @@ if let Irrefutable(x) = irr {
|
|||||||
// Try this instead:
|
// Try this instead:
|
||||||
let Irrefutable(x) = irr;
|
let Irrefutable(x) = irr;
|
||||||
foo(x);
|
foo(x);
|
||||||
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
E0165: r##"
|
E0165: r##"
|
||||||
@ -275,6 +287,7 @@ A while-let pattern attempts to match the pattern, and enters the body if the
|
|||||||
match was succesful. If the match is irrefutable (when it cannot fail to match),
|
match was succesful. If the match is irrefutable (when it cannot fail to match),
|
||||||
use a regular `let`-binding inside a `loop` instead. For instance:
|
use a regular `let`-binding inside a `loop` instead. For instance:
|
||||||
|
|
||||||
|
```
|
||||||
struct Irrefutable(i32);
|
struct Irrefutable(i32);
|
||||||
let irr = Irrefutable(0);
|
let irr = Irrefutable(0);
|
||||||
|
|
||||||
@ -288,22 +301,27 @@ loop {
|
|||||||
let Irrefutable(x) = irr;
|
let Irrefutable(x) = irr;
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
E0170: r##"
|
E0170: r##"
|
||||||
Enum variants are qualified by default. For example, given this type:
|
Enum variants are qualified by default. For example, given this type:
|
||||||
|
|
||||||
|
```
|
||||||
enum Method {
|
enum Method {
|
||||||
GET,
|
GET,
|
||||||
POST
|
POST
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
you would match it using:
|
you would match it using:
|
||||||
|
|
||||||
|
```
|
||||||
match m {
|
match m {
|
||||||
Method::GET => ...
|
Method::GET => ...
|
||||||
Method::POST => ...
|
Method::POST => ...
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
If you don't qualify the names, the code will bind new variables named "GET" and
|
If you don't qualify the names, the code will bind new variables named "GET" and
|
||||||
"POST" instead. This behavior is likely not what you want, so rustc warns when
|
"POST" instead. This behavior is likely not what you want, so rustc warns when
|
||||||
@ -312,8 +330,10 @@ that happens.
|
|||||||
Qualified names are good practice, and most code works well with them. But if
|
Qualified names are good practice, and most code works well with them. But if
|
||||||
you prefer them unqualified, you can import the variants into scope:
|
you prefer them unqualified, you can import the variants into scope:
|
||||||
|
|
||||||
|
```
|
||||||
use Method::*;
|
use Method::*;
|
||||||
enum Method { GET, POST }
|
enum Method { GET, POST }
|
||||||
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
E0267: r##"
|
E0267: r##"
|
||||||
@ -333,7 +353,9 @@ E0296: r##"
|
|||||||
This error indicates that the given recursion limit could not be parsed. Ensure
|
This error indicates that the given recursion limit could not be parsed. Ensure
|
||||||
that the value provided is a positive integer between quotes, like so:
|
that the value provided is a positive integer between quotes, like so:
|
||||||
|
|
||||||
|
```
|
||||||
#![recursion_limit="1000"]
|
#![recursion_limit="1000"]
|
||||||
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
E0297: r##"
|
E0297: r##"
|
||||||
@ -342,6 +364,7 @@ that a name will be extracted in all cases. Instead of pattern matching the
|
|||||||
loop variable, consider using a `match` or `if let` inside the loop body. For
|
loop variable, consider using a `match` or `if let` inside the loop body. For
|
||||||
instance:
|
instance:
|
||||||
|
|
||||||
|
```
|
||||||
// This fails because `None` is not covered.
|
// This fails because `None` is not covered.
|
||||||
for Some(x) in xs {
|
for Some(x) in xs {
|
||||||
...
|
...
|
||||||
@ -361,6 +384,7 @@ for item in xs {
|
|||||||
...
|
...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
E0301: r##"
|
E0301: r##"
|
||||||
@ -370,11 +394,13 @@ on which the match depends in such a way, that the match would not be
|
|||||||
exhaustive. For instance, the following would not match any arm if mutable
|
exhaustive. For instance, the following would not match any arm if mutable
|
||||||
borrows were allowed:
|
borrows were allowed:
|
||||||
|
|
||||||
|
```
|
||||||
match Some(()) {
|
match Some(()) {
|
||||||
None => { },
|
None => { },
|
||||||
option if option.take().is_none() => { /* impossible, option is `Some` */ },
|
option if option.take().is_none() => { /* impossible, option is `Some` */ },
|
||||||
Some(_) => { } // When the previous match failed, the option became `None`.
|
Some(_) => { } // When the previous match failed, the option became `None`.
|
||||||
}
|
}
|
||||||
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
E0302: r##"
|
E0302: r##"
|
||||||
@ -384,11 +410,13 @@ on which the match depends in such a way, that the match would not be
|
|||||||
exhaustive. For instance, the following would not match any arm if assignments
|
exhaustive. For instance, the following would not match any arm if assignments
|
||||||
were allowed:
|
were allowed:
|
||||||
|
|
||||||
|
```
|
||||||
match Some(()) {
|
match Some(()) {
|
||||||
None => { },
|
None => { },
|
||||||
option if { option = None; false } { },
|
option if { option = None; false } { },
|
||||||
Some(_) => { } // When the previous match failed, the option became `None`.
|
Some(_) => { } // When the previous match failed, the option became `None`.
|
||||||
}
|
}
|
||||||
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
E0303: r##"
|
E0303: r##"
|
||||||
@ -396,9 +424,10 @@ In certain cases it is possible for sub-bindings to violate memory safety.
|
|||||||
Updates to the borrow checker in a future version of Rust may remove this
|
Updates to the borrow checker in a future version of Rust may remove this
|
||||||
restriction, but for now patterns must be rewritten without sub-bindings.
|
restriction, but for now patterns must be rewritten without sub-bindings.
|
||||||
|
|
||||||
// Before.
|
```
|
||||||
match Some("hi".to_string()) {
|
// Code like this...
|
||||||
ref op_string_ref @ Some(ref s) => ...
|
match Some(5) {
|
||||||
|
ref op_num @ Some(num) => ...
|
||||||
None => ...
|
None => ...
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,6 +439,7 @@ match Some("hi".to_string()) {
|
|||||||
}
|
}
|
||||||
None => ...
|
None => ...
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
The `op_string_ref` binding has type &Option<&String> in both cases.
|
The `op_string_ref` binding has type &Option<&String> in both cases.
|
||||||
|
|
||||||
|
@ -828,6 +828,9 @@
|
|||||||
$(document).on("click", ".collapse-toggle", function() {
|
$(document).on("click", ".collapse-toggle", function() {
|
||||||
var toggle = $(this);
|
var toggle = $(this);
|
||||||
var relatedDoc = toggle.parent().next();
|
var relatedDoc = toggle.parent().next();
|
||||||
|
if (relatedDoc.is(".stability")) {
|
||||||
|
relatedDoc = relatedDoc.next();
|
||||||
|
}
|
||||||
if (relatedDoc.is(".docblock")) {
|
if (relatedDoc.is(".docblock")) {
|
||||||
if (relatedDoc.is(":visible")) {
|
if (relatedDoc.is(":visible")) {
|
||||||
relatedDoc.slideUp({duration:'fast', easing:'linear'});
|
relatedDoc.slideUp({duration:'fast', easing:'linear'});
|
||||||
@ -848,9 +851,10 @@
|
|||||||
.html("[<span class='inner'>-</span>]");
|
.html("[<span class='inner'>-</span>]");
|
||||||
|
|
||||||
$(".method").each(function() {
|
$(".method").each(function() {
|
||||||
if ($(this).next().is(".docblock")) {
|
if ($(this).next().is(".docblock") ||
|
||||||
$(this).children().first().after(toggle.clone());
|
($(this).next().is(".stability") && $(this).next().next().is(".docblock"))) {
|
||||||
}
|
$(this).children().first().after(toggle.clone());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var mainToggle =
|
var mainToggle =
|
||||||
|
@ -40,14 +40,6 @@ impl Drop for DynamicLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DynamicLibrary {
|
impl DynamicLibrary {
|
||||||
// FIXME (#12938): Until DST lands, we cannot decompose &str into
|
|
||||||
// & and str, so we cannot usefully take ToCStr arguments by
|
|
||||||
// reference (without forcing an additional & around &str). So we
|
|
||||||
// are instead temporarily adding an instance for &Path, so that
|
|
||||||
// we can take ToCStr as owned. When DST lands, the &Path instance
|
|
||||||
// should be removed, and arguments bound by ToCStr should be
|
|
||||||
// passed by reference. (Here: in the `open` method.)
|
|
||||||
|
|
||||||
/// Lazily open a dynamic library. When passed None it gives a
|
/// Lazily open a dynamic library. When passed None it gives a
|
||||||
/// handle to the calling process
|
/// handle to the calling process
|
||||||
pub fn open(filename: Option<&Path>) -> Result<DynamicLibrary, String> {
|
pub fn open(filename: Option<&Path>) -> Result<DynamicLibrary, String> {
|
||||||
|
@ -95,6 +95,8 @@ impl Write for StderrRaw {
|
|||||||
///
|
///
|
||||||
/// This handle implements the `Read` trait, but beware that concurrent reads
|
/// This handle implements the `Read` trait, but beware that concurrent reads
|
||||||
/// of `Stdin` must be executed with care.
|
/// of `Stdin` must be executed with care.
|
||||||
|
///
|
||||||
|
/// Created by the function `io::stdin()`.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct Stdin {
|
pub struct Stdin {
|
||||||
inner: Arc<Mutex<BufReader<StdinRaw>>>,
|
inner: Arc<Mutex<BufReader<StdinRaw>>>,
|
||||||
@ -206,6 +208,8 @@ const OUT_MAX: usize = ::usize::MAX;
|
|||||||
/// Each handle shares a global buffer of data to be written to the standard
|
/// Each handle shares a global buffer of data to be written to the standard
|
||||||
/// output stream. Access is also synchronized via a lock and explicit control
|
/// output stream. Access is also synchronized via a lock and explicit control
|
||||||
/// over locking is available via the `lock` method.
|
/// over locking is available via the `lock` method.
|
||||||
|
///
|
||||||
|
/// Created by the function `io::stdout()`.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct Stdout {
|
pub struct Stdout {
|
||||||
// FIXME: this should be LineWriter or BufWriter depending on the state of
|
// FIXME: this should be LineWriter or BufWriter depending on the state of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user