Skip to content

Commit f7ec95e

Browse files
committed
auto merge of #16917 : nick29581/rust/cross-trait, r=pcwalton
Closes #15349 r? @pcwalton (or anyone else)
2 parents 2e38581 + 7f72884 commit f7ec95e

File tree

14 files changed

+54
-25
lines changed

14 files changed

+54
-25
lines changed

src/librustc/middle/trans/cleanup.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
640640
while !popped_scopes.is_empty() {
641641
let mut scope = popped_scopes.pop().unwrap();
642642

643-
if scope.cleanups.iter().any(|c| cleanup_is_suitable_for(*c, label))
643+
if scope.cleanups.iter().any(|c| cleanup_is_suitable_for(&**c, label))
644644
{
645645
let name = scope.block_name("clean");
646646
debug!("generating cleanups for {}", name);
@@ -649,7 +649,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
649649
None);
650650
let mut bcx_out = bcx_in;
651651
for cleanup in scope.cleanups.iter().rev() {
652-
if cleanup_is_suitable_for(*cleanup, label) {
652+
if cleanup_is_suitable_for(&**cleanup, label) {
653653
bcx_out = cleanup.trans(bcx_out);
654654
}
655655
}

src/librustc/middle/trans/datum.rs

+2
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ impl Datum<Expr> {
451451
name: &str,
452452
expr_id: ast::NodeId)
453453
-> DatumBlock<'a, Lvalue> {
454+
debug!("to_lvalue_datum self: {}", self.to_string(bcx.ccx()));
455+
454456
assert!(ty::lltype_is_sized(bcx.tcx(), self.ty),
455457
"Trying to convert unsized value to lval");
456458
self.match_kind(

src/librustc/middle/trans/expr.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -2061,11 +2061,17 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
20612061
if ty::type_is_sized(bcx.tcx(), content_ty) {
20622062
deref_owned_pointer(bcx, expr, datum, content_ty)
20632063
} else {
2064-
// A fat pointer and an opened DST value have the same represenation
2065-
// just different types.
2066-
DatumBlock::new(bcx, Datum::new(datum.val,
2067-
ty::mk_open(bcx.tcx(), content_ty),
2068-
datum.kind))
2064+
// A fat pointer and an opened DST value have the same
2065+
// represenation just different types. Since there is no
2066+
// temporary for `*e` here (because it is unsized), we cannot
2067+
// emulate the sized object code path for running drop glue and
2068+
// free. Instead, we schedule cleanup for `e`, turning it into
2069+
// an lvalue.
2070+
let datum = unpack_datum!(
2071+
bcx, datum.to_lvalue_datum(bcx, "deref", expr.id));
2072+
2073+
let datum = Datum::new(datum.val, ty::mk_open(bcx.tcx(), content_ty), LvalueExpr);
2074+
DatumBlock::new(bcx, datum)
20692075
}
20702076
}
20712077

@@ -2094,7 +2100,7 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
20942100
// just different types.
20952101
DatumBlock::new(bcx, Datum::new(datum.val,
20962102
ty::mk_open(bcx.tcx(), content_ty),
2097-
datum.kind))
2103+
LvalueExpr))
20982104
}
20992105
}
21002106

src/librustc/middle/typeck/infer/coercion.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ impl<'f> Coerce<'f> {
327327

328328
let sty_b = &ty::get(b).sty;
329329
match (sty_a, sty_b) {
330-
(&ty::ty_uniq(_), &ty::ty_rptr(..)) => Err(ty::terr_mismatch),
331330
(&ty::ty_rptr(_, ty::mt{ty: t_a, ..}), &ty::ty_rptr(_, mt_b)) => {
332331
self.unpack_actual_value(t_a, |sty_a| {
333332
match self.unsize_ty(sty_a, mt_b.ty) {
@@ -511,7 +510,7 @@ impl<'f> Coerce<'f> {
511510
let tcx = self.get_ref().infcx.tcx;
512511

513512
match *sty_a {
514-
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
513+
ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
515514
ty::ty_trait(box ty::TyTrait {
516515
def_id,
517516
ref substs,

src/librustrt/unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) ->
570570
n => {
571571
let f: Callback = unsafe { mem::transmute(n) };
572572
let (file, line) = *file_line;
573-
f(msg, file, line);
573+
f(&*msg, file, line);
574574
}
575575
}
576576
};

src/libstd/failure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn on_fail(obj: &Any + Send, file: &'static str, line: uint) {
8181
"task '{}' failed at '{}', {}:{}\n",
8282
n, msg, file, line);
8383
if backtrace::log_enabled() {
84-
let _ = backtrace::write(stderr);
84+
let _ = backtrace::write(&mut *stderr);
8585
}
8686
local_stderr.replace(Some(stderr));
8787
}

src/libstd/io/stdio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()>) {
203203
let mut my_stdout = local_stdout.replace(None).unwrap_or_else(|| {
204204
box stdout() as Box<Writer + Send>
205205
});
206-
let result = f(my_stdout);
206+
let result = f(&mut *my_stdout);
207207
local_stdout.replace(Some(my_stdout));
208208
result
209209
} else {

src/libsyntax/parse/parser.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl<'a> Parser<'a> {
351351
mut rdr: Box<Reader+'a>)
352352
-> Parser<'a>
353353
{
354-
let tok0 = real_token(rdr);
354+
let tok0 = real_token(&mut *rdr);
355355
let span = tok0.sp;
356356
let placeholder = TokenAndSpan {
357357
tok: token::UNDERSCORE,
@@ -899,7 +899,7 @@ impl<'a> Parser<'a> {
899899
None
900900
};
901901
let next = if self.buffer_start == self.buffer_end {
902-
real_token(self.reader)
902+
real_token(&mut *self.reader)
903903
} else {
904904
// Avoid token copies with `replace`.
905905
let buffer_start = self.buffer_start as uint;
@@ -943,7 +943,7 @@ impl<'a> Parser<'a> {
943943
-> R {
944944
let dist = distance as int;
945945
while self.buffer_length() < dist {
946-
self.buffer[self.buffer_end as uint] = real_token(self.reader);
946+
self.buffer[self.buffer_end as uint] = real_token(&mut *self.reader);
947947
self.buffer_end = (self.buffer_end + 1) & 3;
948948
}
949949
f(&self.buffer[((self.buffer_start + dist - 1) & 3) as uint].tok)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2012-2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
12+
// forbidden when `T` is a trait.
13+
14+
struct Foo;
15+
trait Trait {}
16+
impl Trait for Foo {}
17+
18+
pub fn main() {
19+
let x: Box<Trait> = box Foo;
20+
let _y: &Trait = x; //~ ERROR mismatched types: expected `&Trait`, found `Box<Trait>`
21+
}
22+

src/test/compile-fail/regions-close-object-into-object.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ trait X {}
1616
impl<'a, T> X for B<'a, T> {}
1717

1818
fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
19-
box B(v) as Box<X>
19+
box B(&*v) as Box<X>
2020
}
2121

2222
fn g<'a, T: 'static>(v: Box<A<T>>) -> Box<X+'static> {
23-
box B(v) as Box<X> //~ ERROR cannot infer
23+
box B(&*v) as Box<X> //~ ERROR cannot infer
2424
}
2525

2626
fn h<'a, T, U>(v: Box<A<U>+'static>) -> Box<X+'static> {
27-
box B(v) as Box<X>
27+
box B(&*v) as Box<X>
2828
}
2929

3030
fn i<'a, T, U>(v: Box<A<U>>) -> Box<X+'static> {
31-
box B(v) as Box<X> //~ ERROR cannot infer
31+
box B(&*v) as Box<X> //~ ERROR cannot infer
3232
}
3333

3434
fn main() {}

src/test/run-pass/cleanup-auto-borrow-obj.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Trait for Foo {}
2929

3030
pub fn main() {
3131
{
32-
let _x: &Trait = box Foo as Box<Trait>;
32+
let _x: &Trait = &*(box Foo as Box<Trait>);
3333
}
3434
unsafe {
3535
assert!(DROP_RAN);

src/test/run-pass/issue-3794.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ pub fn main() {
3636
let s: Box<S> = box S { s: 5 };
3737
print_s(&*s);
3838
let t: Box<T> = s as Box<T>;
39-
print_t(t);
39+
print_t(&*t);
4040
}

src/test/run-pass/new-box.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Trait for Struct {
2929

3030
fn g(x: Box<Trait>) {
3131
x.printme();
32-
let y: &Trait = x;
32+
let y: &Trait = &*x;
3333
y.printme();
3434
}
3535

src/test/run-pass/regions-early-bound-trait-param.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ pub fn main() {
120120
assert_eq!(field_invoke2(&s2), 3);
121121

122122
let m : Box<Trait> = make_val();
123-
assert_eq!(object_invoke1(m), (4,5));
124-
assert_eq!(object_invoke2(m), 5);
123+
assert_eq!(object_invoke1(&*m), (4,5));
124+
assert_eq!(object_invoke2(&*m), 5);
125125

126126
// The RefMakerTrait above is pretty strange (i.e. it is strange
127127
// to consume a value of type T and return a &T). Easiest thing

0 commit comments

Comments
 (0)