Skip to content

Commit bf0b3ec

Browse files
asdfgraydon
authored andcommitted
---
yaml --- r: 52156 b: refs/heads/dist-snap c: 4096c9f h: refs/heads/master v: v3
1 parent 8ffae2e commit bf0b3ec

File tree

21 files changed

+111
-97
lines changed

21 files changed

+111
-97
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: 44d4d6de762f3f9aae1fedcf454c66b79b3ad58d
10-
refs/heads/dist-snap: 816cb8c5350084e04770b9c3a133400923bd2e1b
10+
refs/heads/dist-snap: 4096c9f25f59e67835999ec6c89bc4ca1f3dcad0
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcore/vec.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,9 @@ pub mod raw {
19601960
* may overlap.
19611961
*/
19621962
pub unsafe fn memcpy<T>(dst: &[mut T], src: &[const T], count: uint) {
1963+
assert dst.len() >= count;
1964+
assert src.len() >= count;
1965+
19631966
do as_mut_buf(dst) |p_dst, _len_dst| {
19641967
do as_const_buf(src) |p_src, _len_src| {
19651968
ptr::memcpy(p_dst, p_src, count)
@@ -1974,6 +1977,9 @@ pub mod raw {
19741977
* may overlap.
19751978
*/
19761979
pub unsafe fn memmove<T>(dst: &[mut T], src: &[const T], count: uint) {
1980+
assert dst.len() >= count;
1981+
assert src.len() >= count;
1982+
19771983
do as_mut_buf(dst) |p_dst, _len_dst| {
19781984
do as_const_buf(src) |p_src, _len_src| {
19791985
ptr::memmove(p_dst, p_src, count)
@@ -3730,6 +3736,15 @@ mod tests {
37303736
fail
37313737
}
37323738
}
3739+
3740+
#[test]
3741+
#[should_fail]
3742+
fn test_memcpy_oob() unsafe {
3743+
let a = [mut 1, 2, 3, 4];
3744+
let b = [1, 2, 3, 4, 5];
3745+
raw::memcpy(a, b, 5);
3746+
}
3747+
37333748
}
37343749

37353750
// Local Variables:

branches/dist-snap/src/librustc/driver/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ fn compile_upto(sess: Session, cfg: ast::crate_cfg,
275275
time(time_passes, ~"mode computation", ||
276276
middle::mode::compute_modes(ty_cx, method_map, crate));
277277

278-
time(time_passes, ~"match checking", ||
279-
middle::check_match::check_crate(ty_cx, method_map, crate));
278+
time(time_passes, ~"alt checking", ||
279+
middle::check_alt::check_crate(ty_cx, method_map, crate));
280280

281281
let last_use_map =
282282
time(time_passes, ~"liveness checking", ||

branches/dist-snap/src/librustc/middle/borrowck/gather_loans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,19 +506,19 @@ impl gather_loan_ctxt {
506506
discr_cmt: cmt,
507507
root_pat: @ast::pat,
508508
arm_id: ast::node_id,
509-
match_id: ast::node_id) {
509+
alt_id: ast::node_id) {
510510
do self.bccx.cat_pattern(discr_cmt, root_pat) |cmt, pat| {
511511
match pat.node {
512512
ast::pat_ident(bm, _, _) if self.pat_is_binding(pat) => {
513513
match bm {
514514
ast::bind_by_value | ast::bind_by_move => {
515515
// copying does not borrow anything, so no check
516516
// is required
517-
// as for move, check::_match ensures it's from an rvalue.
517+
// as for move, check::alt ensures it's from an rvalue.
518518
}
519519
ast::bind_by_ref(mutbl) => {
520520
// ref x or ref x @ p --- creates a ptr which must
521-
// remain valid for the scope of the match
521+
// remain valid for the scope of the alt
522522

523523
// find the region of the resulting pointer (note that
524524
// the type of such a pattern will *always* be a
@@ -531,7 +531,7 @@ impl gather_loan_ctxt {
531531
// of the function of this node in method preserve():
532532
let arm_scope = ty::re_scope(arm_id);
533533
if self.bccx.is_subregion_of(scope_r, arm_scope) {
534-
let cmt_discr = self.bccx.cat_discr(cmt, match_id);
534+
let cmt_discr = self.bccx.cat_discr(cmt, alt_id);
535535
self.guarantee_valid(cmt_discr, mutbl, scope_r);
536536
} else {
537537
self.guarantee_valid(cmt, mutbl, scope_r);

branches/dist-snap/src/librustc/middle/borrowck/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ impl borrowck_ctxt {
494494
cat_variant(self.tcx, self.method_map, arg, enum_did, cmt)
495495
}
496496

497-
fn cat_discr(cmt: cmt, match_id: ast::node_id) -> cmt {
498-
return @{cat:cat_discr(cmt, match_id),.. *cmt};
497+
fn cat_discr(cmt: cmt, alt_id: ast::node_id) -> cmt {
498+
return @{cat:cat_discr(cmt, alt_id),.. *cmt};
499499
}
500500

501501
fn cat_pattern(cmt: cmt, pat: @ast::pat, op: fn(cmt, @ast::pat)) {

branches/dist-snap/src/librustc/middle/borrowck/preserve.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ priv impl &preserve_ctxt {
195195
self.attempt_root(cmt, base, derefs)
196196
}
197197
}
198-
cat_discr(base, match_id) => {
199-
// Subtle: in a match, we must ensure that each binding
198+
cat_discr(base, alt_id) => {
199+
// Subtle: in an alt, we must ensure that each binding
200200
// variable remains valid for the duration of the arm in
201201
// which it appears, presuming that this arm is taken.
202202
// But it is inconvenient in trans to root something just
203203
// for one arm. Therefore, we insert a cat_discr(),
204204
// basically a special kind of category that says "if this
205205
// value must be dynamically rooted, root it for the scope
206-
// `match_id`.
206+
// `alt_id`.
207207
//
208208
// As an example, consider this scenario:
209209
//
@@ -213,7 +213,7 @@ priv impl &preserve_ctxt {
213213
// Technically, the value `x` need only be rooted
214214
// in the `some` arm. However, we evaluate `x` in trans
215215
// before we know what arm will be taken, so we just
216-
// always root it for the duration of the match.
216+
// always root it for the duration of the alt.
217217
//
218218
// As a second example, consider *this* scenario:
219219
//
@@ -225,7 +225,7 @@ priv impl &preserve_ctxt {
225225
// found only when checking which pattern matches: but
226226
// this check is done before entering the arm. Therefore,
227227
// even in this case we just choose to keep the value
228-
// rooted for the entire match. This means the value will be
228+
// rooted for the entire alt. This means the value will be
229229
// rooted even if the none arm is taken. Oh well.
230230
//
231231
// At first, I tried to optimize the second case to only
@@ -247,12 +247,12 @@ priv impl &preserve_ctxt {
247247
// Nonetheless, if you decide to optimize this case in the
248248
// future, you need only adjust where the cat_discr()
249249
// node appears to draw the line between what will be rooted
250-
// in the *arm* vs the *match*.
250+
// in the *arm* vs the *alt*.
251251

252-
let match_rooting_ctxt =
253-
preserve_ctxt({scope_region: ty::re_scope(match_id),
252+
let alt_rooting_ctxt =
253+
preserve_ctxt({scope_region: ty::re_scope(alt_id),
254254
.. **self});
255-
(&match_rooting_ctxt).preserve(base)
255+
(&alt_rooting_ctxt).preserve(base)
256256
}
257257
}
258258
}

branches/dist-snap/src/librustc/middle/check_match.rs renamed to branches/dist-snap/src/librustc/middle/check_alt.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ use syntax::codemap::span;
3030
use syntax::print::pprust::pat_to_str;
3131
use syntax::visit;
3232

33-
struct MatchCheckCtxt {
33+
struct AltCheckCtxt {
3434
tcx: ty::ctxt,
3535
method_map: method_map,
3636
}
3737

3838
fn check_crate(tcx: ty::ctxt, method_map: method_map, crate: @crate) {
39-
let cx = @MatchCheckCtxt { tcx: tcx, method_map: method_map };
39+
let cx = @AltCheckCtxt { tcx: tcx, method_map: method_map };
4040
visit::visit_crate(*crate, (), visit::mk_vt(@{
4141
visit_expr: |a,b,c| check_expr(cx, a, b, c),
4242
visit_local: |a,b,c| check_local(cx, a, b, c),
@@ -47,7 +47,7 @@ fn check_crate(tcx: ty::ctxt, method_map: method_map, crate: @crate) {
4747
tcx.sess.abort_if_errors();
4848
}
4949

50-
fn expr_is_non_moving_lvalue(cx: @MatchCheckCtxt, expr: @expr) -> bool {
50+
fn expr_is_non_moving_lvalue(cx: @AltCheckCtxt, expr: @expr) -> bool {
5151
if !ty::expr_is_lval(cx.tcx, cx.method_map, expr) {
5252
return false;
5353
}
@@ -61,7 +61,7 @@ fn expr_is_non_moving_lvalue(cx: @MatchCheckCtxt, expr: @expr) -> bool {
6161
}
6262
}
6363

64-
fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
64+
fn check_expr(cx: @AltCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
6565
visit::visit_expr(ex, s, v);
6666
match ex.node {
6767
expr_match(scrut, ref arms) => {
@@ -107,7 +107,7 @@ fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
107107
}
108108

109109
// Check for unreachable patterns
110-
fn check_arms(cx: @MatchCheckCtxt, arms: ~[arm]) {
110+
fn check_arms(cx: @AltCheckCtxt, arms: ~[arm]) {
111111
let mut seen = ~[];
112112
for arms.each |arm| {
113113
for arm.pats.each |pat| {
@@ -130,7 +130,7 @@ fn raw_pat(p: @pat) -> @pat {
130130
}
131131
}
132132

133-
fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
133+
fn check_exhaustive(cx: @AltCheckCtxt, sp: span, pats: ~[@pat]) {
134134
assert(pats.is_not_empty());
135135
let ext = match is_useful(cx, vec::map(pats, |p| ~[*p]), ~[wild()]) {
136136
not_useful => return, // This is good, wildcard pattern isn't reachable
@@ -216,7 +216,7 @@ impl ctor : cmp::Eq {
216216

217217
// Note: is_useful doesn't work on empty types, as the paper notes.
218218
// So it assumes that v is non-empty.
219-
fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: ~[@pat]) -> useful {
219+
fn is_useful(cx: @AltCheckCtxt, +m: matrix, +v: ~[@pat]) -> useful {
220220
if m.len() == 0u { return useful_; }
221221
if m[0].len() == 0u { return not_useful; }
222222
let real_pat = match vec::find(m, |r| r[0].id != 0) {
@@ -289,7 +289,7 @@ fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: ~[@pat]) -> useful {
289289
}
290290
}
291291

292-
fn is_useful_specialized(cx: @MatchCheckCtxt, m: matrix, +v: ~[@pat],
292+
fn is_useful_specialized(cx: @AltCheckCtxt, m: matrix, +v: ~[@pat],
293293
+ctor: ctor, arity: uint, lty: ty::t) -> useful {
294294
let ms = vec::filter_map(m, |r| specialize(cx, *r, ctor, arity, lty));
295295
let could_be_useful = is_useful(
@@ -300,7 +300,7 @@ fn is_useful_specialized(cx: @MatchCheckCtxt, m: matrix, +v: ~[@pat],
300300
}
301301
}
302302

303-
fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
303+
fn pat_ctor_id(cx: @AltCheckCtxt, p: @pat) -> Option<ctor> {
304304
let pat = raw_pat(p);
305305
match /*bad*/copy pat.node {
306306
pat_wild => { None }
@@ -337,7 +337,7 @@ fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
337337
}
338338
}
339339

340-
fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
340+
fn is_wild(cx: @AltCheckCtxt, p: @pat) -> bool {
341341
let pat = raw_pat(p);
342342
match pat.node {
343343
pat_wild => { true }
@@ -351,7 +351,7 @@ fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
351351
}
352352
}
353353

354-
fn missing_ctor(cx: @MatchCheckCtxt,
354+
fn missing_ctor(cx: @AltCheckCtxt,
355355
m: matrix,
356356
left_ty: ty::t)
357357
-> Option<ctor> {
@@ -451,7 +451,7 @@ fn missing_ctor(cx: @MatchCheckCtxt,
451451
}
452452
}
453453

454-
fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
454+
fn ctor_arity(cx: @AltCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
455455
match /*bad*/copy ty::get(ty).sty {
456456
ty::ty_tup(fs) => fs.len(),
457457
ty::ty_rec(fs) => fs.len(),
@@ -479,7 +479,7 @@ fn wild() -> @pat {
479479
@{id: 0, node: pat_wild, span: ast_util::dummy_sp()}
480480
}
481481

482-
fn specialize(cx: @MatchCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,
482+
fn specialize(cx: @AltCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,
483483
left_ty: ty::t) -> Option<~[@pat]> {
484484
let r0 = raw_pat(r[0]);
485485
match /*bad*/copy r0.node {
@@ -637,12 +637,12 @@ fn specialize(cx: @MatchCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,
637637
}
638638
}
639639

640-
fn default(cx: @MatchCheckCtxt, r: ~[@pat]) -> Option<~[@pat]> {
640+
fn default(cx: @AltCheckCtxt, r: ~[@pat]) -> Option<~[@pat]> {
641641
if is_wild(cx, r[0]) { Some(vec::tail(r)) }
642642
else { None }
643643
}
644644

645-
fn check_local(cx: @MatchCheckCtxt, loc: @local, &&s: (), v: visit::vt<()>) {
645+
fn check_local(cx: @AltCheckCtxt, loc: @local, &&s: (), v: visit::vt<()>) {
646646
visit::visit_local(loc, s, v);
647647
if is_refutable(cx, loc.node.pat) {
648648
cx.tcx.sess.span_err(loc.node.pat.span,
@@ -657,7 +657,7 @@ fn check_local(cx: @MatchCheckCtxt, loc: @local, &&s: (), v: visit::vt<()>) {
657657
check_legality_of_move_bindings(cx, is_lvalue, false, [ loc.node.pat ]);
658658
}
659659

660-
fn check_fn(cx: @MatchCheckCtxt,
660+
fn check_fn(cx: @AltCheckCtxt,
661661
kind: visit::fn_kind,
662662
decl: fn_decl,
663663
body: blk,
@@ -674,7 +674,7 @@ fn check_fn(cx: @MatchCheckCtxt,
674674
}
675675
}
676676

677-
fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
677+
fn is_refutable(cx: @AltCheckCtxt, pat: &pat) -> bool {
678678
match cx.tcx.def_map.find(pat.id) {
679679
Some(def_variant(enum_id, _)) => {
680680
if vec::len(*ty::enum_variants(cx.tcx, enum_id)) != 1u {
@@ -712,7 +712,7 @@ fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
712712

713713
// Legality of move bindings checking
714714

715-
fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
715+
fn check_legality_of_move_bindings(cx: @AltCheckCtxt,
716716
is_lvalue: bool,
717717
has_guard: bool,
718718
pats: &[@pat]) {

branches/dist-snap/src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use syntax::ast::*;
4646
// & and * pointers
4747
// copies of general constants
4848
//
49-
// (in theory, probably not at first: if/match on integer-const
49+
// (in theory, probably not at first: if/alt on integer-const
5050
// conditions / descriminants)
5151
//
5252
// - Non-constants: everything else.

branches/dist-snap/src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ impl &mem_categorization_ctxt {
904904
// local(x)->@->@
905905
//
906906
// where the id of `local(x)` is the id of the `x` that appears
907-
// in the match, the id of `local(x)->@` is the `@y` pattern,
907+
// in the alt, the id of `local(x)->@` is the `@y` pattern,
908908
// and the id of `local(x)->@->@` is the id of the `y` pattern.
909909

910910

branches/dist-snap/src/librustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct ctxt {
7171
// that when we visit it we can view it as a parent.
7272
root_exprs: HashMap<ast::node_id, ()>,
7373

74-
// The parent scope is the innermost block, statement, call, or match
74+
// The parent scope is the innermost block, statement, call, or alt
7575
// expression during the execution of which the current expression
7676
// will be evaluated. Generally speaking, the innermost parent
7777
// scope is also the closest suitable ancestor in the AST tree.

0 commit comments

Comments
 (0)