Skip to content

Commit dc5524e

Browse files
committed
---
yaml --- r: 210874 b: refs/heads/try c: 5e535ea h: refs/heads/master v: v3
1 parent d46d760 commit dc5524e

17 files changed

+217
-55
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: fa28642de9fc158613f294896e62e12c3067714e
5+
refs/heads/try: 5e535eae5c4b70879aefc050a5fe0b8137c07eac
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/mk/main.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
######################################################################
1414

1515
# The version number
16-
CFG_RELEASE_NUM=1.1.0
16+
CFG_RELEASE_NUM=1.2.0
1717

1818
# An optional number to put after the label, e.g. '.2' -> '-beta.2'
1919
# NB Make sure it starts with a dot to conform to semver pre-release

branches/try/src/doc/complement-design-faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ feature.
7979
A nice replacement is the [lazy constructor macro][lcm] by [Marvin
8080
Löbel][kim].
8181

82-
[fqa]: https://mail.mozilla.org/pipermail/rust-dev/2013-April/003815.html
82+
[fqa]: http://yosefk.com/c++fqa/ctors.html#fqa-10.12
8383
[elp]: http://ericlippert.com/2013/02/06/static-constructors-part-one/
8484
[lcm]: https://gist.github.com/Kimundi/8782487
8585
[kim]: https://github.com/Kimundi

branches/try/src/doc/trpl/const-and-static.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ static N: i32 = 5;
3131

3232
Unlike [`let`][let] bindings, you must annotate the type of a `static`.
3333

34-
[let]: variable-bindings.html
35-
3634
Statics live for the entire lifetime of a program, and therefore any
37-
reference stored in a constant has a [`static` lifetime][lifetimes]:
35+
reference stored in a constant has a [`'static` lifetime][lifetimes]:
3836

3937
```rust
4038
static NAME: &'static str = "Steve";

branches/try/src/doc/trpl/method-syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn main() {
156156

157157
This ‘associated function’ builds a new `Circle` for us. Note that associated
158158
functions are called with the `Struct::function()` syntax, rather than the
159-
`ref.method()` syntax. Some other langauges call associated functions ‘static
159+
`ref.method()` syntax. Some other languages call associated functions ‘static
160160
methods’.
161161

162162
# Builder Pattern

branches/try/src/doc/trpl/nightly-rust.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ $ sh rustup.sh --channel=nightly
2626
If you're on Windows, please download either the [32-bit installer][win32] or
2727
the [64-bit installer][win64] and run it.
2828

29-
[win32]: https://static.rust-lang.org/dist/rust-1.0.0-beta-i686-pc-windows-gnu.msi
30-
[win64]: https://static.rust-lang.org/dist/rust-1.0.0-beta-x86_64-pc-windows-gnu.msi
29+
[win32]: https://static.rust-lang.org/dist/rust-nightly-i686-pc-windows-gnu.msi
30+
[win64]: https://static.rust-lang.org/dist/rust-nightly-x86_64-pc-windows-gnu.msi
3131

3232
## Uninstalling
3333

branches/try/src/doc/trpl/traits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ let result = f.write("whatever".as_bytes());
208208

209209
This will compile without error.
210210

211-
This means that even if someone does something bad like add methods to `int`,
211+
This means that even if someone does something bad like add methods to `i32`,
212212
it won’t affect you, unless you `use` that trait.
213213

214214
There’s one more restriction on implementing traits. Either the trait or the

branches/try/src/libstd/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
//! [`FromStr`](str/trait.FromStr.html) trait.
6161
//!
6262
//! Data may be shared by placing it in a reference-counted box or the
63-
//! [`Rc`][rc/index.html] type, and if further contained in a [`Cell`
63+
//! [`Rc`](rc/index.html) type, and if further contained in a [`Cell`
6464
//! or `RefCell`](cell/index.html), may be mutated as well as shared.
6565
//! Likewise, in a concurrent setting it is common to pair an
6666
//! atomically-reference-counted box, [`Arc`](sync/struct.Arc.html),

branches/try/src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 78 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -325,42 +325,55 @@ fn check_matcher<'a, I>(cx: &mut ExtCtxt, matcher: I, follow: &Token)
325325
last = match *token {
326326
TtToken(sp, MatchNt(ref name, ref frag_spec, _, _)) => {
327327
// ii. If T is a simple NT, look ahead to the next token T' in
328-
// M.
329-
let next_token = match tokens.peek() {
330-
// If T' closes a complex NT, replace T' with F
331-
Some(&&TtToken(_, CloseDelim(_))) => follow.clone(),
332-
Some(&&TtToken(_, ref tok)) => tok.clone(),
333-
Some(&&TtSequence(sp, _)) => {
334-
cx.span_err(sp,
335-
&format!("`${0}:{1}` is followed by a \
336-
sequence repetition, which is not \
337-
allowed for `{1}` fragments",
338-
name.as_str(), frag_spec.as_str())
328+
// M. If T' is in the set FOLLOW(NT), continue. Else; reject.
329+
if can_be_followed_by_any(frag_spec.as_str()) {
330+
continue
331+
} else {
332+
let next_token = match tokens.peek() {
333+
// If T' closes a complex NT, replace T' with F
334+
Some(&&TtToken(_, CloseDelim(_))) => follow.clone(),
335+
Some(&&TtToken(_, ref tok)) => tok.clone(),
336+
Some(&&TtSequence(sp, _)) => {
337+
// Be conservative around sequences: to be
338+
// more specific, we would need to
339+
// consider FIRST sets, but also the
340+
// possibility that the sequence occurred
341+
// zero times (in which case we need to
342+
// look at the token that follows the
343+
// sequence, which may itself a sequence,
344+
// and so on).
345+
cx.span_err(sp,
346+
&format!("`${0}:{1}` is followed by a \
347+
sequence repetition, which is not \
348+
allowed for `{1}` fragments",
349+
name.as_str(), frag_spec.as_str())
339350
);
340-
Eof
341-
},
342-
// die next iteration
343-
Some(&&TtDelimited(_, ref delim)) => delim.close_token(),
344-
// else, we're at the end of the macro or sequence
345-
None => follow.clone()
346-
};
347-
348-
let tok = if let TtToken(_, ref tok) = *token { tok } else { unreachable!() };
349-
// If T' is in the set FOLLOW(NT), continue. Else, reject.
350-
match (&next_token, is_in_follow(cx, &next_token, frag_spec.as_str())) {
351-
(_, Err(msg)) => {
352-
cx.span_err(sp, &msg);
353-
continue
351+
Eof
352+
},
353+
// die next iteration
354+
Some(&&TtDelimited(_, ref delim)) => delim.close_token(),
355+
// else, we're at the end of the macro or sequence
356+
None => follow.clone()
357+
};
358+
359+
let tok = if let TtToken(_, ref tok) = *token { tok } else { unreachable!() };
360+
361+
// If T' is in the set FOLLOW(NT), continue. Else, reject.
362+
match (&next_token, is_in_follow(cx, &next_token, frag_spec.as_str())) {
363+
(_, Err(msg)) => {
364+
cx.span_err(sp, &msg);
365+
continue
366+
}
367+
(&Eof, _) => return Some((sp, tok.clone())),
368+
(_, Ok(true)) => continue,
369+
(next, Ok(false)) => {
370+
cx.span_err(sp, &format!("`${0}:{1}` is followed by `{2}`, which \
371+
is not allowed for `{1}` fragments",
372+
name.as_str(), frag_spec.as_str(),
373+
token_to_string(next)));
374+
continue
375+
},
354376
}
355-
(&Eof, _) => return Some((sp, tok.clone())),
356-
(_, Ok(true)) => continue,
357-
(next, Ok(false)) => {
358-
cx.span_err(sp, &format!("`${0}:{1}` is followed by `{2}`, which \
359-
is not allowed for `{1}` fragments",
360-
name.as_str(), frag_spec.as_str(),
361-
token_to_string(next)));
362-
continue
363-
},
364377
}
365378
},
366379
TtSequence(sp, ref seq) => {
@@ -427,8 +440,39 @@ fn check_matcher<'a, I>(cx: &mut ExtCtxt, matcher: I, follow: &Token)
427440
last
428441
}
429442

443+
/// True if a fragment of type `frag` can be followed by any sort of
444+
/// token. We use this (among other things) as a useful approximation
445+
/// for when `frag` can be followed by a repetition like `$(...)*` or
446+
/// `$(...)+`. In general, these can be a bit tricky to reason about,
447+
/// so we adopt a conservative position that says that any fragment
448+
/// specifier which consumes at most one token tree can be followed by
449+
/// a fragment specifier (indeed, these fragments can be followed by
450+
/// ANYTHING without fear of future compatibility hazards).
451+
fn can_be_followed_by_any(frag: &str) -> bool {
452+
match frag {
453+
"item" | // always terminated by `}` or `;`
454+
"block" | // exactly one token tree
455+
"ident" | // exactly one token tree
456+
"meta" | // exactly one token tree
457+
"tt" => // exactly one token tree
458+
true,
459+
460+
_ =>
461+
false,
462+
}
463+
}
464+
465+
/// True if `frag` can legally be followed by the token `tok`. For
466+
/// fragments that can consume an unbounded numbe of tokens, `tok`
467+
/// must be within a well-defined follow set. This is intended to
468+
/// guarantee future compatibility: for example, without this rule, if
469+
/// we expanded `expr` to include a new binary operator, we might
470+
/// break macros that were relying on that binary operator as a
471+
/// separator.
430472
fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str) -> Result<bool, String> {
431473
if let &CloseDelim(_) = tok {
474+
// closing a token tree can never be matched by any fragment;
475+
// iow, we always require that `(` and `)` match, etc.
432476
Ok(true)
433477
} else {
434478
match frag {

branches/try/src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,8 @@ impl<'a> Parser<'a> {
20262026
return self.parse_block_expr(lo, DefaultBlock);
20272027
},
20282028
token::BinOp(token::Or) | token::OrOr => {
2029-
return self.parse_lambda_expr(CaptureByRef);
2029+
let lo = self.span.lo;
2030+
return self.parse_lambda_expr(lo, CaptureByRef);
20302031
},
20312032
token::Ident(id @ ast::Ident {
20322033
name: token::SELF_KEYWORD_NAME,
@@ -2081,7 +2082,8 @@ impl<'a> Parser<'a> {
20812082
return Ok(self.mk_expr(lo, hi, ExprPath(Some(qself), path)));
20822083
}
20832084
if try!(self.eat_keyword(keywords::Move) ){
2084-
return self.parse_lambda_expr(CaptureByValue);
2085+
let lo = self.last_span.lo;
2086+
return self.parse_lambda_expr(lo, CaptureByValue);
20852087
}
20862088
if try!(self.eat_keyword(keywords::If)) {
20872089
return self.parse_if_expr();
@@ -2840,10 +2842,9 @@ impl<'a> Parser<'a> {
28402842
}
28412843

28422844
// `|args| expr`
2843-
pub fn parse_lambda_expr(&mut self, capture_clause: CaptureClause)
2845+
pub fn parse_lambda_expr(&mut self, lo: BytePos, capture_clause: CaptureClause)
28442846
-> PResult<P<Expr>>
28452847
{
2846-
let lo = self.span.lo;
28472848
let decl = try!(self.parse_fn_block_decl());
28482849
let body = match decl.output {
28492850
DefaultReturn(_) => {
@@ -5266,11 +5267,7 @@ impl<'a> Parser<'a> {
52665267
return Ok(Some(try!(self.parse_item_foreign_mod(lo, opt_abi, visibility, attrs))));
52675268
}
52685269

5269-
let span = self.span;
5270-
let token_str = self.this_token_to_string();
5271-
return Err(self.span_fatal(span,
5272-
&format!("expected `{}` or `fn`, found `{}`", "{",
5273-
token_str)))
5270+
try!(self.expect_one_of(&[], &[]));
52745271
}
52755272

52765273
if try!(self.eat_keyword_noexpect(keywords::Virtual) ){
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for issue #25436: check that things which can be
12+
// followed by any token also permit X* to come afterwards.
13+
14+
macro_rules! foo {
15+
( $a:expr $($b:tt)* ) => { }; //~ ERROR not allowed for `expr` fragments
16+
( $a:ty $($b:tt)* ) => { }; //~ ERROR not allowed for `ty` fragments
17+
}
18+
19+
fn main() { }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we cannot have two sequence repetitions in a row.
12+
13+
macro_rules! foo {
14+
( $($a:expr)* $($b:tt)* ) => { }; //~ ERROR sequence repetition followed by another sequence
15+
( $($a:tt)* $($b:tt)* ) => { }; //~ ERROR sequence repetition followed by another sequence
16+
}
17+
18+
fn main() { }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Make sure that the span of a closure marked `move` begins at the `move` keyword.
12+
13+
fn main() {
14+
let x: () =
15+
move //~ ERROR mismatched types
16+
|| ();
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern crte foo; //~ ERROR expected one of `crate`, `fn`, or `{`, found `crte`

branches/try/src/test/parse-fail/extern-expected-fn-or-brace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
// Verifies that the expected token errors for `extern crate` are
1414
// raised
1515

16-
extern "C" mod foo; //~ERROR expected `{` or `fn`, found `mod`
16+
extern "C" mod foo; //~ERROR expected one of `fn` or `{`, found `mod`
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for issue #25436: check that things which can be
12+
// followed by any token also permit X* to come afterwards.
13+
14+
macro_rules! foo {
15+
( $a:tt $($b:tt)* ) => { };
16+
( $a:ident $($b:tt)* ) => { };
17+
( $a:item $($b:tt)* ) => { };
18+
( $a:block $($b:tt)* ) => { };
19+
( $a:meta $($b:tt)* ) => { }
20+
}
21+
22+
fn main() { }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for issue #25436: permit token-trees to be followed
12+
// by sequences, enabling more general parsing.
13+
14+
use self::Join::*;
15+
16+
#[derive(Debug)]
17+
enum Join<A,B> {
18+
Keep(A,B),
19+
Skip(A,B),
20+
}
21+
22+
macro_rules! parse_list {
23+
( < $a:expr; > $($b:tt)* ) => { Keep(parse_item!($a),parse_list!($($b)*)) };
24+
( $a:tt $($b:tt)* ) => { Skip(parse_item!($a), parse_list!($($b)*)) };
25+
( ) => { () };
26+
}
27+
28+
macro_rules! parse_item {
29+
( $x:expr ) => { $x }
30+
}
31+
32+
fn main() {
33+
let list = parse_list!(<1;> 2 <3;> 4);
34+
assert_eq!("Keep(1, Skip(2, Keep(3, Skip(4, ()))))",
35+
format!("{:?}", list));
36+
}

0 commit comments

Comments
 (0)