Skip to content

Commit 2d3dd37

Browse files
committed
---
yaml --- r: 138734 b: refs/heads/try2 c: 5ae06ae h: refs/heads/master v: v3
1 parent 7bf6424 commit 2d3dd37

File tree

5 files changed

+85
-49
lines changed

5 files changed

+85
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 359bb3e10bb022aabc5bfc60e48d3dfffc2ee62c
8+
refs/heads/try2: 5ae06ae9dea2f1dac157193b702f640e2216a5a9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/vec.rs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,10 @@ pub pure fn head_opt<T>(v: &r/[T]) -> Option<&r/T> {
223223
}
224224
225225
/// Returns a vector containing all but the first element of a slice
226-
pub pure fn tail<T:Copy>(v: &[const T]) -> ~[T] {
227-
slice(v, 1u, len(v)).to_vec()
228-
}
226+
pub pure fn tail<T>(v: &r/[T]) -> &r/[T] { slice(v, 1, v.len()) }
229227
230-
/**
231-
* Returns a vector containing all but the first `n` \
232-
* elements of a slice
233-
*/
234-
pub pure fn tailn<T:Copy>(v: &[const T], n: uint) -> ~[T] {
235-
slice(v, n, len(v)).to_vec()
236-
}
228+
/// Returns a vector containing all but the first `n` elements of a slice
229+
pub pure fn tailn<T>(v: &r/[T], n: uint) -> &r/[T] { slice(v, n, v.len()) }
237230
238231
/// Returns a vector containing all but the last element of a slice
239232
pub pure fn init<T:Copy>(v: &[const T]) -> ~[T] {
@@ -1704,7 +1697,6 @@ pub trait CopyableVector<T> {
17041697
pure fn init(&self) -> ~[T];
17051698
pure fn last(&self) -> T;
17061699
pure fn slice(&self, start: uint, end: uint) -> ~[T];
1707-
pure fn tail(&self) -> ~[T];
17081700
}
17091701

17101702
/// Extension methods for vectors
@@ -1722,16 +1714,14 @@ impl<T:Copy> CopyableVector<T> for &[const T] {
17221714
pure fn slice(&self, start: uint, end: uint) -> ~[T] {
17231715
slice(*self, start, end).to_vec()
17241716
}
1725-
1726-
/// Returns all but the first element of a vector
1727-
#[inline]
1728-
pure fn tail(&self) -> ~[T] { tail(*self) }
17291717
}
17301718

17311719
pub trait ImmutableVector<T> {
17321720
pure fn view(&self, start: uint, end: uint) -> &self/[T];
17331721
pure fn head(&self) -> &self/T;
17341722
pure fn head_opt(&self) -> Option<&self/T>;
1723+
pure fn tail(&self) -> &self/[T];
1724+
pure fn tailn(&self, n: uint) -> &self/[T];
17351725
pure fn foldr<U: Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U;
17361726
pure fn map<U>(&self, f: fn(t: &T) -> U) -> ~[U];
17371727
pure fn mapi<U>(&self, f: fn(uint, t: &T) -> U) -> ~[U];
@@ -1757,6 +1747,14 @@ impl<T> ImmutableVector<T> for &[T] {
17571747
#[inline]
17581748
pure fn head_opt(&self) -> Option<&self/T> { head_opt(*self) }
17591749

1750+
/// Returns all but the first element of a vector
1751+
#[inline]
1752+
pure fn tail(&self) -> &self/[T] { tail(*self) }
1753+
1754+
/// Returns all but the first `n' elements of a vector
1755+
#[inline]
1756+
pure fn tailn(&self, n: uint) -> &self/[T] { tailn(*self, n) }
1757+
17601758
/// Reduce a vector from right to left
17611759
#[inline]
17621760
pure fn foldr<U:Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U {
@@ -2611,10 +2609,33 @@ mod tests {
26112609
#[test]
26122610
fn test_tail() {
26132611
let mut a = ~[11];
2614-
assert (tail(a) == ~[]);
2615-
2612+
assert a.tail() == &[];
26162613
a = ~[11, 12];
2617-
assert (tail(a) == ~[12]);
2614+
assert a.tail() == &[12];
2615+
}
2616+
2617+
#[test]
2618+
#[should_fail]
2619+
#[ignore(cfg(windows))]
2620+
fn test_tail_empty() {
2621+
let a: ~[int] = ~[];
2622+
a.tail();
2623+
}
2624+
2625+
#[test]
2626+
fn test_tailn() {
2627+
let mut a = ~[11, 12, 13];
2628+
assert a.tailn(0) == &[11, 12, 13];
2629+
a = ~[11, 12, 13];
2630+
assert a.tailn(2) == &[13];
2631+
}
2632+
2633+
#[test]
2634+
#[should_fail]
2635+
#[ignore(cfg(windows))]
2636+
fn test_tailn_empty() {
2637+
let a: ~[int] = ~[];
2638+
a.tailn(2);
26182639
}
26192640

26202641
#[test]

branches/try2/src/librustc/middle/check_match.rs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: &[@pat]) -> useful {
265265
Some(ref ctor) => {
266266
match is_useful(cx,
267267
vec::filter_map(m, |r| default(cx, r)),
268-
vec::tail(v)) {
268+
v.tail()) {
269269
useful_ => useful(left_ty, (/*bad*/copy *ctor)),
270270
ref u => (/*bad*/copy *u)
271271
}
@@ -281,7 +281,7 @@ pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: &[@pat]) -> useful {
281281
282282
pub fn is_useful_specialized(cx: @MatchCheckCtxt,
283283
m: matrix,
284-
+v: &[@pat],
284+
v: &[@pat],
285285
+ctor: ctor,
286286
arity: uint,
287287
lty: ty::t)
@@ -475,7 +475,7 @@ pub fn wild() -> @pat {
475475
}
476476
477477
pub fn specialize(cx: @MatchCheckCtxt,
478-
+r: &[@pat],
478+
r: &[@pat],
479479
ctor_id: ctor,
480480
arity: uint,
481481
left_ty: ty::t)
@@ -485,13 +485,17 @@ pub fn specialize(cx: @MatchCheckCtxt,
485485
match r0 {
486486
pat{id: pat_id, node: n, span: pat_span} =>
487487
match n {
488-
pat_wild => Some(vec::append(vec::from_elem(arity, wild()),
489-
vec::tail(r))),
488+
pat_wild => {
489+
Some(vec::append(vec::from_elem(arity, wild()), r.tail()))
490+
}
490491
pat_ident(_, _, _) => {
491492
match cx.tcx.def_map.find(&pat_id) {
492493
Some(def_variant(_, id)) => {
493-
if variant(id) == ctor_id { Some(vec::tail(r)) }
494-
else { None }
494+
if variant(id) == ctor_id {
495+
Some(vec::from_slice(r.tail()))
496+
} else {
497+
None
498+
}
495499
}
496500
Some(def_const(did)) => {
497501
let const_expr =
@@ -506,10 +510,20 @@ pub fn specialize(cx: @MatchCheckCtxt,
506510
single => true,
507511
_ => fail!(~"type error")
508512
};
509-
if match_ { Some(vec::tail(r)) } else { None }
513+
if match_ {
514+
Some(vec::from_slice(r.tail()))
515+
} else {
516+
None
517+
}
518+
}
519+
_ => {
520+
Some(
521+
vec::append(
522+
vec::from_elem(arity, wild()),
523+
r.tail()
524+
)
525+
)
510526
}
511-
_ => Some(vec::append(vec::from_elem(arity, wild()),
512-
vec::tail(r)))
513527
}
514528
}
515529
pat_enum(_, args) => {
@@ -519,7 +533,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
519533
Some(args) => args,
520534
None => vec::from_elem(arity, wild())
521535
};
522-
Some(vec::append(args, vec::tail(r)))
536+
Some(vec::append(args, vec::from_slice(r.tail())))
523537
}
524538
def_variant(_, _) => None,
525539
def_struct(*) => {
@@ -529,7 +543,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
529543
Some(args) => new_args = args,
530544
None => new_args = vec::from_elem(arity, wild())
531545
}
532-
Some(vec::append(new_args, vec::tail(r)))
546+
Some(vec::append(new_args, vec::from_slice(r.tail())))
533547
}
534548
_ => None
535549
}
@@ -545,7 +559,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
545559
_ => wild()
546560
}
547561
});
548-
Some(vec::append(args, vec::tail(r)))
562+
Some(vec::append(args, vec::from_slice(r.tail())))
549563
}
550564
pat_struct(_, ref flds, _) => {
551565
// Is this a struct or an enum variant?
@@ -560,7 +574,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
560574
_ => wild()
561575
}
562576
});
563-
Some(vec::append(args, vec::tail(r)))
577+
Some(vec::append(args, vec::from_slice(r.tail())))
564578
} else {
565579
None
566580
}
@@ -587,13 +601,14 @@ pub fn specialize(cx: @MatchCheckCtxt,
587601
_ => wild()
588602
}
589603
});
590-
Some(vec::append(args, vec::tail(r)))
604+
Some(vec::append(args, vec::from_slice(r.tail())))
591605
}
592606
}
593607
}
594-
pat_tup(args) => Some(vec::append(args, vec::tail(r))),
595-
pat_box(a) | pat_uniq(a) | pat_region(a) =>
596-
Some(vec::append(~[a], vec::tail(r))),
608+
pat_tup(args) => Some(vec::append(args, r.tail())),
609+
pat_box(a) | pat_uniq(a) | pat_region(a) => {
610+
Some(vec::append(~[a], r.tail()))
611+
}
597612
pat_lit(expr) => {
598613
let e_v = eval_const_expr(cx.tcx, expr);
599614
let match_ = match ctor_id {
@@ -605,21 +620,21 @@ pub fn specialize(cx: @MatchCheckCtxt,
605620
single => true,
606621
_ => fail!(~"type error")
607622
};
608-
if match_ { Some(vec::tail(r)) } else { None }
623+
if match_ { Some(vec::from_slice(r.tail())) } else { None }
609624
}
610625
pat_range(lo, hi) => {
611626
let (c_lo, c_hi) = match ctor_id {
612627
val(ref v) => ((/*bad*/copy *v), (/*bad*/copy *v)),
613628
range(ref lo, ref hi) =>
614629
((/*bad*/copy *lo), (/*bad*/copy *hi)),
615-
single => return Some(vec::tail(r)),
630+
single => return Some(vec::from_slice(r.tail())),
616631
_ => fail!(~"type error")
617632
};
618633
let v_lo = eval_const_expr(cx.tcx, lo),
619634
v_hi = eval_const_expr(cx.tcx, hi);
620635
let match_ = compare_const_vals(c_lo, v_lo) >= 0 &&
621636
compare_const_vals(c_hi, v_hi) <= 0;
622-
if match_ { Some(vec::tail(r)) } else { None }
637+
if match_ { Some(vec::from_slice(r.tail())) } else { None }
623638
}
624639
pat_vec(elems, tail) => {
625640
match ctor_id {
@@ -630,10 +645,10 @@ pub fn specialize(cx: @MatchCheckCtxt,
630645
vec::append(elems, vec::from_elem(
631646
arity - num_elements, wild()
632647
)),
633-
vec::tail(r)
648+
vec::from_slice(r.tail())
634649
))
635650
} else if num_elements == arity {
636-
Some(vec::append(elems, vec::tail(r)))
651+
Some(vec::append(elems, r.tail()))
637652
} else {
638653
None
639654
}
@@ -645,8 +660,8 @@ pub fn specialize(cx: @MatchCheckCtxt,
645660
}
646661
}
647662
648-
pub fn default(cx: @MatchCheckCtxt, r: ~[@pat]) -> Option<~[@pat]> {
649-
if is_wild(cx, r[0]) { Some(vec::tail(r)) }
663+
pub fn default(cx: @MatchCheckCtxt, r: &[@pat]) -> Option<~[@pat]> {
664+
if is_wild(cx, r[0]) { Some(vec::from_slice(r.tail())) }
650665
else { None }
651666
}
652667

branches/try2/src/librustc/middle/trans/cabi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ pub impl FnType {
7171
let llretptr = GEPi(bcx, llargbundle, [0u, n]);
7272
let llretloc = Load(bcx, llretptr);
7373
llargvals = ~[llretloc];
74-
atys = vec::tail(atys);
75-
attrs = vec::tail(attrs);
74+
atys = vec::from_slice(atys.tail());
75+
attrs = vec::from_slice(attrs.tail());
7676
}
7777

7878
while i < n {
@@ -131,8 +131,8 @@ pub impl FnType {
131131
let mut attrs = /*bad*/copy self.attrs;
132132
let mut j = 0u;
133133
let llretptr = if self.sret {
134-
atys = vec::tail(atys);
135-
attrs = vec::tail(attrs);
134+
atys = vec::from_slice(atys.tail());
135+
attrs = vec::from_slice(attrs.tail());
136136
j = 1u;
137137
get_param(llwrapfn, 0u)
138138
} else if self.ret_ty.cast {

branches/try2/src/librustdoc/unindent_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn unindent(s: &str) -> ~str {
7979

8080
if !lines.is_empty() {
8181
let unindented = ~[lines.head().trim()]
82-
+ do vec::tail(lines).map |line| {
82+
+ do lines.tail().map |line| {
8383
if str::is_whitespace(*line) {
8484
copy *line
8585
} else {

0 commit comments

Comments
 (0)