Skip to content

Commit 73b2c46

Browse files
committed
---
yaml --- r: 14714 b: refs/heads/try c: ebc1d3e h: refs/heads/master v: v3
1 parent 3bcd025 commit 73b2c46

File tree

8 files changed

+22
-12
lines changed

8 files changed

+22
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: c9cf73f0a8ad09ed9c032ce01683fcaa19389d6a
5+
refs/heads/try: ebc1d3e7042f19ed836bf99e6ede10e4ad049776
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/path.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ fn splitext(p: path) -> (str, str) {
169169
let parts = str::split_char(p, '.');
170170
if vec::len(parts) > 1u {
171171
let base = str::connect(vec::init(parts), ".");
172-
let ext = "." + vec::last_total(parts);
172+
// We just checked that parts is non-empty, so this is safe
173+
let ext = "." + vec::last_unsafe(parts);
173174

174175
fn is_dotfile(base: str) -> bool {
175176
str::is_empty(base)

branches/try/src/libcore/vec.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,15 @@ pure fn last<T: copy>(v: [const T]) -> option<T> {
200200
}
201201

202202
/*
203-
Function: last_total
203+
Function: last_unsafe
204204
205-
Returns the last element of a non-empty vector `v`
205+
Returns the last element of a `v`, failing if the vector is empty.
206206
207-
Predicates:
208-
<is_not_empty> (v)
209207
*/
210-
pure fn last_total<T: copy>(v: [const T]) -> T { v[len(v) - 1u] }
208+
pure fn last_unsafe<T: copy>(v: [const T]) -> T {
209+
if len(v) == 0u { fail "last_unsafe: empty vector" }
210+
v[len(v) - 1u]
211+
}
211212

212213
/*
213214
Function: slice

branches/try/src/libstd/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ fn splitext(p: path) -> (str, str) {
270270
let parts = str::split_char(p, '.');
271271
if vec::len(parts) > 1u {
272272
let base = str::connect(vec::init(parts), ".");
273-
let ext = "." + vec::last_total(parts);
273+
// We just checked that parts is non-empty
274+
let ext = "." + vec::last_unsafe(parts);
274275

275276
fn is_dotfile(base: str) -> bool {
276277
str::is_empty(base)

branches/try/src/rustc/middle/ast_map.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {
187187
let (id, name) = alt vp.node {
188188
view_path_simple(nm, _, id) { (id, nm) }
189189
view_path_glob(pth, id) | view_path_list(pth, _, id) {
190-
(id, vec::last_total(*pth))
190+
// should be a constraint on the type
191+
assert (vec::is_not_empty(*pth));
192+
(id, vec::last_unsafe(*pth))
191193
}
192194
};
193195
cx.map.insert(id, node_export(vp, extend(cx, name)));

branches/try/src/rustc/middle/pat_util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,7 @@ fn pat_binding_ids(dm: resolve::def_map, pat: @pat) -> [node_id] {
6868
ret found;
6969
}
7070

71-
fn path_to_ident(p: @path) -> ident { vec::last_total(p.node.idents) }
71+
fn path_to_ident(p: @path) -> ident {
72+
assert (vec::is_not_empty(p.node.idents)); // should be a constraint on path
73+
vec::last_unsafe(p.node.idents)
74+
}

branches/try/src/rustdoc/reexport_pass.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ fn build_reexport_path_map(srv: astsrv::srv, -def_map: def_map) -> path_map {
161161
let path = alt check ctxt.ast_map.get(exp_id) {
162162
ast_map::node_export(_, path) { path }
163163
};
164-
let name = alt check vec::last_total(*path) {
164+
// should be a constraint on the node_export constructor
165+
// that guarantees path is non-empty
166+
let name = alt check vec::last_unsafe(*path) {
165167
ast_map::path_name(nm) { nm }
166168
};
167169
let modpath = ast_map::path_to_str(vec::init(*path));

branches/try/src/test/run-pass/zip-same-length.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ fn main() {
1919

2020
check (is_not_empty(ps));
2121
assert (head(ps) == ('a', 1u));
22-
assert (last_total(ps) == (j as char, 10u));
22+
assert (last_unsafe(ps) == (j as char, 10u));
2323
}

0 commit comments

Comments
 (0)