Skip to content

Commit 697c7d0

Browse files
committed
---
yaml --- r: 130134 b: refs/heads/master c: dfbd466 h: refs/heads/master v: v3
1 parent 778ab06 commit 697c7d0

25 files changed

+479
-108
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 7241267b93ea02cc25edda531fdc5b6261a96d01
2+
refs/heads/master: dfbd4669cd0ce6298b5cee7d4b5e1585d8228daa
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 67b97ab6d2b7de9b69fd97dc171fcf8feec932ff
55
refs/heads/try: 28d5878c1f0465c11c8e7a3085008b0c592d48d0

trunk/src/doc/rust.md

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,32 +3668,17 @@ let a: List<int> = Cons(7, box Cons(13, box Nil));
36683668

36693669
All pointers in Rust are explicit first-class values.
36703670
They can be copied, stored into data structures, and returned from functions.
3671-
There are four varieties of pointer in Rust:
3672-
3673-
* Owning pointers (`Box`)
3674-
: These point to owned heap allocations (or "boxes") in the shared, inter-task heap.
3675-
Each owned box has a single owning pointer; pointer and pointee retain a 1:1 relationship at all times.
3676-
Owning pointers are written `Box<content>`,
3677-
for example `Box<int>` means an owning pointer to an owned box containing an integer.
3678-
Copying an owned box is a "deep" operation:
3679-
it involves allocating a new owned box and copying the contents of the old box into the new box.
3680-
Releasing an owning pointer immediately releases its corresponding owned box.
3671+
There are two varieties of pointer in Rust:
36813672

36823673
* References (`&`)
36833674
: These point to memory _owned by some other value_.
3684-
References arise by (automatic) conversion from owning pointers, managed pointers,
3685-
or by applying the borrowing operator `&` to some other value,
3686-
including [lvalues, rvalues or temporaries](#lvalues,-rvalues-and-temporaries).
3687-
A borrow expression is written `&content`.
3688-
3689-
A reference type is written `&'f type` for some lifetime-variable `f`,
3690-
or just `&type` when the lifetime can be elided;
3691-
for example `&int` means a reference to an integer.
3675+
A reference type is written `&type` for some lifetime-variable `f`,
3676+
or just `&'a type` when you need an explicit lifetime.
36923677
Copying a reference is a "shallow" operation:
36933678
it involves only copying the pointer itself.
36943679
Releasing a reference typically has no effect on the value it points to,
3695-
with the exception of temporary values,
3696-
which are released when the last reference to them is released.
3680+
with the exception of temporary values, which are released when the last
3681+
reference to them is released.
36973682

36983683
* Raw pointers (`*`)
36993684
: Raw pointers are pointers without safety or liveness guarantees.
@@ -3706,6 +3691,9 @@ There are four varieties of pointer in Rust:
37063691
they exist to support interoperability with foreign code,
37073692
and writing performance-critical or low-level functions.
37083693

3694+
The standard library contains addtional 'smart pointer' types beyond references
3695+
and raw pointers.
3696+
37093697
### Function types
37103698

37113699
The function type constructor `fn` forms new function types.

trunk/src/libcore/slice.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,15 @@ impl<'a, T> Collection for &'a [T] {
996996
}
997997
}
998998

999+
#[experimental = "trait is experimental"]
1000+
impl<'a, T> Collection for &'a mut [T] {
1001+
/// Returns the length of a vector
1002+
#[inline]
1003+
fn len(&self) -> uint {
1004+
self.repr().len
1005+
}
1006+
}
1007+
9991008
#[unstable = "waiting for DST"]
10001009
impl<'a, T> Default for &'a [T] {
10011010
fn default() -> &'a [T] { &[] }

trunk/src/librustc/diagnostics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,7 @@ register_diagnostics!(
169169
E0155,
170170
E0156,
171171
E0157,
172-
E0158
172+
E0158,
173+
E0159,
174+
E0160
173175
)

trunk/src/librustc/middle/astencode.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,18 @@ impl<'a> rbml_writer_helpers for Encoder<'a> {
10731073
this.emit_enum_variant_arg(0, |this| Ok(this.emit_unsize_kind(ecx, uk)))
10741074
})
10751075
}
1076-
&ty::AutoUnsafe(m) => {
1077-
this.emit_enum_variant("AutoUnsafe", 3, 1, |this| {
1078-
this.emit_enum_variant_arg(0, |this| m.encode(this))
1076+
&ty::AutoUnsafe(m, None) => {
1077+
this.emit_enum_variant("AutoUnsafe", 3, 2, |this| {
1078+
this.emit_enum_variant_arg(0, |this| m.encode(this));
1079+
this.emit_enum_variant_arg(1,
1080+
|this| this.emit_option(|this| this.emit_option_none()))
1081+
})
1082+
}
1083+
&ty::AutoUnsafe(m, Some(box ref a)) => {
1084+
this.emit_enum_variant("AutoUnsafe", 3, 2, |this| {
1085+
this.emit_enum_variant_arg(0, |this| m.encode(this));
1086+
this.emit_enum_variant_arg(1, |this| this.emit_option(
1087+
|this| this.emit_option_some(|this| Ok(this.emit_autoref(ecx, a)))))
10791088
})
10801089
}
10811090
}
@@ -1635,8 +1644,16 @@ impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> {
16351644
3 => {
16361645
let m: ast::Mutability =
16371646
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
1647+
let a: Option<Box<ty::AutoRef>> =
1648+
this.read_enum_variant_arg(1, |this| this.read_option(|this, b| {
1649+
if b {
1650+
Ok(Some(box this.read_autoref(xcx)))
1651+
} else {
1652+
Ok(None)
1653+
}
1654+
})).unwrap();
16381655

1639-
ty::AutoUnsafe(m)
1656+
ty::AutoUnsafe(m, a)
16401657
}
16411658
_ => fail!("bad enum variant for ty::AutoRef")
16421659
})

trunk/src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
762762
ty::BorrowKind::from_mutbl(m),
763763
AutoRef);
764764
}
765-
ty::AutoUnsizeUniq(_) | ty::AutoUnsize(_) | ty::AutoUnsafe(_) => {}
765+
ty::AutoUnsizeUniq(_) | ty::AutoUnsize(_) | ty::AutoUnsafe(..) => {}
766766
}
767767
}
768768

trunk/src/librustc/middle/trans/adt.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,9 @@ impl Case {
296296

297297
for (i, &ty) in self.tys.iter().enumerate() {
298298
match ty::get(ty).sty {
299-
// &T/&mut T could either be a thin or fat pointer depending on T
300-
ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty {
299+
// &T/&mut T/*T could either be a thin or fat pointer depending on T
300+
ty::ty_rptr(_, ty::mt { ty, .. })
301+
| ty::ty_ptr(ty::mt { ty, .. }) => match ty::get(ty).sty {
301302
// &[T] and &str are a pointer and length pair
302303
ty::ty_vec(_, None) | ty::ty_str => return Some(FatPointer(i, slice_elt_base)),
303304

trunk/src/librustc/middle/trans/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,8 @@ pub fn compare_scalar_types<'a>(
566566

567567
match ty::get(t).sty {
568568
ty::ty_nil => f(nil_type),
569-
ty::ty_bool | ty::ty_ptr(_) |
570-
ty::ty_uint(_) | ty::ty_char => f(unsigned_int),
569+
ty::ty_bool | ty::ty_uint(_) | ty::ty_char => f(unsigned_int),
570+
ty::ty_ptr(mt) if ty::type_is_sized(cx.tcx(), mt.ty) => f(unsigned_int),
571571
ty::ty_int(_) => f(signed_int),
572572
ty::ty_float(_) => f(floating_point),
573573
// Should never get here, because t is scalar.

trunk/src/librustc/middle/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
243243
}
244244
Some(ref autoref) => {
245245
match *autoref {
246-
ty::AutoUnsafe(_) |
246+
ty::AutoUnsafe(_, None) |
247247
ty::AutoPtr(ty::ReStatic, _, None) => {
248248
// Don't copy data to do a deref+ref
249249
// (i.e., skip the last auto-deref).

trunk/src/librustc/middle/trans/expr.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,7 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
254254
let mut datum = datum;
255255

256256
let datum = match autoref {
257-
&AutoUnsafe(..) => {
258-
debug!(" AutoUnsafe");
259-
unpack_datum!(bcx, ref_ptr(bcx, expr, datum))
260-
}
261-
&AutoPtr(_, _, ref a) => {
257+
&AutoPtr(_, _, ref a) | &AutoUnsafe(_, ref a) => {
262258
debug!(" AutoPtr");
263259
match a {
264260
&Some(box ref a) => datum = unpack_datum!(bcx,
@@ -1847,8 +1843,7 @@ pub fn cast_type_kind(tcx: &ty::ctxt, t: ty::t) -> cast_kind {
18471843
match ty::get(t).sty {
18481844
ty::ty_char => cast_integral,
18491845
ty::ty_float(..) => cast_float,
1850-
ty::ty_ptr(..) => cast_pointer,
1851-
ty::ty_rptr(_, mt) => {
1846+
ty::ty_rptr(_, mt) | ty::ty_ptr(mt) => {
18521847
if ty::type_is_sized(tcx, mt.ty) {
18531848
cast_pointer
18541849
} else {

trunk/src/librustc/middle/trans/reflect.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
154154
// Unfortunately we can't do anything here because at runtime we
155155
// pass around the value by pointer (*u8). But unsized pointers are
156156
// fat and so we can't just cast them to *u8 and back. So we have
157-
// to work with the pointer directly (see ty_rptr/ty_uniq).
157+
// to work with the pointer directly (see ty_ptr/ty_rptr/ty_uniq).
158158
fail!("Can't reflect unsized type")
159159
}
160160
// FIXME(15049) Reflection for unsized structs.
@@ -177,8 +177,24 @@ impl<'a, 'b> Reflector<'a, 'b> {
177177
self.visit("box", extra.as_slice())
178178
}
179179
ty::ty_ptr(ref mt) => {
180-
let extra = self.c_mt(mt);
181-
self.visit("ptr", extra.as_slice())
180+
match ty::get(mt.ty).sty {
181+
ty::ty_vec(ty, None) => {
182+
let extra = self.c_mt(&ty::mt{ty: ty, mutbl: mt.mutbl});
183+
self.visit("evec_slice", extra.as_slice())
184+
}
185+
ty::ty_str => self.visit("estr_slice", &[]),
186+
ty::ty_trait(..) => {
187+
let extra = [
188+
self.c_slice(token::intern_and_get_ident(
189+
ty_to_string(tcx, t).as_slice()))
190+
];
191+
self.visit("trait", extra);
192+
}
193+
_ => {
194+
let extra = self.c_mt(mt);
195+
self.visit("ptr", extra.as_slice())
196+
}
197+
}
182198
}
183199
ty::ty_uniq(typ) => {
184200
match ty::get(typ).sty {

trunk/src/librustc/middle/trans/type_of.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,8 @@ pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
174174
ty::ty_uint(t) => Type::uint_from_ty(cx, t),
175175
ty::ty_float(t) => Type::float_from_ty(cx, t),
176176

177-
ty::ty_box(..) |
178-
ty::ty_ptr(..) => Type::i8p(cx),
179-
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => {
177+
ty::ty_box(..) => Type::i8p(cx),
178+
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) | ty::ty_ptr(ty::mt{ty, ..}) => {
180179
if ty::type_is_sized(cx.tcx(), ty) {
181180
Type::i8p(cx)
182181
} else {
@@ -303,9 +302,8 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
303302
ty::ty_box(typ) => {
304303
Type::at_box(cx, type_of(cx, typ)).ptr_to()
305304
}
306-
ty::ty_ptr(ref mt) => type_of(cx, mt.ty).ptr_to(),
307305

308-
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => {
306+
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) | ty::ty_ptr(ty::mt{ty, ..}) => {
309307
match ty::get(ty).sty {
310308
ty::ty_str => {
311309
// This means we get a nicer name in the output (str is always

trunk/src/librustc/middle/ty.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ pub enum AutoRef {
298298

299299
/// Convert from T to *T
300300
/// Value to thin pointer
301-
AutoUnsafe(ast::Mutability),
301+
/// The second field allows us to wrap other AutoRef adjustments.
302+
AutoUnsafe(ast::Mutability, Option<Box<AutoRef>>),
302303
}
303304

304305
// Ugly little helper function. The first bool in the returned tuple is true if
@@ -326,6 +327,7 @@ fn autoref_object_region(autoref: &AutoRef) -> (bool, bool, Option<Region>) {
326327
(b, u, Some(adj_r))
327328
}
328329
}
330+
&AutoUnsafe(_, Some(box ref autoref)) => autoref_object_region(autoref),
329331
_ => (false, false, None)
330332
}
331333
}
@@ -380,6 +382,12 @@ pub fn type_of_adjust(cx: &ctxt, adj: &AutoAdjustment) -> Option<t> {
380382
None => None
381383
}
382384
}
385+
&AutoUnsafe(m, Some(box ref autoref)) => {
386+
match type_of_autoref(cx, autoref) {
387+
Some(t) => Some(mk_ptr(cx, mt {mutbl: m, ty: t})),
388+
None => None
389+
}
390+
}
383391
_ => None
384392
}
385393
}
@@ -1898,7 +1906,7 @@ pub fn type_is_self(ty: t) -> bool {
18981906

18991907
fn type_is_slice(ty: t) -> bool {
19001908
match get(ty).sty {
1901-
ty_rptr(_, mt) => match get(mt.ty).sty {
1909+
ty_ptr(mt) | ty_rptr(_, mt) => match get(mt.ty).sty {
19021910
ty_vec(_, None) | ty_str => true,
19031911
_ => false,
19041912
},
@@ -1996,7 +2004,8 @@ pub fn type_is_unique(ty: t) -> bool {
19962004

19972005
pub fn type_is_fat_ptr(cx: &ctxt, ty: t) -> bool {
19982006
match get(ty).sty {
1999-
ty_rptr(_, mt{ty, ..}) | ty_uniq(ty) if !type_is_sized(cx, ty) => true,
2007+
ty_ptr(mt{ty, ..}) | ty_rptr(_, mt{ty, ..})
2008+
| ty_uniq(ty) if !type_is_sized(cx, ty) => true,
20002009
_ => false,
20012010
}
20022011
}
@@ -2896,7 +2905,7 @@ pub fn is_type_representable(cx: &ctxt, sp: Span, ty: t) -> Representability {
28962905

28972906
pub fn type_is_trait(ty: t) -> bool {
28982907
match get(ty).sty {
2899-
ty_uniq(ty) | ty_rptr(_, mt { ty, ..}) => match get(ty).sty {
2908+
ty_uniq(ty) | ty_rptr(_, mt { ty, ..}) | ty_ptr(mt { ty, ..}) => match get(ty).sty {
29002909
ty_trait(..) => true,
29012910
_ => false
29022911
},
@@ -3392,8 +3401,12 @@ pub fn adjust_ty(cx: &ctxt,
33923401
})
33933402
}
33943403

3395-
AutoUnsafe(m) => {
3396-
mk_ptr(cx, mt {ty: ty, mutbl: m})
3404+
AutoUnsafe(m, ref a) => {
3405+
let adjusted_ty = match a {
3406+
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3407+
&None => ty
3408+
};
3409+
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
33973410
}
33983411

33993412
AutoUnsize(ref k) => unsize_ty(cx, ty, k, span),
@@ -3444,7 +3457,8 @@ impl AutoRef {
34443457
ty::AutoPtr(r, m, Some(ref a)) => ty::AutoPtr(f(r), m, Some(box a.map_region(f))),
34453458
ty::AutoUnsize(ref k) => ty::AutoUnsize(k.clone()),
34463459
ty::AutoUnsizeUniq(ref k) => ty::AutoUnsizeUniq(k.clone()),
3447-
ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
3460+
ty::AutoUnsafe(m, None) => ty::AutoUnsafe(m, None),
3461+
ty::AutoUnsafe(m, Some(ref a)) => ty::AutoUnsafe(m, Some(box a.map_region(f))),
34483462
}
34493463
}
34503464
}

trunk/src/librustc/middle/ty_fold.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,10 @@ pub fn super_fold_autoref<T:TypeFolder>(this: &mut T,
466466
ty::AutoPtr(r, m, Some(ref a)) => {
467467
ty::AutoPtr(this.fold_region(r), m, Some(box super_fold_autoref(this, &**a)))
468468
}
469-
ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
469+
ty::AutoUnsafe(m, None) => ty::AutoUnsafe(m, None),
470+
ty::AutoUnsafe(m, Some(ref a)) => {
471+
ty::AutoUnsafe(m, Some(box super_fold_autoref(this, &**a)))
472+
}
470473
ty::AutoUnsize(ref k) => ty::AutoUnsize(k.fold_with(this)),
471474
ty::AutoUnsizeUniq(ref k) => ty::AutoUnsizeUniq(k.fold_with(this)),
472475
}

0 commit comments

Comments
 (0)