From 685f557729e3bb2691a81ac10074bddf4f61a0b6 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 10 May 2015 16:32:18 -0400 Subject: [PATCH 01/18] Update docs to stop referencing `BufReadExt` --- src/libstd/io/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 9089b417fcb..e7b2b01d09f 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -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 { buf: B, @@ -873,7 +873,7 @@ fn next(&mut self) -> Option>> { /// 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 { buf: B, From 6d410132dcbe7a83f3276b6eac4c0baa0f6a3930 Mon Sep 17 00:00:00 2001 From: Pete Hunt Date: Sun, 10 May 2015 15:11:40 -0700 Subject: [PATCH 02/18] Fix typo in guessing-game docs --- src/doc/trpl/guessing-game.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 50767b603c4..86158e716d2 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -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. From a168a15008e5a5ac50a3914e8d15c6ee8fbc92ce Mon Sep 17 00:00:00 2001 From: Pete Hunt Date: Sun, 10 May 2015 16:10:02 -0700 Subject: [PATCH 03/18] Fix typo in references-and-borrowing docs --- src/doc/trpl/references-and-borrowing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index da416e994c4..c434371ce59 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -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); } -``` \ No newline at end of file +``` From 295b62dfb9ae53cb14518664ddaaf71348b20f18 Mon Sep 17 00:00:00 2001 From: Johann Hofmann Date: Mon, 11 May 2015 00:53:24 +0200 Subject: [PATCH 04/18] Docs: Compile-time bounds check in index expression The reference was claiming all vectors all bounds-checked at run-time, when constant vectors are usually checked at compile-time. For the changed example see http://is.gd/28ak9E --- src/doc/reference.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 16fdcfa3013..fe5a6d9be49 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -842,7 +842,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 +2564,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 From 770f0e95a189e84491845ab1378eb3bc3c896f62 Mon Sep 17 00:00:00 2001 From: Johann Hofmann Date: Mon, 11 May 2015 02:03:37 +0200 Subject: [PATCH 05/18] Add if let expressions example --- src/doc/reference.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/doc/reference.md b/src/doc/reference.md index 16fdcfa3013..89f74d8d87a 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3064,6 +3064,17 @@ 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"); +if let ("Bacon", b) = dish { // will not execute because let is refuted + println!("Bacon is served with {}", b); +} + +if let ("Ham", b) = dish { // will execute + 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 From 6a19046423b49672bc71eb07149ae9ef32bc8af5 Mon Sep 17 00:00:00 2001 From: Johann Date: Mon, 11 May 2015 02:40:02 +0200 Subject: [PATCH 06/18] Four spaces indent, rephrasing --- src/doc/reference.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 89f74d8d87a..e6afa695b2c 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3066,12 +3066,15 @@ block will execute, otherwise flow proceeds to the first `else` block that follo ``` let dish = ("Ham", "Eggs"); -if let ("Bacon", b) = dish { // will not execute because let is refuted - println!("Bacon is served with {}", b); + +// this body will be skipped because the pattern is refuted +if let ("Bacon", b) = dish { + println!("Bacon is served with {}", b); } -if let ("Ham", b) = dish { // will execute - println!("Ham is served with {}", b); +// this body will execute +if let ("Ham", b) = dish { + println!("Ham is served with {}", b); } ``` From 4e8afd65f93f1c351365c71f4461a2c6728f8287 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Mon, 11 May 2015 00:22:04 +0200 Subject: [PATCH 07/18] docs: Update FromStr documentation Fixes #25250 --- src/libcore/str/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 4d39607b16e..11ca6e332b5 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -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; } From 02b8e4e6cf6f3fc3a7d31f348fc82bafa0165e3a Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Mon, 11 May 2015 00:29:50 +0200 Subject: [PATCH 08/18] docs: Clarify Path::starts_with (and ends_with) Fixes #24882 --- src/libstd/path.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 8ccc387c902..21f873e6877 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1449,6 +1449,8 @@ pub fn relative_from<'a, P: ?Sized + AsRef>(&'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>(&'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>(&self, base: P) -> bool { @@ -1465,6 +1469,8 @@ pub fn starts_with>(&self, base: P) -> bool { /// Determines whether `child` is a suffix of `self`. /// + /// Only considers whole path components to match. + /// /// # Examples /// /// ``` From 098040f8fc8a0928bec25382066b5318c63e2a31 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Mon, 11 May 2015 00:38:47 +0200 Subject: [PATCH 09/18] docs: Link from tls macros to relevant docs Fixes #25233 --- src/libstd/thread/local.rs | 2 ++ src/libstd/thread/scoped_tls.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 41bdf034705..2e043c58a5d 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -85,6 +85,8 @@ pub struct LocalKey { } /// 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] diff --git a/src/libstd/thread/scoped_tls.rs b/src/libstd/thread/scoped_tls.rs index 35684a1f390..e195c3aaa3f 100644 --- a/src/libstd/thread/scoped_tls.rs +++ b/src/libstd/thread/scoped_tls.rs @@ -66,6 +66,8 @@ pub struct ScopedKey { #[doc(hidden)] pub inner: __impl::KeyInner } /// /// 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 { From 12d50b2da02166582326833efa6ba59e55cd18cf Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Mon, 11 May 2015 01:25:10 +0200 Subject: [PATCH 10/18] docs: Fixes in Reference Chapter 6.1 --- src/doc/reference.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 16fdcfa3013..0c70f442231 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -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 From aabdd8e0a607643915020c072923fdf135358921 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Mon, 11 May 2015 02:01:27 +0200 Subject: [PATCH 11/18] docs: Update SliceConcatExt docs for assoc types --- src/libcollections/slice.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index b9e9800f7a0..d5a069b194a 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1002,7 +1002,7 @@ pub trait SliceConcatExt { /// 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 { #[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 /// From c9c8ff1762b6761b738380ba57c939d515eab50c Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Tue, 5 May 2015 20:52:34 -0400 Subject: [PATCH 12/18] Add visibility section of the grammar Namely an optional "pub" before any item. The "pub" in the Use declaration section should use this too. --- src/doc/grammar.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 4897b27dec3..e14300dcd5d 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -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 ; ``` @@ -335,8 +335,8 @@ 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 | '*' ] ] ? @@ -414,8 +414,9 @@ extern_block : [ foreign_fn ] * ; ## Visibility and Privacy -**FIXME:** grammar? - +```antlr +vis : "pub" ; +``` ### Re-exporting and Visibility **FIXME:** grammar? From a5c651cfdfe78d464653d63cc5b6496f50c2fab0 Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Tue, 5 May 2015 21:06:17 -0400 Subject: [PATCH 13/18] Point to the use declaration section from the re-exporting section The syntax for re-exporting privacy is covered in the use declaration item. --- src/doc/grammar.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index e14300dcd5d..6a2ad874513 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -419,7 +419,7 @@ vis : "pub" ; ``` ### Re-exporting and Visibility -**FIXME:** grammar? +See [Use declarations](#use-declarations). ## Attributes From ab913c881cfd559591fcde3ca1c82c784c5aab87 Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Tue, 5 May 2015 21:52:21 -0400 Subject: [PATCH 14/18] Fill in grammar for Statements Some of this text is duplicated in the reference (and belongs there) so remove it. It says item grammar is the same, so point to that grammar section. --- src/doc/grammar.md | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 6a2ad874513..e606b282f5c 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -434,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 @@ -464,7 +457,9 @@ init : [ '=' ] expr ; ### Expression statements -**FIXME:** grammar? +```antlr +expr_stmt : expr ';' ; +``` ## Expressions From e607d76564cf01247b247e0e83c7abdc4bb1fbee Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Tue, 5 May 2015 22:32:20 -0400 Subject: [PATCH 15/18] Fill in more parts of the grammar for Expressions --- src/doc/grammar.md | 59 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index e606b282f5c..a752ce47b1b 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -463,7 +463,15 @@ 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 @@ -475,19 +483,23 @@ expr_stmt : 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 @@ -545,41 +557,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? +```antlr +compound_assignment_expr : expr [ arith_op | bitwise_op ] '=' expr ; +``` #### Operator precedence From c3156a8ff434060403a1743cff780d8e80a53db2 Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Tue, 5 May 2015 22:32:38 -0400 Subject: [PATCH 16/18] Remove operator precedence section covered in the reference --- src/doc/grammar.md | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index a752ce47b1b..3cecc28b803 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -612,30 +612,6 @@ assignment_expr : expr '=' expr ; compound_assignment_expr : expr [ arith_op | bitwise_op ] '=' expr ; ``` -#### 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'. - ### Grouped expressions ```antlr From 53cd0bc772c5b73d8059a02f828ceecf9ed2287c Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Sun, 10 May 2015 20:48:02 -0400 Subject: [PATCH 17/18] Add literal semicolon to the grammar of view_item Both external crate declarations and use declarations need to end with a semicolon. --- src/doc/grammar.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 3cecc28b803..a3325b82a9d 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -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 From 218d38fb94379feca89eb858b309890d513c35da Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Sun, 10 May 2015 22:17:33 -0400 Subject: [PATCH 18/18] Overwrite grammar sections with what was removed from the reference Between ffc5f1c, when grammar.md was created by copying parts of the reference, and 8cf2552, when all EBNF was removed from reference.md, there were parts of the grammar that were updated in reference.md but not grammar.md, and then they weren't copied over because they existed already, but they were slightly out of date. Example: the `path_item : ident | "self" ;` rule in Use declarations was changed from "mod" to "self" in the reference in 195fd9a but wasn't updated in the grammar. --- src/doc/grammar.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index a3325b82a9d..fb7562e7bdf 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -253,7 +253,7 @@ The two values of the boolean type are written `true` and `false`. ### Symbols ```antlr -symbol : "::" "->" +symbol : "::" | "->" | '#' | '[' | ']' | '(' | ')' | '{' | '}' | ',' | ';' ; ``` @@ -342,7 +342,7 @@ path_glob : ident [ "::" [ path_glob | '*' ] ] ? | '{' path_item [ ',' path_item ] * '}' ; -path_item : ident | "mod" ; +path_item : ident | "self" ; ``` ### Functions @@ -424,7 +424,7 @@ 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 ] ? ; @@ -515,8 +515,7 @@ struct_expr : expr_path '{' ident ':' expr ### Block expressions ```antlr -block_expr : '{' [ view_item ] * - [ stmt ';' | item ] * +block_expr : '{' [ stmt ';' | item ] * [ expr ] '}' ; ``` @@ -537,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