Skip to content

Rollup of 7 pull requests #25303

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 25 commits into from
May 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
685f557
Update docs to stop referencing `BufReadExt`
frewsxcv May 10, 2015
6d41013
Fix typo in guessing-game docs
petehunt May 10, 2015
a168a15
Fix typo in references-and-borrowing docs
petehunt May 10, 2015
295b62d
Docs: Compile-time bounds check in index expression
May 10, 2015
770f0e9
Add if let expressions example
May 11, 2015
6a19046
Four spaces indent, rephrasing
May 11, 2015
4e8afd6
docs: Update FromStr documentation
May 10, 2015
02b8e4e
docs: Clarify Path::starts_with (and ends_with)
May 10, 2015
098040f
docs: Link from tls macros to relevant docs
May 10, 2015
12d50b2
docs: Fixes in Reference Chapter 6.1
May 10, 2015
aabdd8e
docs: Update SliceConcatExt docs for assoc types
May 11, 2015
c9c8ff1
Add visibility section of the grammar
carols10cents May 6, 2015
a5c651c
Point to the use declaration section from the re-exporting section
carols10cents May 6, 2015
ab913c8
Fill in grammar for Statements
carols10cents May 6, 2015
e607d76
Fill in more parts of the grammar for Expressions
carols10cents May 6, 2015
c3156a8
Remove operator precedence section covered in the reference
carols10cents May 6, 2015
53cd0bc
Add literal semicolon to the grammar of view_item
carols10cents May 11, 2015
218d38f
Overwrite grammar sections with what was removed from the reference
carols10cents May 11, 2015
c891375
Rollup merge of #25280 - frewsxcv:patch-22, r=steveklabnik
Manishearth May 11, 2015
b0b6db6
Rollup merge of #25284 - petehunt:patch-1, r=steveklabnik
Manishearth May 11, 2015
1b8f52b
Rollup merge of #25286 - johannhof:patch-1, r=steveklabnik
Manishearth May 11, 2015
8f01d8d
Rollup merge of #25287 - petehunt:patch-2, r=steveklabnik
Manishearth May 11, 2015
f2c2736
Rollup merge of #25290 - bluss:docfixes, r=steveklabnik
Manishearth May 11, 2015
dec4225
Rollup merge of #25291 - johannhof:let-expressions-example, r=stevekl…
Manishearth May 11, 2015
2b0191e
Rollup merge of #25297 - carols10cents:grammar-todos, r=steveklabnik
Manishearth May 11, 2015
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
134 changes: 68 additions & 66 deletions src/doc/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ The two values of the boolean type are written `true` and `false`.
### Symbols

```antlr
symbol : "::" "->"
symbol : "::" | "->"
| '#' | '[' | ']' | '(' | ')' | '{' | '}'
| ',' | ';' ;
```
Expand Down Expand Up @@ -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 ;
```

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ] ? ;
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -507,8 +515,7 @@ struct_expr : expr_path '{' ident ':' expr
### Block expressions

```antlr
block_expr : '{' [ view_item ] *
[ stmt ';' | item ] *
block_expr : '{' [ stmt ';' | item ] *
[ expr ] '}' ;
```

Expand All @@ -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
Expand All @@ -549,65 +556,60 @@ 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
+ -
<< >>
&
^
|
< > <= >=
== !=
&&
||
=
```

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'.
```antlr
compound_assignment_expr : expr [ arith_op | bitwise_op ] '=' expr ;
```

### Grouped expressions

Expand Down
56 changes: 39 additions & 17 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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`
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/guessing-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading