Skip to content

Commit a8e393b

Browse files
committed
---
yaml --- r: 142718 b: refs/heads/try2 c: 4957414 h: refs/heads/master v: v3
1 parent acaf370 commit a8e393b

File tree

10 files changed

+131
-14
lines changed

10 files changed

+131
-14
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: 663a9597b24f841f44e560e2478225353dbcec30
8+
refs/heads/try2: 495741498cadf0bcf75e9d21fd5dc83d6b471eb6
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ pub fn parse_type_param_def_data(data: &[u8], start: uint,
543543
}
544544

545545
fn parse_type_param_def(st: &mut PState, conv: conv_did) -> ty::TypeParameterDef {
546-
ty::TypeParameterDef {def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
546+
ty::TypeParameterDef {ident: parse_ident(st, ':'),
547+
def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
547548
bounds: @parse_bounds(st, |x,y| conv(x,y))}
548549
}
549550

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: &ty::ParamBounds) {
416416
}
417417

418418
pub fn enc_type_param_def(w: @io::Writer, cx: @ctxt, v: &ty::TypeParameterDef) {
419+
w.write_str(cx.tcx.sess.str_of(v.ident));
420+
w.write_char(':');
419421
w.write_str((cx.ds)(v.def_id));
420422
w.write_char('|');
421423
enc_bounds(w, cx, v.bounds);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl Subst for ty::ParamBounds {
130130
impl Subst for ty::TypeParameterDef {
131131
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::TypeParameterDef {
132132
ty::TypeParameterDef {
133+
ident: self.ident,
133134
def_id: self.def_id,
134135
bounds: self.bounds.subst(tcx, substs)
135136
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ impl ToStr for IntVarValue {
794794
}
795795

796796
pub struct TypeParameterDef {
797+
ident: ast::ident,
797798
def_id: ast::def_id,
798799
bounds: @ParamBounds
799800
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use syntax::print::pprust::{path_to_str, explicit_self_to_str};
5959
use syntax::visit;
6060
use syntax::opt_vec::OptVec;
6161
use syntax::opt_vec;
62+
use syntax::parse::token::special_idents;
6263

6364
pub fn collect_item_types(ccx: @mut CrateCtxt, crate: &ast::crate) {
6465
fn collect_intrinsic_type(ccx: &CrateCtxt,
@@ -318,6 +319,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
318319
let self_trait_def = get_trait_def(ccx, local_def(trait_id));
319320
let self_trait_ref = self_trait_def.trait_ref.subst(tcx, &substs);
320321
new_type_param_defs.push(ty::TypeParameterDef {
322+
ident: special_idents::self_,
321323
def_id: dummy_defid,
322324
bounds: @ty::ParamBounds {
323325
builtin_bounds: ty::EmptyBuiltinBounds(),
@@ -1151,6 +1153,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
11511153
let bounds = @compute_bounds(ccx, rp, generics,
11521154
param_ty, &param.bounds);
11531155
let def = ty::TypeParameterDef {
1156+
ident: param.ident,
11541157
def_id: local_def(param.id),
11551158
bounds: bounds
11561159
};

branches/try2/src/librustc/util/ppaux.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,17 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
435435
ty_infer(infer_ty) => infer_ty.to_str(),
436436
ty_err => ~"[type error]",
437437
ty_param(param_ty {idx: id, def_id: did}) => {
438-
let mut parm = (('T' as uint) + id) as char;
439-
if (parm as uint) > ('Z' as uint) {
440-
parm = (parm as uint - 26) as char;
441-
}
442-
443-
if cx.sess.verbose() {
444-
fmt!("%c:%?", parm, did)
445-
} else {
446-
fmt!("%c", parm)
447-
}
438+
let param_def = cx.ty_param_defs.find(&did.node);
439+
let ident = match param_def {
440+
Some(def) => {
441+
cx.sess.str_of(def.ident).to_owned()
442+
}
443+
None => {
444+
// This should not happen...
445+
fmt!("BUG[%?]", id)
446+
}
447+
};
448+
if !cx.sess.verbose() { ident } else { fmt!("%s:%?", ident, did) }
448449
}
449450
ty_self(*) => ~"Self",
450451
ty_enum(did, ref substs) | ty_struct(did, ref substs) => {

branches/try2/src/libstd/ptr.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use option::{Option, Some, None};
1515
use sys;
1616
use unstable::intrinsics;
1717
use util::swap;
18+
use ops::{Add,Sub};
19+
use num::Int;
1820

1921
#[cfg(not(test))] use cmp::{Eq, Ord};
2022
use uint;
@@ -384,6 +386,46 @@ impl<T> Ord for *const T {
384386
}
385387
}
386388

389+
#[cfg(not(test))]
390+
impl<T, I: Int> Add<I, *T> for *T {
391+
/// Add an integer value to a pointer to get an offset pointer.
392+
/// Is calculated according to the size of the type pointed to.
393+
#[inline]
394+
pub fn add(&self, rhs: &I) -> *T {
395+
self.offset(rhs.to_int() as uint)
396+
}
397+
}
398+
399+
#[cfg(not(test))]
400+
impl<T, I: Int> Sub<I, *T> for *T {
401+
/// Subtract an integer value from a pointer to get an offset pointer.
402+
/// Is calculated according to the size of the type pointed to.
403+
#[inline]
404+
pub fn sub(&self, rhs: &I) -> *T {
405+
self.offset(-rhs.to_int() as uint)
406+
}
407+
}
408+
409+
#[cfg(not(test))]
410+
impl<T, I: Int> Add<I, *mut T> for *mut T {
411+
/// Add an integer value to a pointer to get an offset pointer.
412+
/// Is calculated according to the size of the type pointed to.
413+
#[inline]
414+
pub fn add(&self, rhs: &I) -> *mut T {
415+
self.offset(rhs.to_int() as uint)
416+
}
417+
}
418+
419+
#[cfg(not(test))]
420+
impl<T, I: Int> Sub<I, *mut T> for *mut T {
421+
/// Subtract an integer value from a pointer to get an offset pointer.
422+
/// Is calculated according to the size of the type pointed to.
423+
#[inline]
424+
pub fn sub(&self, rhs: &I) -> *mut T {
425+
self.offset(-rhs.to_int() as uint)
426+
}
427+
}
428+
387429
#[cfg(test)]
388430
pub mod ptr_tests {
389431
use super::*;
@@ -501,6 +543,60 @@ pub mod ptr_tests {
501543
}
502544
}
503545

546+
#[test]
547+
fn test_ptr_addition() {
548+
use vec::raw::*;
549+
550+
unsafe {
551+
let xs = ~[5, ..16];
552+
let mut ptr = to_ptr(xs);
553+
let end = ptr + 16;
554+
555+
while ptr < end {
556+
assert_eq!(*ptr, 5);
557+
ptr = ptr + 1u;
558+
}
559+
560+
let mut xs_mut = xs.clone();
561+
let mut m_ptr = to_mut_ptr(xs_mut);
562+
let m_end = m_ptr + 16i16;
563+
564+
while m_ptr < m_end {
565+
*m_ptr += 5;
566+
m_ptr = m_ptr + 1u8;
567+
}
568+
569+
assert_eq!(xs_mut, ~[10, ..16]);
570+
}
571+
}
572+
573+
#[test]
574+
fn test_ptr_subtraction() {
575+
use vec::raw::*;
576+
577+
unsafe {
578+
let xs = ~[0,1,2,3,4,5,6,7,8,9];
579+
let mut idx = 9i8;
580+
let ptr = to_ptr(xs);
581+
582+
while idx >= 0i8 {
583+
assert_eq!(*(ptr + idx), idx as int);
584+
idx = idx - 1i8;
585+
}
586+
587+
let mut xs_mut = xs.clone();
588+
let mut m_start = to_mut_ptr(xs_mut);
589+
let mut m_ptr = m_start + 9u32;
590+
591+
while m_ptr >= m_start {
592+
*m_ptr += *m_ptr;
593+
m_ptr = m_ptr - 1i8;
594+
}
595+
596+
assert_eq!(xs_mut, ~[0,2,4,6,8,10,12,14,16,18]);
597+
}
598+
}
599+
504600
#[test]
505601
fn test_ptr_array_each_with_len() {
506602
unsafe {

branches/try2/src/libstd/repr.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,13 @@ impl ReprVisitor {
206206
inner: *TyDesc)
207207
-> bool {
208208
let mut p = ptr;
209-
let end = ptr::offset(p, len);
210209
let (sz, al) = unsafe { ((*inner).size, (*inner).align) };
211210
self.writer.write_char('[');
212211
let mut first = true;
213-
while (p as uint) < (end as uint) {
212+
let mut left = len;
213+
// unit structs have 0 size, and don't loop forever.
214+
let dec = if sz == 0 {1} else {sz};
215+
while left > 0 {
214216
if first {
215217
first = false;
216218
} else {
@@ -219,6 +221,7 @@ impl ReprVisitor {
219221
self.write_mut_qualifier(mtbl);
220222
self.visit_ptr_inner(p as *c_void, inner);
221223
p = align(ptr::offset(p, sz) as uint, al) as *u8;
224+
left -= dec;
222225
}
223226
self.writer.write_char(']');
224227
true
@@ -635,4 +638,7 @@ fn test_repr() {
635638
"(10, ~\"hello\")");
636639
exact_test(&(10_u64, ~"hello"),
637640
"(10, ~\"hello\")");
641+
642+
struct Foo;
643+
exact_test(&(~[Foo, Foo, Foo]), "~[{}, {}, {}]");
638644
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Test that we print out the names of type parameters correctly in
2+
// our error messages.
3+
4+
fn foo<Foo, Bar>(x: Foo) -> Bar { x } //~ ERROR expected `Bar` but found `Foo`
5+
6+
fn main() {}

0 commit comments

Comments
 (0)