Skip to content

Commit e59a458

Browse files
committed
auto merge of #16805 : nick29581/rust/dst-raw, r=nikomatsakis
r? @pnkfelix or @nikomatsakis
2 parents 0ff7bac + 5520ea8 commit e59a458

21 files changed

+413
-76
lines changed

src/librustc/diagnostics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,6 @@ register_diagnostics!(
170170
E0156,
171171
E0157,
172172
E0158,
173-
E0159
173+
E0159,
174+
E0160
174175
)

src/librustc/middle/astencode.rs

+21-4
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
})

src/librustc/middle/expr_use_visitor.rs

+1-1
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

src/librustc/middle/trans/adt.rs

+3-2
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

src/librustc/middle/trans/base.rs

+2-2
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.

src/librustc/middle/trans/consts.rs

+1-1
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).

src/librustc/middle/trans/expr.rs

+2-7
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 {

src/librustc/middle/trans/reflect.rs

+19-3
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 {

src/librustc/middle/trans/type_of.rs

+3-5
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

src/librustc/middle/ty.rs

+21-7
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
}

src/librustc/middle/ty_fold.rs

+4-1
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
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3650,7 +3650,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
36503650
ast::ExprAddrOf(mutbl, ref oprnd) => {
36513651
let expected = expected.only_has_type();
36523652
let hint = expected.map(fcx, |sty| {
3653-
match *sty { ty::ty_rptr(_, ref mt) => ExpectHasType(mt.ty),
3653+
match *sty { ty::ty_rptr(_, ref mt) | ty::ty_ptr(ref mt) => ExpectHasType(mt.ty),
36543654
_ => NoExpectation }
36553655
});
36563656
let lvalue_pref = match mutbl {

src/librustc/middle/typeck/check/regionck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ fn link_autoref(rcx: &Rcx,
13631363
ty::BorrowKind::from_mutbl(m), expr_cmt);
13641364
}
13651365

1366-
ty::AutoUnsafe(_) | ty::AutoUnsizeUniq(_) | ty::AutoUnsize(_) => {}
1366+
ty::AutoUnsafe(..) | ty::AutoUnsizeUniq(_) | ty::AutoUnsize(_) => {}
13671367
}
13681368
}
13691369

src/librustc/middle/typeck/check/vtable.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,13 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
630630

631631
let cx = fcx.ccx;
632632
let check_object_cast = |src_ty: ty::t, target_ty: ty::t| {
633+
debug!("check_object_cast {} to {}",
634+
fcx.infcx().ty_to_string(src_ty),
635+
fcx.infcx().ty_to_string(target_ty));
633636
// Check that a cast is of correct types.
634637
match (&ty::get(target_ty).sty, &ty::get(src_ty).sty) {
635638
(&ty::ty_rptr(_, ty::mt{ty, mutbl}), &ty::ty_rptr(_, mt))
639+
| (&ty::ty_ptr(ty::mt{ty, mutbl}), &ty::ty_rptr(_, mt))
636640
if !mutability_allowed(mt.mutbl, mutbl) => {
637641
match ty::get(ty).sty {
638642
ty::ty_trait(..) => {
@@ -641,7 +645,9 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
641645
_ => {}
642646
}
643647
}
644-
(&ty::ty_uniq(..), &ty::ty_uniq(..) ) => {}
648+
(&ty::ty_uniq(..), &ty::ty_uniq(..) )
649+
| (&ty::ty_ptr(..), &ty::ty_ptr(..) )
650+
| (&ty::ty_ptr(..), &ty::ty_rptr(..)) => {}
645651
(&ty::ty_rptr(r_t, _), &ty::ty_rptr(r_s, _)) => {
646652
infer::mk_subr(fcx.infcx(),
647653
infer::RelateObjectBound(ex.span),
@@ -669,6 +675,16 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
669675
_ => {}
670676
}
671677
}
678+
(&ty::ty_ptr(ty::mt{ty, ..}), _) => {
679+
match ty::get(ty).sty {
680+
ty::ty_trait(..) => {
681+
span_err!(fcx.ccx.tcx.sess, ex.span, E0160,
682+
"can only cast an *-pointer or &-pointer to an *-object, not a {}",
683+
ty::ty_sort_string(fcx.tcx(), src_ty));
684+
}
685+
_ => {}
686+
}
687+
}
672688
_ => {}
673689
}
674690
};
@@ -880,7 +896,8 @@ fn trait_cast_types(fcx: &FnCtxt,
880896
match autoref {
881897
&ty::AutoUnsize(ref k) |
882898
&ty::AutoUnsizeUniq(ref k) => trait_cast_types_unsize(fcx, k, src_ty, sp),
883-
&ty::AutoPtr(_, _, Some(box ref autoref)) => {
899+
&ty::AutoPtr(_, _, Some(box ref autoref)) |
900+
&ty::AutoUnsafe(_, Some(box ref autoref)) => {
884901
trait_cast_types_autoref(fcx, autoref, src_ty, sp)
885902
}
886903
_ => None
@@ -891,7 +908,7 @@ fn trait_cast_types(fcx: &FnCtxt,
891908
&ty::AutoDerefRef(AutoDerefRef{autoref: Some(ref autoref), autoderefs}) => {
892909
let mut derefed_type = src_ty;
893910
for _ in range(0, autoderefs) {
894-
derefed_type = ty::deref(derefed_type, false).unwrap().ty;
911+
derefed_type = ty::deref(derefed_type, true).unwrap().ty;
895912
derefed_type = structurally_resolved_type(fcx, sp, derefed_type)
896913
}
897914
trait_cast_types_autoref(fcx, autoref, derefed_type, sp)

src/librustc/middle/typeck/coherence.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,19 @@ fn get_base_type_def_id(inference_context: &InferCtxt,
157157
ty_unboxed_closure(def_id, _) => {
158158
Some(def_id)
159159
}
160-
ty_rptr(_, ty::mt {ty, ..}) | ty_uniq(ty) => match ty::get(ty).sty {
161-
ty_trait(box ty::TyTrait { def_id, .. }) => {
162-
Some(def_id)
163-
}
164-
_ => {
165-
fail!("get_base_type() returned a type that wasn't an \
166-
enum, struct, or trait");
160+
ty_ptr(ty::mt {ty, ..}) |
161+
ty_rptr(_, ty::mt {ty, ..}) |
162+
ty_uniq(ty) => {
163+
match ty::get(ty).sty {
164+
ty_trait(box ty::TyTrait { def_id, .. }) => {
165+
Some(def_id)
166+
}
167+
_ => {
168+
fail!("get_base_type() returned a type that wasn't an \
169+
enum, struct, or trait");
170+
}
167171
}
168-
},
172+
}
169173
ty_trait(box ty::TyTrait { def_id, .. }) => {
170174
Some(def_id)
171175
}

src/librustc/middle/typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ fn check_method_self_type<RS:RegionScope>(
14011401
ast::SelfExplicit(ref ast_type, _) => {
14021402
let typ = crate_context.to_ty(rs, &**ast_type);
14031403
let base_type = match ty::get(typ).sty {
1404-
ty::ty_rptr(_, tm) => tm.ty,
1404+
ty::ty_ptr(tm) | ty::ty_rptr(_, tm) => tm.ty,
14051405
ty::ty_uniq(typ) => typ,
14061406
_ => typ,
14071407
};

0 commit comments

Comments
 (0)