Skip to content

Commit 16cefcb

Browse files
committed
---
yaml --- r: 150899 b: refs/heads/try2 c: d35804e h: refs/heads/master i: 150897: 9ee7b9a 150895: 203ffb0 v: v3
1 parent 65ce136 commit 16cefcb

33 files changed

+598
-163
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: 37096730fbcbf2f14990a024fa908a5dc427730d
8+
refs/heads/try2: d35804ea5e69c9a3a8957626533a856f976fe4e3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcollections/bitv.rs

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ impl SmallBitv {
9797
pub fn set_all(&mut self) { self.bits = !0; }
9898

9999
#[inline]
100-
pub fn is_true(&self, nbits: uint) -> bool {
100+
pub fn all(&self, nbits: uint) -> bool {
101101
small_mask(nbits) & !self.bits == 0
102102
}
103103

104104
#[inline]
105-
pub fn is_false(&self, nbits: uint) -> bool {
105+
pub fn none(&self, nbits: uint) -> bool {
106106
small_mask(nbits) & self.bits == 0
107107
}
108108

@@ -412,13 +412,10 @@ impl Bitv {
412412

413413
/// Returns `true` if all bits are 1
414414
#[inline]
415-
pub fn is_true(&self) -> bool {
415+
pub fn all(&self) -> bool {
416416
match self.rep {
417-
Small(ref b) => b.is_true(self.nbits),
418-
_ => {
419-
for i in self.iter() { if !i { return false; } }
420-
true
421-
}
417+
Small(ref b) => b.all(self.nbits),
418+
_ => self.iter().all(|x| x)
422419
}
423420
}
424421

@@ -433,16 +430,19 @@ impl Bitv {
433430
}
434431

435432
/// Returns `true` if all bits are 0
436-
pub fn is_false(&self) -> bool {
433+
pub fn none(&self) -> bool {
437434
match self.rep {
438-
Small(ref b) => b.is_false(self.nbits),
439-
Big(_) => {
440-
for i in self.iter() { if i { return false; } }
441-
true
442-
}
435+
Small(ref b) => b.none(self.nbits),
436+
_ => self.iter().all(|x| !x)
443437
}
444438
}
445439

440+
#[inline]
441+
/// Returns `true` if any bit is 1
442+
pub fn any(&self) -> bool {
443+
!self.none()
444+
}
445+
446446
pub fn init_to_vec(&self, i: uint) -> uint {
447447
return if self.get(i) { 1 } else { 0 };
448448
}
@@ -1551,6 +1551,51 @@ mod tests {
15511551
assert!(b.contains(&1000));
15521552
}
15531553

1554+
#[test]
1555+
fn test_small_bitv_tests() {
1556+
let v = from_bytes([0]);
1557+
assert!(!v.all());
1558+
assert!(!v.any());
1559+
assert!(v.none());
1560+
1561+
let v = from_bytes([0b00010100]);
1562+
assert!(!v.all());
1563+
assert!(v.any());
1564+
assert!(!v.none());
1565+
1566+
let v = from_bytes([0xFF]);
1567+
assert!(v.all());
1568+
assert!(v.any());
1569+
assert!(!v.none());
1570+
}
1571+
1572+
#[test]
1573+
fn test_big_bitv_tests() {
1574+
let v = from_bytes([ // 88 bits
1575+
0, 0, 0, 0,
1576+
0, 0, 0, 0,
1577+
0, 0, 0]);
1578+
assert!(!v.all());
1579+
assert!(!v.any());
1580+
assert!(v.none());
1581+
1582+
let v = from_bytes([ // 88 bits
1583+
0, 0, 0b00010100, 0,
1584+
0, 0, 0, 0b00110100,
1585+
0, 0, 0]);
1586+
assert!(!v.all());
1587+
assert!(v.any());
1588+
assert!(!v.none());
1589+
1590+
let v = from_bytes([ // 88 bits
1591+
0xFF, 0xFF, 0xFF, 0xFF,
1592+
0xFF, 0xFF, 0xFF, 0xFF,
1593+
0xFF, 0xFF, 0xFF]);
1594+
assert!(v.all());
1595+
assert!(v.any());
1596+
assert!(!v.none());
1597+
}
1598+
15541599
fn rng() -> rand::IsaacRng {
15551600
let seed = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
15561601
rand::SeedableRng::from_seed(seed)

branches/try2/src/librustc/metadata/creader.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,6 @@ fn resolve_crate<'a>(e: &mut Env,
300300
dylib, rlib, metadata
301301
} = load_ctxt.load_library_crate(root);
302302

303-
// Claim this crate number and cache it
304-
let cnum = e.next_crate_num;
305-
e.next_crate_num += 1;
306-
307303
// Stash paths for top-most crate locally if necessary.
308304
let crate_paths = if root.is_none() {
309305
Some(CratePaths {
@@ -324,6 +320,17 @@ fn resolve_crate<'a>(e: &mut Env,
324320
@RefCell::new(HashMap::new())
325321
};
326322

323+
// Claim this crate number and cache it if we're linking to the
324+
// crate, otherwise it's a syntax-only crate and we don't need to
325+
// reserve a number
326+
let cnum = if should_link {
327+
let n = e.next_crate_num;
328+
e.next_crate_num += 1;
329+
n
330+
} else {
331+
-1
332+
};
333+
327334
let cmeta = @cstore::crate_metadata {
328335
name: load_ctxt.crate_id.name.to_owned(),
329336
data: metadata,

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,8 +3507,9 @@ impl<'a> Resolver<'a> {
35073507
// its scope.
35083508

35093509
self.resolve_error(span,
3510-
"attempt to use a type \
3511-
argument out of scope");
3510+
"can't use type parameters from \
3511+
outer function; try using a local \
3512+
type parameter instead");
35123513
}
35133514

35143515
return None;
@@ -3530,8 +3531,9 @@ impl<'a> Resolver<'a> {
35303531
// its scope.
35313532

35323533
self.resolve_error(span,
3533-
"attempt to use a type \
3534-
argument out of scope");
3534+
"can't use type parameters from \
3535+
outer function; try using a local \
3536+
type parameter instead");
35353537
}
35363538

35373539
return None;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ impl<'a> TypeFolder for SubstFolder<'a> {
9595
root.repr(self.tcx)),
9696
None => ~""
9797
};
98-
let m = format!("missing type param `{}`{}",
99-
t.repr(self.tcx), root_msg);
98+
let m = format!("can't use type parameters from outer \
99+
function{}; try using a local type \
100+
parameter instead", root_msg);
100101
match self.span {
101102
Some(span) => self.tcx.sess.span_err(span, m),
102103
None => self.tcx.sess.err(m)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
272272
}
273273

274274
// Ugh -- but this ensures any new variants won't be forgotten
275+
ast_map::NodeLifetime(..) |
275276
ast_map::NodeExpr(..) |
276277
ast_map::NodeStmt(..) |
277278
ast_map::NodeArg(..) |

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,13 +2416,13 @@ pub enum Representability {
24162416

24172417
/// Check whether a type is representable. This means it cannot contain unboxed
24182418
/// structural recursion. This check is needed for structs and enums.
2419-
pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
2419+
pub fn is_type_representable(cx: &ctxt, sp: Span, ty: t) -> Representability {
24202420

24212421
// Iterate until something non-representable is found
2422-
fn find_nonrepresentable<It: Iterator<t>>(cx: &ctxt, seen: &mut Vec<DefId>,
2422+
fn find_nonrepresentable<It: Iterator<t>>(cx: &ctxt, sp: Span, seen: &mut Vec<DefId>,
24232423
mut iter: It) -> Representability {
24242424
for ty in iter {
2425-
let r = type_structurally_recursive(cx, seen, ty);
2425+
let r = type_structurally_recursive(cx, sp, seen, ty);
24262426
if r != Representable {
24272427
return r
24282428
}
@@ -2432,7 +2432,7 @@ pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
24322432

24332433
// Does the type `ty` directly (without indirection through a pointer)
24342434
// contain any types on stack `seen`?
2435-
fn type_structurally_recursive(cx: &ctxt, seen: &mut Vec<DefId>,
2435+
fn type_structurally_recursive(cx: &ctxt, sp: Span, seen: &mut Vec<DefId>,
24362436
ty: t) -> Representability {
24372437
debug!("type_structurally_recursive: {}",
24382438
::util::ppaux::ty_to_str(cx, ty));
@@ -2455,19 +2455,19 @@ pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
24552455
match get(ty).sty {
24562456
// Tuples
24572457
ty_tup(ref ts) => {
2458-
find_nonrepresentable(cx, seen, ts.iter().map(|t| *t))
2458+
find_nonrepresentable(cx, sp, seen, ts.iter().map(|t| *t))
24592459
}
24602460
// Fixed-length vectors.
24612461
// FIXME(#11924) Behavior undecided for zero-length vectors.
24622462
ty_vec(ty, VstoreFixed(_)) => {
2463-
type_structurally_recursive(cx, seen, ty)
2463+
type_structurally_recursive(cx, sp, seen, ty)
24642464
}
24652465

24662466
// Push struct and enum def-ids onto `seen` before recursing.
24672467
ty_struct(did, ref substs) => {
24682468
seen.push(did);
24692469
let fields = struct_fields(cx, did, substs);
2470-
let r = find_nonrepresentable(cx, seen,
2470+
let r = find_nonrepresentable(cx, sp, seen,
24712471
fields.iter().map(|f| f.mt.ty));
24722472
seen.pop();
24732473
r
@@ -2478,8 +2478,10 @@ pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
24782478

24792479
let mut r = Representable;
24802480
for variant in vs.iter() {
2481-
let iter = variant.args.iter().map(|aty| subst(cx, substs, *aty));
2482-
r = find_nonrepresentable(cx, seen, iter);
2481+
let iter = variant.args.iter().map(|aty| {
2482+
aty.subst_spanned(cx, substs, Some(sp))
2483+
});
2484+
r = find_nonrepresentable(cx, sp, seen, iter);
24832485

24842486
if r != Representable { break }
24852487
}
@@ -2499,7 +2501,7 @@ pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
24992501
// contains a different, structurally recursive type, maintain a stack
25002502
// of seen types and check recursion for each of them (issues #3008, #3779).
25012503
let mut seen: Vec<DefId> = Vec::new();
2502-
type_structurally_recursive(cx, &mut seen, ty)
2504+
type_structurally_recursive(cx, sp, &mut seen, ty)
25032505
}
25042506

25052507
pub fn type_is_trait(ty: t) -> bool {

branches/try2/src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3356,7 +3356,7 @@ pub fn check_representable(tcx: &ty::ctxt,
33563356
// recursive type. It is only necessary to throw an error on those that
33573357
// contain themselves. For case 2, there must be an inner type that will be
33583358
// caught by case 1.
3359-
match ty::is_type_representable(tcx, rty) {
3359+
match ty::is_type_representable(tcx, sp, rty) {
33603360
ty::SelfRecursive => {
33613361
tcx.sess.span_err(
33623362
sp, format!("illegal recursive {} type; \

branches/try2/src/librustc/middle/typeck/collect.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,24 @@ pub fn ty_generics(ccx: &CrateCtxt,
945945
let param_ty = ty::param_ty {idx: base_index + offset,
946946
def_id: local_def(param.id)};
947947
let bounds = @compute_bounds(ccx, param_ty, &param.bounds);
948-
let default = param.default.map(|x| ast_ty_to_ty(ccx, &ExplicitRscope, x));
948+
let default = param.default.map(|path| {
949+
let ty = ast_ty_to_ty(ccx, &ExplicitRscope, path);
950+
let cur_idx = param_ty.idx;
951+
952+
ty::walk_ty(ty, |t| {
953+
match ty::get(t).sty {
954+
ty::ty_param(p) => if p.idx > cur_idx {
955+
ccx.tcx.sess.span_err(path.span,
956+
"type parameters with a default cannot use \
957+
forward declared identifiers")
958+
},
959+
_ => {}
960+
}
961+
});
962+
963+
ty
964+
});
965+
949966
let def = ty::TypeParameterDef {
950967
ident: param.ident,
951968
def_id: local_def(param.id),

0 commit comments

Comments
 (0)