Skip to content

Commit a6fc577

Browse files
committed
auto merge of #10693 : eddyb/rust/freeze-ast, r=thestinger
It's truly immutable now, which will allow us to remove some cloning in the parser and box parts of the AST in `Rc<T>` (if desired).
2 parents 23674be + f09b7b0 commit a6fc577

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

src/libsyntax/ast.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,14 +612,14 @@ pub enum token_tree {
612612
tt_tok(Span, ::parse::token::Token),
613613
// a delimited sequence (the delimiters appear as the first
614614
// and last elements of the vector)
615-
tt_delim(@mut ~[token_tree]),
615+
tt_delim(@~[token_tree]),
616616

617617
// These only make sense for right-hand-sides of MBE macros:
618618

619619
// a kleene-style repetition sequence with a span, a tt_forest,
620620
// an optional separator, and a boolean where true indicates
621621
// zero or more (*), and false indicates one or more (+).
622-
tt_seq(Span, @mut ~[token_tree], Option<::parse::token::Token>, bool),
622+
tt_seq(Span, @~[token_tree], Option<::parse::token::Token>, bool),
623623

624624
// a syntactic variable that will be filled in by macro expansion.
625625
tt_nonterminal(Span, Ident)
@@ -1180,6 +1180,18 @@ pub enum inlined_item {
11801180
ii_foreign(@foreign_item),
11811181
}
11821182

1183+
#[cfg(test)]
1184+
mod test {
1185+
use super::*;
1186+
1187+
fn is_freeze<T: Freeze>() {}
1188+
1189+
// Assert that the AST remains Freeze (#10693).
1190+
#[test] fn ast_is_freeze() {
1191+
is_freeze::<item>();
1192+
}
1193+
}
1194+
11831195
/* hold off on tests ... they appear in a later merge.
11841196
#[cfg(test)]
11851197
mod test {

src/libsyntax/ext/log_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt,
2323
cx.print_backtrace();
2424
println(
2525
print::pprust::tt_to_str(
26-
&ast::tt_delim(@mut tt.to_owned()),
26+
&ast::tt_delim(@tt.to_owned()),
2727
get_ident_interner()));
2828

2929
//trivial expression

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn generic_extension(cx: @ExtCtxt,
104104
println!("{}! \\{ {} \\}",
105105
cx.str_of(name),
106106
print::pprust::tt_to_str(
107-
&ast::tt_delim(@mut arg.to_owned()),
107+
&ast::tt_delim(@arg.to_owned()),
108108
get_ident_interner()));
109109
}
110110

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::option;
2222

2323
///an unzipping of `token_tree`s
2424
struct TtFrame {
25-
forest: @mut ~[ast::token_tree],
25+
forest: @~[ast::token_tree],
2626
idx: uint,
2727
dotdotdoted: bool,
2828
sep: Option<Token>,
@@ -52,7 +52,7 @@ pub fn new_tt_reader(sp_diag: @mut span_handler,
5252
let r = @mut TtReader {
5353
sp_diag: sp_diag,
5454
stack: @mut TtFrame {
55-
forest: @mut src,
55+
forest: @src,
5656
idx: 0u,
5757
dotdotdoted: false,
5858
sep: None,
@@ -74,7 +74,7 @@ pub fn new_tt_reader(sp_diag: @mut span_handler,
7474

7575
fn dup_tt_frame(f: @mut TtFrame) -> @mut TtFrame {
7676
@mut TtFrame {
77-
forest: @mut (*f.forest).clone(),
77+
forest: @(*f.forest).clone(),
7878
idx: f.idx,
7979
dotdotdoted: f.dotdotdoted,
8080
sep: f.sep.clone(),
@@ -175,8 +175,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
175175
loop {
176176
{
177177
let stack = &mut *r.stack;
178-
let forest = &mut *stack.forest;
179-
if stack.idx < forest.len() {
178+
if stack.idx < stack.forest.len() {
180179
break;
181180
}
182181
}

src/libsyntax/fold.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,10 @@ pub fn fold_tts<T:ast_fold>(tts: &[token_tree], fld: &T) -> ~[token_tree] {
457457
match *tt {
458458
tt_tok(span, ref tok) =>
459459
tt_tok(span,maybe_fold_ident(tok,fld)),
460-
tt_delim(ref tts) => tt_delim(@mut fold_tts(**tts, fld)),
461-
tt_seq(span, ref pattern, ref sep, is_optional) =>
460+
tt_delim(tts) => tt_delim(@fold_tts(*tts, fld)),
461+
tt_seq(span, pattern, ref sep, is_optional) =>
462462
tt_seq(span,
463-
@mut fold_tts(**pattern, fld),
463+
@fold_tts(*pattern, fld),
464464
sep.as_ref().map(|tok|maybe_fold_ident(tok,fld)),
465465
is_optional),
466466
tt_nonterminal(sp,ref ident) =>

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ impl Parser {
21122112
};
21132113
tt_seq(
21142114
mk_sp(sp.lo, p.span.hi),
2115-
@mut seq,
2115+
@seq,
21162116
s,
21172117
z
21182118
)
@@ -2157,7 +2157,7 @@ impl Parser {
21572157
result.push(parse_any_tt_tok(self));
21582158
self.open_braces.pop();
21592159

2160-
tt_delim(@mut result)
2160+
tt_delim(@result)
21612161
}
21622162
_ => parse_non_delim_tt_tok(self)
21632163
}

0 commit comments

Comments
 (0)