Skip to content

Commit f697041

Browse files
committed
Auto merge of #25303 - Manishearth:rollup, r=Manishearth
- Successful merges: #25280, #25284, #25286, #25287, #25290, #25291, #25297 - Failed merges:
2 parents 8004fc9 + 2b0191e commit f697041

File tree

10 files changed

+130
-92
lines changed

10 files changed

+130
-92
lines changed

src/doc/grammar.md

+68-66
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ The two values of the boolean type are written `true` and `false`.
253253
### Symbols
254254

255255
```antlr
256-
symbol : "::" "->"
256+
symbol : "::" | "->"
257257
| '#' | '[' | ']' | '(' | ')' | '{' | '}'
258258
| ',' | ';' ;
259259
```
@@ -304,7 +304,7 @@ transcriber : '(' transcriber * ')' | '[' transcriber * ']'
304304
## Items
305305

306306
```antlr
307-
item : mod_item | fn_item | type_item | struct_item | enum_item
307+
item : vis ? mod_item | fn_item | type_item | struct_item | enum_item
308308
| const_item | static_item | trait_item | impl_item | extern_block ;
309309
```
310310

@@ -322,7 +322,7 @@ mod : [ view_item | item ] * ;
322322
#### View items
323323

324324
```antlr
325-
view_item : extern_crate_decl | use_decl ;
325+
view_item : extern_crate_decl | use_decl ';' ;
326326
```
327327

328328
##### Extern crate declarations
@@ -335,14 +335,14 @@ crate_name: ident | ( ident "as" ident )
335335
##### Use declarations
336336

337337
```antlr
338-
use_decl : "pub" ? "use" [ path "as" ident
339-
| path_glob ] ;
338+
use_decl : vis ? "use" [ path "as" ident
339+
| path_glob ] ;
340340
341341
path_glob : ident [ "::" [ path_glob
342342
| '*' ] ] ?
343343
| '{' path_item [ ',' path_item ] * '}' ;
344344
345-
path_item : ident | "mod" ;
345+
path_item : ident | "self" ;
346346
```
347347

348348
### Functions
@@ -414,16 +414,17 @@ extern_block : [ foreign_fn ] * ;
414414

415415
## Visibility and Privacy
416416

417-
**FIXME:** grammar?
418-
417+
```antlr
418+
vis : "pub" ;
419+
```
419420
### Re-exporting and Visibility
420421

421-
**FIXME:** grammar?
422+
See [Use declarations](#use-declarations).
422423

423424
## Attributes
424425

425426
```antlr
426-
attribute : "#!" ? '[' meta_item ']' ;
427+
attribute : '#' '!' ? '[' meta_item ']' ;
427428
meta_item : ident [ '=' literal
428429
| '(' meta_seq ')' ] ? ;
429430
meta_seq : meta_item [ ',' meta_seq ] ? ;
@@ -433,26 +434,19 @@ meta_seq : meta_item [ ',' meta_seq ] ? ;
433434

434435
## Statements
435436

436-
**FIXME:** grammar?
437+
```antlr
438+
stmt : decl_stmt | expr_stmt ;
439+
```
437440

438441
### Declaration statements
439442

440-
**FIXME:** grammar?
441-
442-
A _declaration statement_ is one that introduces one or more *names* into the
443-
enclosing statement block. The declared names may denote new variables or new
444-
items.
443+
```antlr
444+
decl_stmt : item | let_decl ;
445+
```
445446

446447
#### Item declarations
447448

448-
**FIXME:** grammar?
449-
450-
An _item declaration statement_ has a syntactic form identical to an
451-
[item](#items) declaration within a module. Declaring an item — a
452-
function, enumeration, structure, type, static, trait, implementation or module
453-
— locally within a statement block is simply a way of restricting its
454-
scope to a narrow region containing all of its uses; it is otherwise identical
455-
in meaning to declaring the item outside the statement block.
449+
See [Items](#items).
456450

457451
#### Variable declarations
458452

@@ -463,11 +457,21 @@ init : [ '=' ] expr ;
463457

464458
### Expression statements
465459

466-
**FIXME:** grammar?
460+
```antlr
461+
expr_stmt : expr ';' ;
462+
```
467463

468464
## Expressions
469465

470-
**FIXME:** grammar?
466+
```antlr
467+
expr : literal | path | tuple_expr | unit_expr | struct_expr
468+
| block_expr | method_call_expr | field_expr | array_expr
469+
| idx_expr | range_expr | unop_expr | binop_expr
470+
| paren_expr | call_expr | lambda_expr | while_expr
471+
| loop_expr | break_expr | continue_expr | for_expr
472+
| if_expr | match_expr | if_let_expr | while_let_expr
473+
| return_expr ;
474+
```
471475

472476
#### Lvalues, rvalues and temporaries
473477

@@ -479,19 +483,23 @@ init : [ '=' ] expr ;
479483

480484
### Literal expressions
481485

482-
**FIXME:** grammar?
486+
See [Literals](#literals).
483487

484488
### Path expressions
485489

486-
**FIXME:** grammar?
490+
See [Paths](#paths).
487491

488492
### Tuple expressions
489493

490-
**FIXME:** grammar?
494+
```antlr
495+
tuple_expr : '(' [ expr [ ',' expr ] * | expr ',' ] ? ')' ;
496+
```
491497

492498
### Unit expressions
493499

494-
**FIXME:** grammar?
500+
```antlr
501+
unit_expr : "()" ;
502+
```
495503

496504
### Structure expressions
497505

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

509517
```antlr
510-
block_expr : '{' [ view_item ] *
511-
[ stmt ';' | item ] *
518+
block_expr : '{' [ stmt ';' | item ] *
512519
[ expr ] '}' ;
513520
```
514521

@@ -529,7 +536,7 @@ field_expr : expr '.' ident ;
529536
```antlr
530537
array_expr : '[' "mut" ? array_elems? ']' ;
531538
532-
array_elems : [expr [',' expr]*] | [expr ',' ".." expr] ;
539+
array_elems : [expr [',' expr]*] | [expr ';' expr] ;
533540
```
534541

535542
### Index expressions
@@ -549,65 +556,60 @@ range_expr : expr ".." expr |
549556

550557
### Unary operator expressions
551558

552-
**FIXME:** grammar?
559+
```antlr
560+
unop_expr : unop expr ;
561+
unop : '-' | '*' | '!' ;
562+
```
553563

554564
### Binary operator expressions
555565

556566
```antlr
557-
binop_expr : expr binop expr ;
567+
binop_expr : expr binop expr | type_cast_expr
568+
| assignment_expr | compound_assignment_expr ;
569+
binop : arith_op | bitwise_op | lazy_bool_op | comp_op
558570
```
559571

560572
#### Arithmetic operators
561573

562-
**FIXME:** grammar?
574+
```antlr
575+
arith_op : '+' | '-' | '*' | '/' | '%' ;
576+
```
563577

564578
#### Bitwise operators
565579

566-
**FIXME:** grammar?
580+
```antlr
581+
bitwise_op : '&' | '|' | '^' | "<<" | ">>" ;
582+
```
567583

568584
#### Lazy boolean operators
569585

570-
**FIXME:** grammar?
586+
```antlr
587+
lazy_bool_op : "&&" | "||" ;
588+
```
571589

572590
#### Comparison operators
573591

574-
**FIXME:** grammar?
592+
```antlr
593+
comp_op : "==" | "!=" | '<' | '>' | "<=" | ">=" ;
594+
```
575595

576596
#### Type cast expressions
577597

578-
**FIXME:** grammar?
598+
```antlr
599+
type_cast_expr : value "as" type ;
600+
```
579601

580602
#### Assignment expressions
581603

582-
**FIXME:** grammar?
604+
```antlr
605+
assignment_expr : expr '=' expr ;
606+
```
583607

584608
#### Compound assignment expressions
585609

586-
**FIXME:** grammar?
587-
588-
#### Operator precedence
589-
590-
The precedence of Rust binary operators is ordered as follows, going from
591-
strong to weak:
592-
593-
```text
594-
* / %
595-
as
596-
+ -
597-
<< >>
598-
&
599-
^
600-
|
601-
< > <= >=
602-
== !=
603-
&&
604-
||
605-
=
606-
```
607-
608-
Operators at the same precedence level are evaluated left-to-right. [Unary
609-
operators](#unary-operator-expressions) have the same precedence level and it
610-
is stronger than any of the binary operators'.
610+
```antlr
611+
compound_assignment_expr : expr [ arith_op | bitwise_op ] '=' expr ;
612+
```
611613

612614
### Grouped expressions
613615

src/doc/reference.md

+39-17
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,10 @@ There are several kinds of item:
653653
* [`use` declarations](#use-declarations)
654654
* [modules](#modules)
655655
* [functions](#functions)
656-
* [type definitions](#type-definitions)
656+
* [type aliases](#type-aliases)
657657
* [structures](#structures)
658658
* [enumerations](#enumerations)
659+
* [constant items](#constant-items)
659660
* [static items](#static-items)
660661
* [traits](#traits)
661662
* [implementations](#implementations)
@@ -672,16 +673,16 @@ which sub-item declarations may appear.
672673

673674
### Type Parameters
674675

675-
All items except modules may be *parameterized* by type. Type parameters are
676-
given as a comma-separated list of identifiers enclosed in angle brackets
677-
(`<...>`), after the name of the item and before its definition. The type
678-
parameters of an item are considered "part of the name", not part of the type
679-
of the item. A referencing [path](#paths) must (in principle) provide type
680-
arguments as a list of comma-separated types enclosed within angle brackets, in
681-
order to refer to the type-parameterized item. In practice, the type-inference
682-
system can usually infer such argument types from context. There are no
683-
general type-parametric types, only type-parametric items. That is, Rust has
684-
no notion of type abstraction: there are no first-class "forall" types.
676+
All items except modules, constants and statics may be *parameterized* by type.
677+
Type parameters are given as a comma-separated list of identifiers enclosed in
678+
angle brackets (`<...>`), after the name of the item and before its definition.
679+
The type parameters of an item are considered "part of the name", not part of
680+
the type of the item. A referencing [path](#paths) must (in principle) provide
681+
type arguments as a list of comma-separated types enclosed within angle
682+
brackets, in order to refer to the type-parameterized item. In practice, the
683+
type-inference system can usually infer such argument types from context. There
684+
are no general type-parametric types, only type-parametric items. That is, Rust
685+
has no notion of type abstraction: there are no first-class "forall" types.
685686

686687
### Modules
687688

@@ -743,7 +744,7 @@ mod thread {
743744
}
744745
```
745746

746-
##### Extern crate declarations
747+
#### Extern crate declarations
747748

748749
An _`extern crate` declaration_ specifies a dependency on an external crate.
749750
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;
767768
extern crate std as ruststd; // linking to 'std' under another name
768769
```
769770

770-
##### Use declarations
771+
#### Use declarations
771772

772773
A _use declaration_ creates one or more local name bindings synonymous with
773774
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
842843
modules within `use` items is desired. It is also possible to use `self` and
843844
`super` at the beginning of a `use` item to refer to the current and direct
844845
parent modules respectively. All rules regarding accessing declared modules in
845-
`use` declarations applies to both module declarations and `extern crate`
846+
`use` declarations apply to both module declarations and `extern crate`
846847
declarations.
847848

848849
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
25642565
be assigned to.
25652566

25662567
Indices are zero-based, and may be of any integral type. Vector access is
2567-
bounds-checked at run-time. When the check fails, it will put the thread in a
2568-
_panicked state_.
2568+
bounds-checked at compile-time for constant arrays being accessed with a constant index value.
2569+
Otherwise a check will be performed at run-time that will put the thread in a _panicked state_ if it fails.
25692570

25702571
```{should-fail}
25712572
([1, 2, 3, 4])[0];
2572-
(["a", "b"])[10]; // panics
2573+
2574+
let x = (["a", "b"])[10]; // compiler error: const index-expr is out of bounds
2575+
2576+
let n = 10;
2577+
let y = (["a", "b"])[n]; // panics
2578+
2579+
let arr = ["a", "b"];
2580+
arr[10]; // panics
25732581
```
25742582

25752583
### Range expressions
@@ -3064,6 +3072,20 @@ of a condition expression it expects a refutable let statement. If the value of
30643072
expression on the right hand side of the let statement matches the pattern, the corresponding
30653073
block will execute, otherwise flow proceeds to the first `else` block that follows.
30663074

3075+
```
3076+
let dish = ("Ham", "Eggs");
3077+
3078+
// this body will be skipped because the pattern is refuted
3079+
if let ("Bacon", b) = dish {
3080+
println!("Bacon is served with {}", b);
3081+
}
3082+
3083+
// this body will execute
3084+
if let ("Ham", b) = dish {
3085+
println!("Ham is served with {}", b);
3086+
}
3087+
```
3088+
30673089
### While let loops
30683090

30693091
A `while let` loop is semantically identical to a `while` loop but in place of a

src/doc/trpl/guessing-game.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ information’. Why throw it away? Well, for a basic program, we just want to
273273
print a generic error, as basically any issue means we can’t continue. The
274274
[`ok()` method][ok] returns a value which has another method defined on it:
275275
`expect()`. The [`expect()` method][expect] takes a value it’s called on, and
276-
if it isn’t a successful one, [`panic!`][panic]s with a message you passed you
276+
if it isn’t a successful one, [`panic!`][panic]s with a message you
277277
passed it. A `panic!` like this will cause our program to crash, displaying
278278
the message.
279279

0 commit comments

Comments
 (0)