Skip to content

Commit 86d23cb

Browse files
committed
---
yaml --- r: 40513 b: refs/heads/dist-snap c: f841d43 h: refs/heads/master i: 40511: 9f5d114 v: v3
1 parent 91e3edb commit 86d23cb

File tree

14 files changed

+144
-729
lines changed

14 files changed

+144
-729
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: a810c03263670238bccd64cabb12a23a46e3a278
99
refs/heads/incoming: e90142e536c150df0d9b4b2f11352152177509b5
10-
refs/heads/dist-snap: 117e5e35831ded02e71554d2e13d6300215119b0
10+
refs/heads/dist-snap: f841d43f54846111d105dedd046c9646fcce98da
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ fn convert_whence(whence: SeekStyle) -> i32 {
404404
impl *libc::FILE: Reader {
405405
fn read(bytes: &[mut u8], len: uint) -> uint {
406406
do vec::as_mut_buf(bytes) |buf_p, buf_len| {
407-
assert buf_len <= len;
407+
assert buf_len >= len;
408408

409409
let count = libc::fread(buf_p as *mut c_void, 1u as size_t,
410410
len as size_t, self);
@@ -1208,6 +1208,29 @@ mod tests {
12081208
}
12091209
}
12101210

1211+
#[test]
1212+
#[should_fail]
1213+
fn test_read_buffer_too_small() {
1214+
let path = &Path("tmp/lib-io-test-read-buffer-too-small.tmp");
1215+
// ensure the file exists
1216+
io::file_writer(path, [io::Create]).get();
1217+
1218+
let file = io::file_reader(path).get();
1219+
let mut buf = vec::from_elem(5, 0);
1220+
file.read(buf, 6); // this should fail because buf is too small
1221+
}
1222+
1223+
#[test]
1224+
fn test_read_buffer_big_enough() {
1225+
let path = &Path("tmp/lib-io-test-read-buffer-big-enough.tmp");
1226+
// ensure the file exists
1227+
io::file_writer(path, [io::Create]).get();
1228+
1229+
let file = io::file_reader(path).get();
1230+
let mut buf = vec::from_elem(5, 0);
1231+
file.read(buf, 4); // this should succeed because buf is big enough
1232+
}
1233+
12111234
#[test]
12121235
fn test_write_empty() {
12131236
let file = io::file_writer(&Path("tmp/lib-io-test-write-empty.tmp"),

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export expr_is_lval, expr_kind;
4141
export ExprKind, LvalueExpr, RvalueDatumExpr, RvalueDpsExpr, RvalueStmtExpr;
4242
export field_ty;
4343
export fold_ty, fold_sty_to_ty, fold_region, fold_regions;
44-
export apply_op_on_t_to_ty_fn;
4544
export fold_regions_and_ty, walk_regions_and_ty;
4645
export field;
4746
export field_idx, field_idx_strict;
@@ -1483,30 +1482,6 @@ fn fold_regions_and_ty(
14831482
}
14841483
}
14851484

1486-
/* A little utility: it often happens that I have a `fn_ty`,
1487-
* but I want to use some function like `fold_regions_and_ty()`
1488-
* that is defined over all types. This utility converts to
1489-
* a full type and back. It's not the best way to do this (somewhat
1490-
* inefficient to do the conversion), it would be better to refactor
1491-
* all this folding business. However, I've been waiting on that
1492-
* until trait support is improved. */
1493-
fn apply_op_on_t_to_ty_fn(
1494-
cx: ctxt,
1495-
f: &FnTy,
1496-
t_op: fn(t) -> t) -> FnTy
1497-
{
1498-
let t0 = ty::mk_fn(cx, *f);
1499-
let t1 = t_op(t0);
1500-
match ty::get(t1).sty {
1501-
ty::ty_fn(copy f) => {
1502-
move f
1503-
}
1504-
_ => {
1505-
cx.sess.bug(~"`t_op` did not return a function type");
1506-
}
1507-
}
1508-
}
1509-
15101485
// n.b. this function is intended to eventually replace fold_region() below,
15111486
// that is why its name is so similar.
15121487
fn fold_regions(

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -251,29 +251,6 @@ fn require_same_types(
251251
}
252252
}
253253
254-
// a list of mapping from in-scope-region-names ("isr") to the
255-
// corresponding ty::Region
256-
type isr_alist = @List<(ty::bound_region, ty::Region)>;
257-
258-
trait get_and_find_region {
259-
fn get(br: ty::bound_region) -> ty::Region;
260-
fn find(br: ty::bound_region) -> Option<ty::Region>;
261-
}
262-
263-
impl isr_alist: get_and_find_region {
264-
fn get(br: ty::bound_region) -> ty::Region {
265-
self.find(br).get()
266-
}
267-
268-
fn find(br: ty::bound_region) -> Option<ty::Region> {
269-
for list::each(self) |isr| {
270-
let (isr_br, isr_r) = *isr;
271-
if isr_br == br { return Some(isr_r); }
272-
}
273-
return None;
274-
}
275-
}
276-
277254
fn arg_is_argv_ty(tcx: ty::ctxt, a: ty::arg) -> bool {
278255
match ty::resolved_mode(tcx, a.mode) {
279256
ast::by_val => { /*ok*/ }

branches/dist-snap/src/librustc/middle/typeck/check.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,29 @@ fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t,
166166
}
167167
}
168168

169+
// a list of mapping from in-scope-region-names ("isr") to the
170+
// corresponding ty::Region
171+
type isr_alist = @List<(ty::bound_region, ty::Region)>;
172+
173+
trait get_and_find_region {
174+
fn get(br: ty::bound_region) -> ty::Region;
175+
fn find(br: ty::bound_region) -> Option<ty::Region>;
176+
}
177+
178+
impl isr_alist: get_and_find_region {
179+
fn get(br: ty::bound_region) -> ty::Region {
180+
self.find(br).get()
181+
}
182+
183+
fn find(br: ty::bound_region) -> Option<ty::Region> {
184+
for list::each(self) |isr| {
185+
let (isr_br, isr_r) = *isr;
186+
if isr_br == br { return Some(isr_r); }
187+
}
188+
return None;
189+
}
190+
}
191+
169192
fn check_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
170193
let visit = visit::mk_simple_visitor(@{
171194
visit_item: |a| check_item(ccx, a),

branches/dist-snap/src/librustc/middle/typeck/infer.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -722,24 +722,5 @@ impl infer_ctxt {
722722
self.type_error_message(sp, mk_msg, a, Some(err));
723723
}
724724

725-
fn replace_bound_regions_with_fresh_regions(
726-
&self, span: span,
727-
fty: &ty::FnTy) -> (ty::FnTy, isr_alist)
728-
{
729-
let {fn_ty, isr, _} =
730-
replace_bound_regions_in_fn_ty(self.tcx, @Nil, None, fty, |br| {
731-
// N.B.: The name of the bound region doesn't have anything to
732-
// do with the region variable that's created for it. The
733-
// only thing we're doing with `br` here is using it in the
734-
// debug message.
735-
let rvar = self.next_region_var_nb(span);
736-
debug!("Bound region %s maps to %?",
737-
bound_region_to_str(self.tcx, br),
738-
rvar);
739-
rvar
740-
});
741-
(fn_ty, isr)
742-
}
743-
744725
}
745726

branches/dist-snap/src/librustc/middle/typeck/infer/combine.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@ fn super_args<C:combine>(
290290

291291
fn super_vstores<C:combine>(
292292
self: &C, vk: ty::terr_vstore_kind,
293-
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore>
294-
{
295-
debug!("%s.super_vstores(a=%?, b=%?)", self.tag(), a, b);
293+
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> {
296294

297295
match (a, b) {
298296
(ty::vstore_slice(a_r), ty::vstore_slice(b_r)) => {
@@ -519,3 +517,4 @@ fn super_tys<C:combine>(
519517
_ => Err(ty::terr_sorts(expected_found(self, a, b)))
520518
}
521519
}
520+

branches/dist-snap/src/librustc/middle/typeck/infer/lub.rs

Lines changed: 12 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use lattice::*;
33
use to_str::ToStr;
44
use syntax::ast::{Many, Once};
55

6-
fn macros() { include!("macros.rs"); } // FIXME(#3114): Macro import/export.
7-
86
enum Lub = combine_fields; // "subtype", "subregion" etc
97

108
impl Lub: combine {
@@ -104,100 +102,6 @@ impl Lub: combine {
104102
}
105103
}
106104

107-
fn fns(a: &ty::FnTy, b: &ty::FnTy) -> cres<ty::FnTy> {
108-
// Note: this is a subtle algorithm. For a full explanation,
109-
// please see the large comment in `region_inference.rs`.
110-
111-
// Take a snapshot. We'll never roll this back, but in later
112-
// phases we do want to be able to examine "all bindings that
113-
// were created as part of this type comparison", and making a
114-
// snapshot is a convenient way to do that.
115-
let snapshot = self.infcx.region_vars.start_snapshot();
116-
117-
// Instantiate each bound region with a fresh region variable.
118-
let (a_with_fresh, a_isr) =
119-
self.infcx.replace_bound_regions_with_fresh_regions(
120-
self.span, a);
121-
let (b_with_fresh, _) =
122-
self.infcx.replace_bound_regions_with_fresh_regions(
123-
self.span, b);
124-
125-
// Collect constraints.
126-
let fn_ty0 = if_ok!(super_fns(&self, &a_with_fresh, &b_with_fresh));
127-
debug!("fn_ty0 = %s", fn_ty0.to_str(self.infcx));
128-
129-
// Generalize the regions appearing in fn_ty0 if possible
130-
let new_vars =
131-
self.infcx.region_vars.vars_created_since_snapshot(snapshot);
132-
let fn_ty1 =
133-
ty::apply_op_on_t_to_ty_fn(
134-
self.infcx.tcx, &fn_ty0,
135-
|t| ty::fold_regions(
136-
self.infcx.tcx, t,
137-
|r, _in_fn| generalize_region(&self, snapshot,
138-
new_vars, a_isr, r)));
139-
return Ok(move fn_ty1);
140-
141-
fn generalize_region(self: &Lub,
142-
snapshot: uint,
143-
new_vars: &[RegionVid],
144-
a_isr: isr_alist,
145-
r0: ty::Region) -> ty::Region {
146-
// Regions that pre-dated the LUB computation stay as they are.
147-
if !is_new_var(new_vars, r0) {
148-
debug!("generalize_region(r0=%?): not new variable", r0);
149-
return r0;
150-
}
151-
152-
let tainted = self.infcx.region_vars.tainted(snapshot, r0);
153-
154-
// Variables created during LUB computation which are
155-
// *related* to regions that pre-date the LUB computation
156-
// stay as they are.
157-
if !tainted.all(|r| is_new_var(new_vars, *r)) {
158-
debug!("generalize_region(r0=%?): \
159-
non-new-variables found in %?",
160-
r0, tainted);
161-
return r0;
162-
}
163-
164-
// Otherwise, the variable must be associated with at
165-
// least one of the variables representing bound regions
166-
// in both A and B. Replace the variable with the "first"
167-
// bound region from A that we find it to be associated
168-
// with.
169-
for list::each(a_isr) |pair| {
170-
let (a_br, a_r) = *pair;
171-
if tainted.contains(&a_r) {
172-
debug!("generalize_region(r0=%?): \
173-
replacing with %?, tainted=%?",
174-
r0, a_br, tainted);
175-
return ty::re_bound(a_br);
176-
}
177-
}
178-
179-
self.infcx.tcx.sess.span_bug(
180-
self.span,
181-
fmt!("Region %? is not associated with \
182-
any bound region from A!", r0));
183-
}
184-
185-
fn is_new_var(new_vars: &[RegionVid], r: ty::Region) -> bool {
186-
match r {
187-
ty::re_infer(ty::ReVar(ref v)) => new_vars.contains(v),
188-
_ => false
189-
}
190-
}
191-
}
192-
193-
fn fn_metas(a: &ty::FnMeta, b: &ty::FnMeta) -> cres<ty::FnMeta> {
194-
super_fn_metas(&self, a, b)
195-
}
196-
197-
fn fn_sigs(a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig> {
198-
super_fn_sigs(&self, a, b)
199-
}
200-
201105
// Traits please (FIXME: #2794):
202106

203107
fn tys(a: ty::t, b: ty::t) -> cres<ty::t> {
@@ -221,6 +125,18 @@ impl Lub: combine {
221125
super_args(&self, a, b)
222126
}
223127

128+
fn fns(a: &ty::FnTy, b: &ty::FnTy) -> cres<ty::FnTy> {
129+
super_fns(&self, a, b)
130+
}
131+
132+
fn fn_metas(a: &ty::FnMeta, b: &ty::FnMeta) -> cres<ty::FnMeta> {
133+
super_fn_metas(&self, a, b)
134+
}
135+
136+
fn fn_sigs(a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig> {
137+
super_fn_sigs(&self, a, b)
138+
}
139+
224140
fn substs(did: ast::def_id,
225141
as_: &ty::substs,
226142
bs: &ty::substs) -> cres<ty::substs> {

0 commit comments

Comments
 (0)