Auto merge of #25303 - Manishearth:rollup, r=Manishearth
- Successful merges: #25280, #25284, #25286, #25287, #25290, #25291, #25297 - Failed merges:
This commit is contained in:
commit
f697041b37
@ -253,7 +253,7 @@ The two values of the boolean type are written `true` and `false`.
|
||||
### Symbols
|
||||
|
||||
```antlr
|
||||
symbol : "::" "->"
|
||||
symbol : "::" | "->"
|
||||
| '#' | '[' | ']' | '(' | ')' | '{' | '}'
|
||||
| ',' | ';' ;
|
||||
```
|
||||
@ -304,7 +304,7 @@ transcriber : '(' transcriber * ')' | '[' transcriber * ']'
|
||||
## Items
|
||||
|
||||
```antlr
|
||||
item : mod_item | fn_item | type_item | struct_item | enum_item
|
||||
item : vis ? mod_item | fn_item | type_item | struct_item | enum_item
|
||||
| const_item | static_item | trait_item | impl_item | extern_block ;
|
||||
```
|
||||
|
||||
@ -322,7 +322,7 @@ mod : [ view_item | item ] * ;
|
||||
#### View items
|
||||
|
||||
```antlr
|
||||
view_item : extern_crate_decl | use_decl ;
|
||||
view_item : extern_crate_decl | use_decl ';' ;
|
||||
```
|
||||
|
||||
##### Extern crate declarations
|
||||
@ -335,14 +335,14 @@ crate_name: ident | ( ident "as" ident )
|
||||
##### Use declarations
|
||||
|
||||
```antlr
|
||||
use_decl : "pub" ? "use" [ path "as" ident
|
||||
| path_glob ] ;
|
||||
use_decl : vis ? "use" [ path "as" ident
|
||||
| path_glob ] ;
|
||||
|
||||
path_glob : ident [ "::" [ path_glob
|
||||
| '*' ] ] ?
|
||||
| '{' path_item [ ',' path_item ] * '}' ;
|
||||
|
||||
path_item : ident | "mod" ;
|
||||
path_item : ident | "self" ;
|
||||
```
|
||||
|
||||
### Functions
|
||||
@ -414,16 +414,17 @@ extern_block : [ foreign_fn ] * ;
|
||||
|
||||
## Visibility and Privacy
|
||||
|
||||
**FIXME:** grammar?
|
||||
|
||||
```antlr
|
||||
vis : "pub" ;
|
||||
```
|
||||
### Re-exporting and Visibility
|
||||
|
||||
**FIXME:** grammar?
|
||||
See [Use declarations](#use-declarations).
|
||||
|
||||
## Attributes
|
||||
|
||||
```antlr
|
||||
attribute : "#!" ? '[' meta_item ']' ;
|
||||
attribute : '#' '!' ? '[' meta_item ']' ;
|
||||
meta_item : ident [ '=' literal
|
||||
| '(' meta_seq ')' ] ? ;
|
||||
meta_seq : meta_item [ ',' meta_seq ] ? ;
|
||||
@ -433,26 +434,19 @@ meta_seq : meta_item [ ',' meta_seq ] ? ;
|
||||
|
||||
## Statements
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
stmt : decl_stmt | expr_stmt ;
|
||||
```
|
||||
|
||||
### Declaration statements
|
||||
|
||||
**FIXME:** grammar?
|
||||
|
||||
A _declaration statement_ is one that introduces one or more *names* into the
|
||||
enclosing statement block. The declared names may denote new variables or new
|
||||
items.
|
||||
```antlr
|
||||
decl_stmt : item | let_decl ;
|
||||
```
|
||||
|
||||
#### Item declarations
|
||||
|
||||
**FIXME:** grammar?
|
||||
|
||||
An _item declaration statement_ has a syntactic form identical to an
|
||||
[item](#items) declaration within a module. Declaring an item — a
|
||||
function, enumeration, structure, type, static, trait, implementation or module
|
||||
— locally within a statement block is simply a way of restricting its
|
||||
scope to a narrow region containing all of its uses; it is otherwise identical
|
||||
in meaning to declaring the item outside the statement block.
|
||||
See [Items](#items).
|
||||
|
||||
#### Variable declarations
|
||||
|
||||
@ -463,11 +457,21 @@ init : [ '=' ] expr ;
|
||||
|
||||
### Expression statements
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
expr_stmt : expr ';' ;
|
||||
```
|
||||
|
||||
## Expressions
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
expr : literal | path | tuple_expr | unit_expr | struct_expr
|
||||
| block_expr | method_call_expr | field_expr | array_expr
|
||||
| idx_expr | range_expr | unop_expr | binop_expr
|
||||
| paren_expr | call_expr | lambda_expr | while_expr
|
||||
| loop_expr | break_expr | continue_expr | for_expr
|
||||
| if_expr | match_expr | if_let_expr | while_let_expr
|
||||
| return_expr ;
|
||||
```
|
||||
|
||||
#### Lvalues, rvalues and temporaries
|
||||
|
||||
@ -479,19 +483,23 @@ init : [ '=' ] expr ;
|
||||
|
||||
### Literal expressions
|
||||
|
||||
**FIXME:** grammar?
|
||||
See [Literals](#literals).
|
||||
|
||||
### Path expressions
|
||||
|
||||
**FIXME:** grammar?
|
||||
See [Paths](#paths).
|
||||
|
||||
### Tuple expressions
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
tuple_expr : '(' [ expr [ ',' expr ] * | expr ',' ] ? ')' ;
|
||||
```
|
||||
|
||||
### Unit expressions
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
unit_expr : "()" ;
|
||||
```
|
||||
|
||||
### Structure expressions
|
||||
|
||||
@ -507,8 +515,7 @@ struct_expr : expr_path '{' ident ':' expr
|
||||
### Block expressions
|
||||
|
||||
```antlr
|
||||
block_expr : '{' [ view_item ] *
|
||||
[ stmt ';' | item ] *
|
||||
block_expr : '{' [ stmt ';' | item ] *
|
||||
[ expr ] '}' ;
|
||||
```
|
||||
|
||||
@ -529,7 +536,7 @@ field_expr : expr '.' ident ;
|
||||
```antlr
|
||||
array_expr : '[' "mut" ? array_elems? ']' ;
|
||||
|
||||
array_elems : [expr [',' expr]*] | [expr ',' ".." expr] ;
|
||||
array_elems : [expr [',' expr]*] | [expr ';' expr] ;
|
||||
```
|
||||
|
||||
### Index expressions
|
||||
@ -549,66 +556,61 @@ range_expr : expr ".." expr |
|
||||
|
||||
### Unary operator expressions
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
unop_expr : unop expr ;
|
||||
unop : '-' | '*' | '!' ;
|
||||
```
|
||||
|
||||
### Binary operator expressions
|
||||
|
||||
```antlr
|
||||
binop_expr : expr binop expr ;
|
||||
binop_expr : expr binop expr | type_cast_expr
|
||||
| assignment_expr | compound_assignment_expr ;
|
||||
binop : arith_op | bitwise_op | lazy_bool_op | comp_op
|
||||
```
|
||||
|
||||
#### Arithmetic operators
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
arith_op : '+' | '-' | '*' | '/' | '%' ;
|
||||
```
|
||||
|
||||
#### Bitwise operators
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
bitwise_op : '&' | '|' | '^' | "<<" | ">>" ;
|
||||
```
|
||||
|
||||
#### Lazy boolean operators
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
lazy_bool_op : "&&" | "||" ;
|
||||
```
|
||||
|
||||
#### Comparison operators
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
comp_op : "==" | "!=" | '<' | '>' | "<=" | ">=" ;
|
||||
```
|
||||
|
||||
#### Type cast expressions
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
type_cast_expr : value "as" type ;
|
||||
```
|
||||
|
||||
#### Assignment expressions
|
||||
|
||||
**FIXME:** grammar?
|
||||
```antlr
|
||||
assignment_expr : expr '=' expr ;
|
||||
```
|
||||
|
||||
#### Compound assignment expressions
|
||||
|
||||
**FIXME:** grammar?
|
||||
|
||||
#### Operator precedence
|
||||
|
||||
The precedence of Rust binary operators is ordered as follows, going from
|
||||
strong to weak:
|
||||
|
||||
```text
|
||||
* / %
|
||||
as
|
||||
+ -
|
||||
<< >>
|
||||
&
|
||||
^
|
||||
|
|
||||
< > <= >=
|
||||
== !=
|
||||
&&
|
||||
||
|
||||
=
|
||||
```antlr
|
||||
compound_assignment_expr : expr [ arith_op | bitwise_op ] '=' expr ;
|
||||
```
|
||||
|
||||
Operators at the same precedence level are evaluated left-to-right. [Unary
|
||||
operators](#unary-operator-expressions) have the same precedence level and it
|
||||
is stronger than any of the binary operators'.
|
||||
|
||||
### Grouped expressions
|
||||
|
||||
```antlr
|
||||
|
@ -653,9 +653,10 @@ There are several kinds of item:
|
||||
* [`use` declarations](#use-declarations)
|
||||
* [modules](#modules)
|
||||
* [functions](#functions)
|
||||
* [type definitions](#type-definitions)
|
||||
* [type aliases](#type-aliases)
|
||||
* [structures](#structures)
|
||||
* [enumerations](#enumerations)
|
||||
* [constant items](#constant-items)
|
||||
* [static items](#static-items)
|
||||
* [traits](#traits)
|
||||
* [implementations](#implementations)
|
||||
@ -672,16 +673,16 @@ which sub-item declarations may appear.
|
||||
|
||||
### Type Parameters
|
||||
|
||||
All items except modules may be *parameterized* by type. Type parameters are
|
||||
given as a comma-separated list of identifiers enclosed in angle brackets
|
||||
(`<...>`), after the name of the item and before its definition. The type
|
||||
parameters of an item are considered "part of the name", not part of the type
|
||||
of the item. A referencing [path](#paths) must (in principle) provide type
|
||||
arguments as a list of comma-separated types enclosed within angle brackets, in
|
||||
order to refer to the type-parameterized item. In practice, the type-inference
|
||||
system can usually infer such argument types from context. There are no
|
||||
general type-parametric types, only type-parametric items. That is, Rust has
|
||||
no notion of type abstraction: there are no first-class "forall" types.
|
||||
All items except modules, constants and statics may be *parameterized* by type.
|
||||
Type parameters are given as a comma-separated list of identifiers enclosed in
|
||||
angle brackets (`<...>`), after the name of the item and before its definition.
|
||||
The type parameters of an item are considered "part of the name", not part of
|
||||
the type of the item. A referencing [path](#paths) must (in principle) provide
|
||||
type arguments as a list of comma-separated types enclosed within angle
|
||||
brackets, in order to refer to the type-parameterized item. In practice, the
|
||||
type-inference system can usually infer such argument types from context. There
|
||||
are no general type-parametric types, only type-parametric items. That is, Rust
|
||||
has no notion of type abstraction: there are no first-class "forall" types.
|
||||
|
||||
### Modules
|
||||
|
||||
@ -743,7 +744,7 @@ mod thread {
|
||||
}
|
||||
```
|
||||
|
||||
##### Extern crate declarations
|
||||
#### Extern crate declarations
|
||||
|
||||
An _`extern crate` declaration_ specifies a dependency on an external crate.
|
||||
The external crate is then bound into the declaring scope as the `ident`
|
||||
@ -767,7 +768,7 @@ extern crate std; // equivalent to: extern crate std as std;
|
||||
extern crate std as ruststd; // linking to 'std' under another name
|
||||
```
|
||||
|
||||
##### Use declarations
|
||||
#### Use declarations
|
||||
|
||||
A _use declaration_ creates one or more local name bindings synonymous with
|
||||
some other [path](#paths). Usually a `use` declaration is used to shorten the
|
||||
@ -842,7 +843,7 @@ module declarations should be at the crate root if direct usage of the declared
|
||||
modules within `use` items is desired. It is also possible to use `self` and
|
||||
`super` at the beginning of a `use` item to refer to the current and direct
|
||||
parent modules respectively. All rules regarding accessing declared modules in
|
||||
`use` declarations applies to both module declarations and `extern crate`
|
||||
`use` declarations apply to both module declarations and `extern crate`
|
||||
declarations.
|
||||
|
||||
An example of what will and will not work for `use` items:
|
||||
@ -2564,12 +2565,19 @@ array is mutable, the resulting [lvalue](#lvalues,-rvalues-and-temporaries) can
|
||||
be assigned to.
|
||||
|
||||
Indices are zero-based, and may be of any integral type. Vector access is
|
||||
bounds-checked at run-time. When the check fails, it will put the thread in a
|
||||
_panicked state_.
|
||||
bounds-checked at compile-time for constant arrays being accessed with a constant index value.
|
||||
Otherwise a check will be performed at run-time that will put the thread in a _panicked state_ if it fails.
|
||||
|
||||
```{should-fail}
|
||||
([1, 2, 3, 4])[0];
|
||||
(["a", "b"])[10]; // panics
|
||||
|
||||
let x = (["a", "b"])[10]; // compiler error: const index-expr is out of bounds
|
||||
|
||||
let n = 10;
|
||||
let y = (["a", "b"])[n]; // panics
|
||||
|
||||
let arr = ["a", "b"];
|
||||
arr[10]; // panics
|
||||
```
|
||||
|
||||
### Range expressions
|
||||
@ -3064,6 +3072,20 @@ of a condition expression it expects a refutable let statement. If the value of
|
||||
expression on the right hand side of the let statement matches the pattern, the corresponding
|
||||
block will execute, otherwise flow proceeds to the first `else` block that follows.
|
||||
|
||||
```
|
||||
let dish = ("Ham", "Eggs");
|
||||
|
||||
// this body will be skipped because the pattern is refuted
|
||||
if let ("Bacon", b) = dish {
|
||||
println!("Bacon is served with {}", b);
|
||||
}
|
||||
|
||||
// this body will execute
|
||||
if let ("Ham", b) = dish {
|
||||
println!("Ham is served with {}", b);
|
||||
}
|
||||
```
|
||||
|
||||
### While let loops
|
||||
|
||||
A `while let` loop is semantically identical to a `while` loop but in place of a
|
||||
|
@ -273,7 +273,7 @@ information’. Why throw it away? Well, for a basic program, we just want to
|
||||
print a generic error, as basically any issue means we can’t continue. The
|
||||
[`ok()` method][ok] returns a value which has another method defined on it:
|
||||
`expect()`. The [`expect()` method][expect] takes a value it’s called on, and
|
||||
if it isn’t a successful one, [`panic!`][panic]s with a message you passed you
|
||||
if it isn’t a successful one, [`panic!`][panic]s with a message you
|
||||
passed it. A `panic!` like this will cause our program to crash, displaying
|
||||
the message.
|
||||
|
||||
|
@ -6,7 +6,7 @@ become quite acquainted. Ownership is how Rust achieves its largest goal,
|
||||
memory safety. There are a few distinct concepts, each with its own
|
||||
chapter:
|
||||
|
||||
* [ownership][ownership], ownership, the key concept
|
||||
* [ownership][ownership], the key concept
|
||||
* borrowing, which you’re reading now
|
||||
* [lifetimes][lifetimes], an advanced concept of borrowing
|
||||
|
||||
@ -368,4 +368,4 @@ statement 1 at 3:14
|
||||
|
||||
println!("{}", y);
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -1002,7 +1002,7 @@ pub trait SliceConcatExt<T: ?Sized> {
|
||||
/// The resulting type after concatenation
|
||||
type Output;
|
||||
|
||||
/// Flattens a slice of `T` into a single value `U`.
|
||||
/// Flattens a slice of `T` into a single value `Self::Output`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -1012,7 +1012,8 @@ pub trait SliceConcatExt<T: ?Sized> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn concat(&self) -> Self::Output;
|
||||
|
||||
/// Flattens a slice of `T` into a single value `U`, placing a given separator between each.
|
||||
/// Flattens a slice of `T` into a single value `Self::Output`, placing a given separator
|
||||
/// between each.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -44,8 +44,11 @@ pub trait FromStr {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
type Err;
|
||||
|
||||
/// Parses a string `s` to return an optional value of this type. If the
|
||||
/// string is ill-formatted, the None is returned.
|
||||
/// Parses a string `s` to return a value of this type.
|
||||
///
|
||||
/// If parsing succeeds, return the value inside `Ok`, otherwise
|
||||
/// when the string is ill-formatted return an error specific to the
|
||||
/// inside `Err`. The error type is specific to implementation of the trait.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err>;
|
||||
}
|
||||
|
@ -844,7 +844,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
/// An iterator over the contents of an instance of `BufRead` split on a
|
||||
/// particular byte.
|
||||
///
|
||||
/// See `BufReadExt::split` for more information.
|
||||
/// See `BufRead::split` for more information.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Split<B> {
|
||||
buf: B,
|
||||
@ -873,7 +873,7 @@ fn next(&mut self) -> Option<Result<Vec<u8>>> {
|
||||
/// An iterator over the lines of an instance of `BufRead` split on a newline
|
||||
/// byte.
|
||||
///
|
||||
/// See `BufReadExt::lines` for more information.
|
||||
/// See `BufRead::lines` for more information.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Lines<B> {
|
||||
buf: B,
|
||||
|
@ -1449,6 +1449,8 @@ pub fn relative_from<'a, P: ?Sized + AsRef<Path>>(&'a self, base: &'a P) -> Opti
|
||||
|
||||
/// Determines whether `base` is a prefix of `self`.
|
||||
///
|
||||
/// Only considers whole path components to match.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -1457,6 +1459,8 @@ pub fn relative_from<'a, P: ?Sized + AsRef<Path>>(&'a self, base: &'a P) -> Opti
|
||||
/// let path = Path::new("/etc/passwd");
|
||||
///
|
||||
/// assert!(path.starts_with("/etc"));
|
||||
///
|
||||
/// assert!(!path.starts_with("/e"));
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool {
|
||||
@ -1465,6 +1469,8 @@ pub fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool {
|
||||
|
||||
/// Determines whether `child` is a suffix of `self`.
|
||||
///
|
||||
/// Only considers whole path components to match.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
@ -85,6 +85,8 @@ pub struct LocalKey<T> {
|
||||
}
|
||||
|
||||
/// Declare a new thread local storage key of type `std::thread::LocalKey`.
|
||||
///
|
||||
/// See [LocalKey documentation](thread/struct.LocalKey.html) for more information.
|
||||
#[macro_export]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow_internal_unstable]
|
||||
|
@ -66,6 +66,8 @@ pub struct ScopedKey<T> { #[doc(hidden)] pub inner: __impl::KeyInner<T> }
|
||||
///
|
||||
/// This macro declares a `static` item on which methods are used to get and
|
||||
/// set the value stored within.
|
||||
///
|
||||
/// See [ScopedKey documentation](thread/struct.ScopedKey.html) for more information.
|
||||
#[macro_export]
|
||||
#[allow_internal_unstable]
|
||||
macro_rules! scoped_thread_local {
|
||||
|
Loading…
Reference in New Issue
Block a user