Skip to content

Commit 85914df

Browse files
committed
Disallow coercions from [T, ..n] to &[T]or *[T]
[breaking-change] Insert an `&` to fix
1 parent f092793 commit 85914df

File tree

1 file changed

+0
-50
lines changed

1 file changed

+0
-50
lines changed

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

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
9393
a.repr(self.get_ref().infcx.tcx),
9494
b.repr(self.get_ref().infcx.tcx));
9595

96-
// Special case: if the subtype is a sized array literal (`[T, ..n]`),
97-
// then it would get auto-borrowed to `&[T, ..n]` and then DST-ified
98-
// to `&[T]`. Doing it all at once makes the target code a bit more
99-
// efficient and spares us from having to handle multiple coercions.
100-
match ty::get(b).sty {
101-
ty::ty_ptr(mt_b) | ty::ty_rptr(_, mt_b) => {
102-
match ty::get(mt_b.ty).sty {
103-
ty::ty_vec(_, None) => {
104-
let unsize_and_ref = self.unpack_actual_value(a, |sty_a| {
105-
self.coerce_unsized_with_borrow(a, sty_a, b, mt_b.mutbl)
106-
});
107-
if unsize_and_ref.is_ok() {
108-
return unsize_and_ref;
109-
}
110-
}
111-
_ => {}
112-
}
113-
}
114-
_ => {}
115-
}
116-
11796
// Consider coercing the subtype to a DST
11897
let unsize = self.unpack_actual_value(a, |sty_a| {
11998
self.coerce_unsized(a, sty_a, b)
@@ -274,35 +253,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
274253
})))
275254
}
276255

277-
// [T, ..n] -> &[T] or &mut [T]
278-
fn coerce_unsized_with_borrow(&self,
279-
a: ty::t,
280-
sty_a: &ty::sty,
281-
b: ty::t,
282-
mutbl_b: ast::Mutability)
283-
-> CoerceResult {
284-
debug!("coerce_unsized_with_borrow(a={}, sty_a={}, b={})",
285-
a.repr(self.get_ref().infcx.tcx), sty_a,
286-
b.repr(self.get_ref().infcx.tcx));
287-
288-
match *sty_a {
289-
ty::ty_vec(t_a, Some(len)) => {
290-
let sub = Sub(self.get_ref().clone());
291-
let coercion = Coercion(self.get_ref().trace.clone());
292-
let r_borrow = self.get_ref().infcx.next_region_var(coercion);
293-
let unsized_ty = ty::mk_slice(self.get_ref().infcx.tcx, r_borrow,
294-
mt {ty: t_a, mutbl: mutbl_b});
295-
try!(self.get_ref().infcx.try(|| sub.tys(unsized_ty, b)));
296-
Ok(Some(AdjustDerefRef(AutoDerefRef {
297-
autoderefs: 0,
298-
autoref: Some(ty::AutoPtr(r_borrow,
299-
mutbl_b,
300-
Some(box AutoUnsize(ty::UnsizeLength(len)))))
301-
})))
302-
}
303-
_ => Err(ty::terr_mismatch)
304-
}
305-
}
306256

307257
// &[T, ..n] or &mut [T, ..n] -> &[T]
308258
// or &mut [T, ..n] -> &mut [T]

0 commit comments

Comments
 (0)