Skip to content

Commit 8b67a3c

Browse files
committed
---
yaml --- r: 208566 b: refs/heads/snap-stage3 c: a9ea33f h: refs/heads/master v: v3
1 parent 9848b77 commit 8b67a3c

File tree

11 files changed

+108
-52
lines changed

11 files changed

+108
-52
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 38a97becdf3e6a6157f6f7ec2d98ade8d8edc193
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 26560e75b702c2254bb8a031276fcffda9bc1bde
4+
refs/heads/snap-stage3: a9ea33fa30fc2c1a8084e035455ba2a0a0dfea3e
55
refs/heads/try: 7b4ef47b7805a402d756fb8157101f64880a522f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# The Rust Programming Language
22

3-
This is a compiler for Rust, including standard libraries, tools and
4-
documentation. Rust is a systems programming language that is fast,
5-
memory safe and multithreaded, but does not employ a garbage collector
6-
or otherwise impose significant runtime overhead.
3+
Rust is a systems programming language that is fast, memory safe and
4+
multithreaded, but does not employ a garbage collector or otherwise
5+
impose significant runtime overhead.
6+
7+
This repo contains the code for `rustc`, the Rust compiler, as well
8+
as standard libraries, tools and documentation for Rust.
79

810
## Quick Start
911

branches/snap-stage3/src/doc/trpl/dining-philosophers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ let handles: Vec<_> = philosophers.into_iter().map(|p| {
396396
}).collect();
397397
```
398398

399-
While this is only five lines, they’re a dense four. Let’s break it down.
399+
While this is only five lines, they’re a dense five. Let’s break it down.
400400

401401
```rust,ignore
402402
let handles: Vec<_> =

branches/snap-stage3/src/doc/trpl/guessing-game.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Check out the generated `Cargo.toml`:
2727
[package]
2828

2929
name = "guessing_game"
30-
version = "0.0.1"
30+
version = "0.1.0"
3131
authors = ["Your Name <[email protected]>"]
3232
```
3333

@@ -46,7 +46,7 @@ Let’s try compiling what Cargo gave us:
4646

4747
```{bash}
4848
$ cargo build
49-
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
49+
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
5050
```
5151

5252
Excellent! Open up your `src/main.rs` again. We’ll be writing all of
@@ -58,7 +58,7 @@ Try it out:
5858

5959
```bash
6060
$ cargo run
61-
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
61+
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
6262
Running `target/debug/guessing_game`
6363
Hello, world!
6464
```
@@ -727,7 +727,7 @@ Let’s try our program out!
727727
728728
```bash
729729
$ cargo run
730-
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
730+
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
731731
Running `target/guessing_game`
732732
Guess the number!
733733
The secret number is: 58
@@ -792,7 +792,7 @@ and quit. Observe:
792792
793793
```bash
794794
$ cargo run
795-
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
795+
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
796796
Running `target/guessing_game`
797797
Guess the number!
798798
The secret number is: 59
@@ -929,7 +929,7 @@ Now we should be good! Let’s try:
929929
930930
```bash
931931
$ cargo run
932-
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
932+
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
933933
Running `target/guessing_game`
934934
Guess the number!
935935
The secret number is: 61

branches/snap-stage3/src/libsyntax/ext/quote.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ pub mod rt {
2828
use ast;
2929
use codemap::Spanned;
3030
use ext::base::ExtCtxt;
31-
use parse::token;
32-
use parse;
31+
use parse::{self, token, classify};
3332
use ptr::P;
3433
use std::rc::Rc;
3534

@@ -94,6 +93,18 @@ pub mod rt {
9493
}
9594
}
9695

96+
impl ToTokens for ast::Generics {
97+
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
98+
vec![ast::TtToken(DUMMY_SP, token::Interpolated(token::NtGenerics(self.clone())))]
99+
}
100+
}
101+
102+
impl ToTokens for ast::WhereClause {
103+
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
104+
vec![ast::TtToken(DUMMY_SP, token::Interpolated(token::NtWhereClause(self.clone())))]
105+
}
106+
}
107+
97108
impl ToTokens for P<ast::Item> {
98109
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
99110
vec![ast::TtToken(self.span, token::Interpolated(token::NtItem(self.clone())))]
@@ -114,7 +125,16 @@ pub mod rt {
114125

115126
impl ToTokens for P<ast::Stmt> {
116127
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
117-
vec![ast::TtToken(self.span, token::Interpolated(token::NtStmt(self.clone())))]
128+
let mut tts = vec![
129+
ast::TtToken(self.span, token::Interpolated(token::NtStmt(self.clone())))
130+
];
131+
132+
// Some statements require a trailing semicolon.
133+
if classify::stmt_ends_with_semi(&self.node) {
134+
tts.push(ast::TtToken(self.span, token::Semi));
135+
}
136+
137+
tts
118138
}
119139
}
120140

branches/snap-stage3/src/libsyntax/fold.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ pub fn noop_fold_interpolated<T: Folder>(nt: token::Nonterminal, fld: &mut T)
689689
token::NtTraitItem(arm) =>
690690
token::NtTraitItem(fld.fold_trait_item(arm)
691691
.expect_one("expected fold to produce exactly one item")),
692+
token::NtGenerics(generics) => token::NtGenerics(fld.fold_generics(generics)),
693+
token::NtWhereClause(where_clause) =>
694+
token::NtWhereClause(fld.fold_where_clause(where_clause)),
692695
}
693696
}
694697

branches/snap-stage3/src/libsyntax/parse/lexer/mod.rs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -403,45 +403,51 @@ impl<'a> StringReader<'a> {
403403
Some('/') => {
404404
self.bump();
405405
self.bump();
406+
406407
// line comments starting with "///" or "//!" are doc-comments
407-
if self.curr_is('/') || self.curr_is('!') {
408-
let start_bpos = self.pos - BytePos(3);
409-
while !self.is_eof() {
410-
match self.curr.unwrap() {
411-
'\n' => break,
412-
'\r' => {
413-
if self.nextch_is('\n') {
414-
// CRLF
415-
break
416-
} else {
417-
self.err_span_(self.last_pos, self.pos,
418-
"bare CR not allowed in doc-comment");
419-
}
408+
let doc_comment = self.curr_is('/') || self.curr_is('!');
409+
let start_bpos = if doc_comment {
410+
self.pos - BytePos(3)
411+
} else {
412+
self.last_pos - BytePos(2)
413+
};
414+
415+
while !self.is_eof() {
416+
match self.curr.unwrap() {
417+
'\n' => break,
418+
'\r' => {
419+
if self.nextch_is('\n') {
420+
// CRLF
421+
break
422+
} else if doc_comment {
423+
self.err_span_(self.last_pos, self.pos,
424+
"bare CR not allowed in doc-comment");
420425
}
421-
_ => ()
422426
}
423-
self.bump();
427+
_ => ()
424428
}
425-
return self.with_str_from(start_bpos, |string| {
426-
// but comments with only more "/"s are not
429+
self.bump();
430+
}
431+
432+
return if doc_comment {
433+
self.with_str_from(start_bpos, |string| {
434+
// comments with only more "/"s are not doc comments
427435
let tok = if is_doc_comment(string) {
428436
token::DocComment(token::intern(string))
429437
} else {
430438
token::Comment
431439
};
432440

433-
return Some(TokenAndSpan{
441+
Some(TokenAndSpan {
434442
tok: tok,
435443
sp: codemap::mk_sp(start_bpos, self.last_pos)
436-
});
437-
});
444+
})
445+
})
438446
} else {
439-
let start_bpos = self.last_pos - BytePos(2);
440-
while !self.curr_is('\n') && !self.is_eof() { self.bump(); }
441-
return Some(TokenAndSpan {
447+
Some(TokenAndSpan {
442448
tok: token::Comment,
443449
sp: codemap::mk_sp(start_bpos, self.last_pos)
444-
});
450+
})
445451
}
446452
}
447453
Some('*') => {
@@ -1563,4 +1569,13 @@ mod tests {
15631569
assert_eq!(lexer.next_token().tok, token::Literal(token::Char(token::intern("a")), None));
15641570
}
15651571

1572+
#[test] fn crlf_comments() {
1573+
let sh = mk_sh();
1574+
let mut lexer = setup(&sh, "// test\r\n/// test\r\n".to_string());
1575+
let comment = lexer.next_token();
1576+
assert_eq!(comment.tok, token::Comment);
1577+
assert_eq!(comment.sp, ::codemap::mk_sp(BytePos(0), BytePos(7)));
1578+
assert_eq!(lexer.next_token().tok, token::Whitespace);
1579+
assert_eq!(lexer.next_token().tok, token::DocComment(token::intern("/// test")));
1580+
}
15661581
}

branches/snap-stage3/src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3808,6 +3808,8 @@ impl<'a> Parser<'a> {
38083808
/// | ( < lifetimes , typaramseq ( , )? > )
38093809
/// where typaramseq = ( typaram ) | ( typaram , typaramseq )
38103810
pub fn parse_generics(&mut self) -> PResult<ast::Generics> {
3811+
maybe_whole!(self, NtGenerics);
3812+
38113813
if try!(self.eat(&token::Lt) ){
38123814
let lifetime_defs = try!(self.parse_lifetime_defs());
38133815
let mut seen_default = false;
@@ -3928,6 +3930,8 @@ impl<'a> Parser<'a> {
39283930
/// where T : Trait<U, V> + 'b, 'a : 'b
39293931
/// ```
39303932
pub fn parse_where_clause(&mut self) -> PResult<ast::WhereClause> {
3933+
maybe_whole!(self, NtWhereClause);
3934+
39313935
let mut where_clause = WhereClause {
39323936
id: ast::DUMMY_NODE_ID,
39333937
predicates: Vec::new(),

branches/snap-stage3/src/libsyntax/parse/token.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ pub enum Nonterminal {
385385
NtArm(ast::Arm),
386386
NtImplItem(P<ast::ImplItem>),
387387
NtTraitItem(P<ast::TraitItem>),
388+
NtGenerics(ast::Generics),
389+
NtWhereClause(ast::WhereClause),
388390
}
389391

390392
impl fmt::Debug for Nonterminal {
@@ -403,6 +405,8 @@ impl fmt::Debug for Nonterminal {
403405
NtArm(..) => f.pad("NtArm(..)"),
404406
NtImplItem(..) => f.pad("NtImplItem(..)"),
405407
NtTraitItem(..) => f.pad("NtTraitItem(..)"),
408+
NtGenerics(..) => f.pad("NtGenerics(..)"),
409+
NtWhereClause(..) => f.pad("NtWhereClause(..)"),
406410
}
407411
}
408412
}

branches/snap-stage3/src/libsyntax/print/pprust.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,19 +287,21 @@ pub fn token_to_string(tok: &Token) -> String {
287287
token::SpecialVarNt(var) => format!("${}", var.as_str()),
288288

289289
token::Interpolated(ref nt) => match *nt {
290-
token::NtExpr(ref e) => expr_to_string(&**e),
291-
token::NtMeta(ref e) => meta_item_to_string(&**e),
292-
token::NtTy(ref e) => ty_to_string(&**e),
293-
token::NtPath(ref e) => path_to_string(&**e),
294-
token::NtItem(..) => "an interpolated item".to_string(),
295-
token::NtBlock(..) => "an interpolated block".to_string(),
296-
token::NtStmt(..) => "an interpolated statement".to_string(),
297-
token::NtPat(..) => "an interpolated pattern".to_string(),
298-
token::NtIdent(..) => "an interpolated identifier".to_string(),
299-
token::NtTT(..) => "an interpolated tt".to_string(),
300-
token::NtArm(..) => "an interpolated arm".to_string(),
301-
token::NtImplItem(..) => "an interpolated impl item".to_string(),
302-
token::NtTraitItem(..) => "an interpolated trait item".to_string(),
290+
token::NtExpr(ref e) => expr_to_string(&**e),
291+
token::NtMeta(ref e) => meta_item_to_string(&**e),
292+
token::NtTy(ref e) => ty_to_string(&**e),
293+
token::NtPath(ref e) => path_to_string(&**e),
294+
token::NtItem(ref e) => item_to_string(&**e),
295+
token::NtBlock(ref e) => block_to_string(&**e),
296+
token::NtStmt(ref e) => stmt_to_string(&**e),
297+
token::NtPat(ref e) => pat_to_string(&**e),
298+
token::NtIdent(ref e, _) => ident_to_string(&**e),
299+
token::NtTT(ref e) => tt_to_string(&**e),
300+
token::NtArm(ref e) => arm_to_string(&*e),
301+
token::NtImplItem(ref e) => impl_item_to_string(&**e),
302+
token::NtTraitItem(ref e) => trait_item_to_string(&**e),
303+
token::NtGenerics(ref e) => generics_to_string(&*e),
304+
token::NtWhereClause(ref e) => where_clause_to_string(&*e),
303305
}
304306
}
305307
}

branches/snap-stage3/src/test/run-pass-fulldeps/quote-tokens.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ fn syntax_extension(cx: &ExtCtxt) {
4343
let _n: syntax::ast::Attribute = quote_attr!(cx, #![cfg(foo, bar = "baz")]);
4444

4545
let _o: Option<P<syntax::ast::Item>> = quote_item!(cx, fn foo<T: ?Sized>() {});
46+
47+
let stmts = vec![
48+
quote_stmt!(cx, let x = 1;).unwrap(),
49+
quote_stmt!(cx, let y = 2;).unwrap(),
50+
];
51+
let expr: P<syntax::ast::Expr> = quote_expr!(cx, x + y);
4652
}
4753

4854
fn main() {

0 commit comments

Comments
 (0)