Skip to content

Commit cb57313

Browse files
committed
---
yaml --- r: 63410 b: refs/heads/snap-stage3 c: 81506a6 h: refs/heads/master v: v3
1 parent d09c014 commit cb57313

File tree

7 files changed

+93
-83
lines changed

7 files changed

+93
-83
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: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 6a6ffb4c76427a5c3ff4870aa8fb5ad3aeb7d70d
4+
refs/heads/snap-stage3: 81506a6b819dbcef0893307becaba03edf5e4bbe
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/trans/base.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,26 +1317,38 @@ pub fn cleanup_and_leave(bcx: block,
13171317

13181318
match cur.kind {
13191319
block_scope(inf) if !inf.empty_cleanups() => {
1320-
let (sub_cx, inf_cleanups) = {
1320+
let (sub_cx, dest, inf_cleanups) = {
13211321
let inf = &mut *inf; // FIXME(#5074) workaround stage0
1322+
let mut skip = 0;
1323+
let mut dest = None;
13221324
{
1323-
let r = vec::find((*inf).cleanup_paths, |cp| cp.target == leave);
1325+
let r = vec::rfind((*inf).cleanup_paths, |cp| cp.target == leave);
13241326
for r.iter().advance |cp| {
1325-
Br(bcx, cp.dest);
1326-
return;
1327+
if cp.size == inf.cleanups.len() {
1328+
Br(bcx, cp.dest);
1329+
return;
1330+
}
1331+
1332+
skip = cp.size;
1333+
dest = Some(cp.dest);
13271334
}
13281335
}
13291336
let sub_cx = sub_block(bcx, "cleanup");
13301337
Br(bcx, sub_cx.llbb);
13311338
inf.cleanup_paths.push(cleanup_path {
13321339
target: leave,
1340+
size: inf.cleanups.len(),
13331341
dest: sub_cx.llbb
13341342
});
1335-
(sub_cx, copy inf.cleanups)
1343+
(sub_cx, dest, inf.cleanups.tailn(skip).to_owned())
13361344
};
13371345
bcx = trans_block_cleanups_(sub_cx,
13381346
inf_cleanups,
13391347
is_lpad);
1348+
for dest.iter().advance |&dest| {
1349+
Br(bcx, dest);
1350+
return;
1351+
}
13401352
}
13411353
_ => ()
13421354
}

branches/snap-stage3/src/librustc/middle/trans/common.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,17 @@ pub enum cleanup {
325325
// target: none means the path ends in an resume instruction
326326
pub struct cleanup_path {
327327
target: Option<BasicBlockRef>,
328+
size: uint,
328329
dest: BasicBlockRef
329330
}
330331

331-
pub fn scope_clean_changed(scope_info: &mut scope_info) {
332-
if scope_info.cleanup_paths.len() > 0u { scope_info.cleanup_paths = ~[]; }
332+
pub fn shrink_scope_clean(scope_info: &mut scope_info, size: uint) {
333+
scope_info.landing_pad = None;
334+
scope_info.cleanup_paths = scope_info.cleanup_paths.iter()
335+
.take_while(|&cu| cu.size <= size).transform(|&x|x).collect();
336+
}
337+
338+
pub fn grow_scope_clean(scope_info: &mut scope_info) {
333339
scope_info.landing_pad = None;
334340
}
335341

@@ -374,7 +380,7 @@ pub fn add_clean(bcx: block, val: ValueRef, t: ty::t) {
374380
scope_info.cleanups.push(
375381
clean(|a| glue::drop_ty_root(a, root, rooted, t),
376382
cleanup_type));
377-
scope_clean_changed(scope_info);
383+
grow_scope_clean(scope_info);
378384
}
379385
}
380386

@@ -388,7 +394,7 @@ pub fn add_clean_temp_immediate(cx: block, val: ValueRef, ty: ty::t) {
388394
scope_info.cleanups.push(
389395
clean_temp(val, |a| glue::drop_ty_immediate(a, val, ty),
390396
cleanup_type));
391-
scope_clean_changed(scope_info);
397+
grow_scope_clean(scope_info);
392398
}
393399
}
394400
pub fn add_clean_temp_mem(bcx: block, val: ValueRef, t: ty::t) {
@@ -402,7 +408,7 @@ pub fn add_clean_temp_mem(bcx: block, val: ValueRef, t: ty::t) {
402408
scope_info.cleanups.push(
403409
clean_temp(val, |a| glue::drop_ty_root(a, root, rooted, t),
404410
cleanup_type));
405-
scope_clean_changed(scope_info);
411+
grow_scope_clean(scope_info);
406412
}
407413
}
408414
pub fn add_clean_return_to_mut(bcx: block,
@@ -434,7 +440,7 @@ pub fn add_clean_return_to_mut(bcx: block,
434440
filename_val,
435441
line_val),
436442
normal_exit_only));
437-
scope_clean_changed(scope_info);
443+
grow_scope_clean(scope_info);
438444
}
439445
}
440446
pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
@@ -451,7 +457,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
451457
do in_scope_cx(cx) |scope_info| {
452458
scope_info.cleanups.push(clean_temp(ptr, free_fn,
453459
normal_exit_and_unwind));
454-
scope_clean_changed(scope_info);
460+
grow_scope_clean(scope_info);
455461
}
456462
}
457463

@@ -474,7 +480,7 @@ pub fn revoke_clean(cx: block, val: ValueRef) {
474480
vec::slice(scope_info.cleanups,
475481
*i + 1u,
476482
scope_info.cleanups.len()));
477-
scope_clean_changed(scope_info);
483+
shrink_scope_clean(scope_info, *i);
478484
}
479485
}
480486
}

branches/snap-stage3/src/librustdoc/attr_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -152,6 +152,6 @@ mod test {
152152
fn should_concatenate_multiple_doc_comments() {
153153
let source = @"/// foo\n/// bar";
154154
let desc = parse_desc(parse_attributes(source));
155-
assert!(desc == Some(~" foo\n bar"));
155+
assert!(desc == Some(~"foo\nbar"));
156156
}
157157
}

branches/snap-stage3/src/libstd/iterator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,8 @@ impl<'self, A, St> UnfoldrIterator<'self, A, St> {
816816
/// Creates a new iterator with the specified closure as the "iterator
817817
/// function" and an initial state to eventually pass to the iterator
818818
#[inline]
819-
pub fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St)
820-
-> UnfoldrIterator<'self, A, St> {
819+
pub fn new<'a>(f: &'a fn(&mut St) -> Option<A>, initial_state: St)
820+
-> UnfoldrIterator<'a, A, St> {
821821
UnfoldrIterator {
822822
f: f,
823823
state: initial_state

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

Lines changed: 23 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -69,59 +69,50 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
6969
return lines.slice(i, j).to_owned();
7070
}
7171

72-
/// remove a "[ \t]*\*" block from each line, if possible
73-
fn horizontal_trim(lines: ~[~str]) -> ~[~str] {
74-
let mut i = uint::max_value;
75-
let mut can_trim = true;
76-
let mut first = true;
77-
for lines.iter().advance |line| {
72+
// drop leftmost columns that contain only values in chars
73+
fn block_trim(lines: ~[~str], chars: ~str, max: Option<uint>) -> ~[~str] {
74+
75+
let mut i = max.get_or_default(uint::max_value);
76+
for lines.each |line| {
77+
if line.trim().is_empty() {
78+
loop;
79+
}
7880
for line.iter().enumerate().advance |(j, c)| {
79-
if j > i || !"* \t".contains_char(c) {
80-
can_trim = false;
81+
if j >= i {
8182
break;
8283
}
83-
if c == '*' {
84-
if first {
85-
i = j;
86-
first = false;
87-
} else if i != j {
88-
can_trim = false;
89-
}
84+
if !chars.contains_char(c) {
85+
i = j;
9086
break;
9187
}
9288
}
93-
if i > line.len() {
94-
can_trim = false;
95-
}
96-
if !can_trim {
97-
break;
98-
}
9989
}
10090

101-
if can_trim {
102-
do lines.map |line| {
103-
line.slice(i + 1, line.len()).to_owned()
91+
return do lines.map |line| {
92+
let chars = line.iter().collect::<~[char]>();
93+
if i > chars.len() {
94+
~""
95+
} else {
96+
str::from_chars(chars.slice(i, chars.len()))
10497
}
105-
} else {
106-
lines
107-
}
98+
};
10899
}
109100

110101
if comment.starts_with("//") {
111102
// FIXME #5475:
112-
// return comment.slice(3u, comment.len()).to_owned();
113-
let r = comment.slice(3u, comment.len()); return r.to_owned();
103+
// return comment.slice(3u, comment.len()).trim().to_owned();
104+
let r = comment.slice(3u, comment.len()); return r.trim().to_owned();
114105
}
115106

116107
if comment.starts_with("/*") {
117108
let lines = comment.slice(3u, comment.len() - 2u)
118109
.any_line_iter()
119110
.transform(|s| s.to_owned())
120111
.collect::<~[~str]>();
121-
122112
let lines = vertical_trim(lines);
123-
let lines = horizontal_trim(lines);
124-
113+
let lines = block_trim(lines, ~"\t ", None);
114+
let lines = block_trim(lines, ~"*", Some(1u));
115+
let lines = block_trim(lines, ~"\t ", None);
125116
return lines.connect("\n");
126117
}
127118

@@ -379,36 +370,3 @@ pub fn gather_comments_and_literals(span_diagnostic:
379370

380371
(comments, literals)
381372
}
382-
383-
#[cfg(test)]
384-
mod test {
385-
use super::*;
386-
387-
#[test] fn test_block_doc_comment_1() {
388-
let comment = "/**\n * Test \n ** Test\n * Test\n*/";
389-
let correct_stripped = " Test \n* Test\n Test";
390-
let stripped = strip_doc_comment_decoration(comment);
391-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
392-
}
393-
394-
#[test] fn test_block_doc_comment_2() {
395-
let comment = "/**\n * Test\n * Test\n*/";
396-
let correct_stripped = " Test\n Test";
397-
let stripped = strip_doc_comment_decoration(comment);
398-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
399-
}
400-
401-
#[test] fn test_block_doc_comment_3() {
402-
let comment = "/**\n let a: *int;\n *a = 5;\n*/";
403-
let correct_stripped = " let a: *int;\n *a = 5;";
404-
let stripped = strip_doc_comment_decoration(comment);
405-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
406-
}
407-
408-
#[test] fn test_line_doc_comment() {
409-
let comment = "/// Test";
410-
let correct_stripped = " Test";
411-
let stripped = strip_doc_comment_decoration(comment);
412-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
413-
}
414-
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2013 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+
use std::iterator::*;
12+
13+
// UnfoldrIterator had a bug with 'self that mean it didn't work
14+
// cross-crate
15+
16+
fn main() {
17+
fn count(st: &mut uint) -> Option<uint> {
18+
if *st < 10 {
19+
let ret = Some(*st);
20+
*st += 1;
21+
ret
22+
} else {
23+
None
24+
}
25+
}
26+
27+
let mut it = UnfoldrIterator::new(count, 0);
28+
let mut i = 0;
29+
for it.advance |counted| {
30+
assert_eq!(counted, i);
31+
i += 1;
32+
}
33+
assert_eq!(i, 10);
34+
}

0 commit comments

Comments
 (0)