Skip to content

Commit 5d4cce6

Browse files
committed
Rebasing
1 parent db1b14a commit 5d4cce6

File tree

19 files changed

+118
-109
lines changed

19 files changed

+118
-109
lines changed

src/liballoc/rc.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ impl<T: ?Sized> Deref for Rc<T> {
460460
}
461461

462462
#[cfg(stage0)] // SNAP c64d671
463-
#[unsafe_destructor]
464463
#[stable(feature = "rust1", since = "1.0.0")]
465464
impl<T> Drop for Rc<T> {
466465
/// Drops the `Rc<T>`.
@@ -512,7 +511,6 @@ impl<T> Drop for Rc<T> {
512511
}
513512

514513
#[cfg(not(stage0))] // SNAP c64d671
515-
#[unsafe_destructor]
516514
#[stable(feature = "rust1", since = "1.0.0")]
517515
impl<T: ?Sized> Drop for Rc<T> {
518516
/// Drops the `Rc<T>`.
@@ -933,7 +931,6 @@ impl<T: ?Sized> Weak<T> {
933931
}
934932

935933
#[cfg(stage0)] // SNAP c64d671
936-
#[unsafe_destructor]
937934
#[stable(feature = "rust1", since = "1.0.0")]
938935
impl<T> Drop for Weak<T> {
939936
/// Drops the `Weak<T>`.
@@ -979,7 +976,6 @@ impl<T> Drop for Weak<T> {
979976
}
980977

981978
#[cfg(not(stage0))] // SNAP c64d671
982-
#[unsafe_destructor]
983979
#[stable(feature = "rust1", since = "1.0.0")]
984980
impl<T: ?Sized> Drop for Weak<T> {
985981
/// Drops the `Weak<T>`.

src/libcore/cell.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,5 +707,4 @@ impl<T: ?Sized> UnsafeCell<T> {
707707
#![allow(trivial_casts)]
708708
&self.value as *const T as *mut T
709709
}
710-
711710
}

src/libcore/ops.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,24 +1220,33 @@ pub trait CoerceUnsized<T> {
12201220
// Empty.
12211221
}
12221222

1223+
// &mut T -> &mut U
12231224
#[cfg(not(stage0))] // SNAP c64d671
12241225
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
1226+
// &mut T -> &U
12251227
#[cfg(not(stage0))] // SNAP c64d671
12261228
impl<'a, 'b: 'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {}
1229+
// &mut T -> *mut U
12271230
#[cfg(not(stage0))] // SNAP c64d671
12281231
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {}
1232+
// &mut T -> *const U
12291233
#[cfg(not(stage0))] // SNAP c64d671
12301234
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {}
12311235

1236+
// &T -> &U
12321237
#[cfg(not(stage0))] // SNAP c64d671
12331238
impl<'a, 'b: 'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
1239+
// &T -> *const U
12341240
#[cfg(not(stage0))] // SNAP c64d671
12351241
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {}
12361242

1243+
// *mut T -> *mut U
12371244
#[cfg(not(stage0))] // SNAP c64d671
12381245
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
1246+
// *mut T -> *const U
12391247
#[cfg(not(stage0))] // SNAP c64d671
12401248
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
12411249

1250+
// *const T -> *const U
12421251
#[cfg(not(stage0))] // SNAP c64d671
12431252
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}

src/libcoretest/cell.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,15 @@ fn unsafe_cell_unsized() {
172172
assert_eq!(unsafe { &mut *cell.get() }, comp);
173173
}
174174

175-
#[test]
176-
fn refcell_unsized() {
177-
let cell: &RefCell<[i32]> = &RefCell::new([1, 2, 3]);
178-
{
179-
let b = &mut *cell.borrow_mut();
180-
b[0] = 4;
181-
b[2] = 5;
182-
}
183-
let comp: &mut [i32] = &mut [4, 2, 5];
184-
assert_eq!(&*cell.borrow(), comp);
185-
}
175+
// FIXME(#25351) needs deeply nested coercions of DST structs.
176+
// #[test]
177+
// fn refcell_unsized() {
178+
// let cell: &RefCell<[i32]> = &RefCell::new([1, 2, 3]);
179+
// {
180+
// let b = &mut *cell.borrow_mut();
181+
// b[0] = 4;
182+
// b[2] = 5;
183+
// }
184+
// let comp: &mut [i32] = &mut [4, 2, 5];
185+
// assert_eq!(&*cell.borrow(), comp);
186+
// }

src/librustc/diagnostics.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,6 @@ register_diagnostics! {
808808
E0019,
809809
E0022,
810810
E0038,
811-
E0079, // enum variant: expected signed integer constant
812-
E0080, // enum variant: constant evaluation error
813811
E0109,
814812
E0110,
815813
E0134,

src/librustc/middle/traits/select.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13691369
fn assemble_candidates_for_unsizing(&mut self,
13701370
obligation: &TraitObligation<'tcx>,
13711371
candidates: &mut SelectionCandidateSet<'tcx>) {
1372-
// TODO is it Ok to skip the binder here?
1372+
// It is ok to skip past the higher-ranked binders here because the `match`
1373+
// below does not consider regions at all.
13731374
let source = self.infcx.shallow_resolve(*obligation.self_ty().skip_binder());
13741375
let target = self.infcx.shallow_resolve(obligation.predicate.0.input_types()[0]);
13751376

@@ -1494,7 +1495,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14941495
&ClosureCandidate(..) |
14951496
&FnPointerCandidate(..) |
14961497
&BuiltinObjectCandidate(..) |
1497-
&&BuiltinUnsizeCandidate(..) |
1498+
&BuiltinUnsizeCandidate(..) |
14981499
&DefaultImplObjectCandidate(..) |
14991500
&BuiltinCandidate(..) => {
15001501
// We have a where-clause so don't go around looking
@@ -2498,7 +2499,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
24982499
ty::lookup_field_type_unsubstituted(tcx, def_id, f.id)
24992500
}).collect::<Vec<_>>();
25002501

2501-
// The last field of the structure has to exist and be a
2502+
// FIXME(#25351) The last field of the structure has to exist and be a
25022503
// type parameter (for now, to avoid tracking edge cases).
25032504
let i = if let Some(&ty::ty_param(p)) = fields.last().map(|ty| &ty.sty) {
25042505
assert!(p.space == TypeSpace);

src/librustc/middle/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub fn predicate_for_trait_def<'tcx>(
377377
let trait_ref = ty::TraitRef {
378378
def_id: trait_def_id,
379379
substs: tcx.mk_substs(Substs::new_trait(ty_params, vec![], param_ty))
380-
});
380+
};
381381
predicate_for_trait_ref(cause, trait_ref, recursion_depth)
382382
}
383383

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4420,7 +4420,7 @@ pub fn deref<'tcx>(ty: Ty<'tcx>, explicit: bool) -> Option<mt<'tcx>> {
44204420
pub fn type_content<'tcx>(ty: Ty<'tcx>) -> Ty<'tcx> {
44214421
match ty.sty {
44224422
ty_uniq(ty) => ty,
4423-
ty_rptr(_, mt) |ty_ptr(mt) => mt.ty,
4423+
ty_rptr(_, mt) | ty_ptr(mt) => mt.ty,
44244424
_ => ty
44254425
}
44264426
}

src/librustc_trans/trans/debuginfo/metadata.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ impl MetadataCreationResult {
10581058
}
10591059
}
10601060

1061+
#[derive(Debug)]
10611062
enum MemberOffset {
10621063
FixedMemberOffset { bytes: usize },
10631064
// For ComputedMemberOffset, the offset is read from the llvm type definition.
@@ -1066,6 +1067,7 @@ enum MemberOffset {
10661067

10671068
// Description of a type member, which can either be a regular field (as in
10681069
// structs or tuples) or an enum variant.
1070+
#[derive(Debug)]
10691071
struct MemberDescription {
10701072
name: String,
10711073
llvm_type: Type,
@@ -1163,13 +1165,13 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
11631165
span: Span)
11641166
-> RecursiveTypeDescription<'tcx> {
11651167
let struct_name = compute_debuginfo_type_name(cx, struct_type, false);
1166-
let struct_llvm_type = type_of::type_of(cx, struct_type);
1168+
let struct_llvm_type = type_of::in_memory_type_of(cx, struct_type);
11671169

11681170
let (containing_scope, _) = get_namespace_and_span_for_item(cx, def_id);
11691171

11701172
let struct_metadata_stub = create_struct_stub(cx,
11711173
struct_llvm_type,
1172-
&struct_name[..],
1174+
&struct_name,
11731175
unique_type_id,
11741176
containing_scope);
11751177

@@ -1299,7 +1301,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
12991301
set_members_of_composite_type(cx,
13001302
variant_type_metadata,
13011303
variant_llvm_type,
1302-
&member_descriptions[..]);
1304+
&member_descriptions);
13031305
MemberDescription {
13041306
name: "".to_string(),
13051307
llvm_type: variant_llvm_type,

src/librustc_trans/trans/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,11 @@ fn coerce_unsized<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
487487
let trait_substs = Substs::erased(VecPerParamSpace::new(vec![target.ty],
488488
vec![source.ty],
489489
Vec::new()));
490-
let trait_ref = ty::Binder(Rc::new(ty::TraitRef {
490+
let trait_ref = ty::Binder(ty::TraitRef {
491491
def_id: langcall(bcx, Some(span), "coercion",
492492
CoerceUnsizedTraitLangItem),
493493
substs: bcx.tcx().mk_substs(trait_substs)
494-
}));
494+
});
495495

496496
let kind = match fulfill_obligation(bcx.ccx(), span, trait_ref) {
497497
traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => {

src/librustc_typeck/check/cast.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,29 @@ pub fn check_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, cast: &CastCheck<'tcx>) {
6060
let e = &cast.expr;
6161
let t_e = structurally_resolved_type(fcx, span, cast.expr_ty);
6262
let t_1 = structurally_resolved_type(fcx, span, cast.cast_ty);
63+
let tcx = fcx.tcx();
6364

6465
// Check for trivial casts.
6566
if !ty::type_has_ty_infer(t_1) {
6667
if let Ok(()) = coercion::mk_assignty(fcx, e, t_e, t_1) {
6768
if ty::type_is_numeric(t_1) && ty::type_is_numeric(t_e) {
68-
fcx.tcx().sess.add_lint(lint::builtin::TRIVIAL_NUMERIC_CASTS,
69-
e.id,
70-
span,
71-
format!("trivial numeric cast: `{}` as `{}`. Cast can be \
72-
replaced by coercion, this might require type \
73-
ascription or a temporary variable",
74-
fcx.infcx().ty_to_string(t_e),
75-
fcx.infcx().ty_to_string(t_1)));
69+
tcx.sess.add_lint(lint::builtin::TRIVIAL_NUMERIC_CASTS,
70+
e.id,
71+
span,
72+
format!("trivial numeric cast: `{}` as `{}`. Cast can be \
73+
replaced by coercion, this might require type \
74+
ascription or a temporary variable",
75+
fcx.infcx().ty_to_string(t_e),
76+
fcx.infcx().ty_to_string(t_1)));
7677
} else {
77-
fcx.tcx().sess.add_lint(lint::builtin::TRIVIAL_CASTS,
78-
e.id,
79-
span,
80-
format!("trivial cast: `{}` as `{}`. Cast can be \
81-
replaced by coercion, this might require type \
82-
ascription or a temporary variable",
83-
fcx.infcx().ty_to_string(t_e),
84-
fcx.infcx().ty_to_string(t_1)));
78+
tcx.sess.add_lint(lint::builtin::TRIVIAL_CASTS,
79+
e.id,
80+
span,
81+
format!("trivial cast: `{}` as `{}`. Cast can be \
82+
replaced by coercion, this might require type \
83+
ascription or a temporary variable",
84+
fcx.infcx().ty_to_string(t_e),
85+
fcx.infcx().ty_to_string(t_1)));
8586
}
8687
return;
8788
}
@@ -91,14 +92,14 @@ pub fn check_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, cast: &CastCheck<'tcx>) {
9192
let t_e_is_scalar = ty::type_is_scalar(t_e);
9293
let t_e_is_integral = ty::type_is_integral(t_e);
9394
let t_e_is_float = ty::type_is_floating_point(t_e);
94-
let t_e_is_c_enum = ty::type_is_c_like_enum(fcx.tcx(), t_e);
95+
let t_e_is_c_enum = ty::type_is_c_like_enum(tcx, t_e);
9596

9697
let t_1_is_scalar = ty::type_is_scalar(t_1);
9798
let t_1_is_integral = ty::type_is_integral(t_1);
9899
let t_1_is_char = ty::type_is_char(t_1);
99100
let t_1_is_bare_fn = ty::type_is_bare_fn(t_1);
100101
let t_1_is_float = ty::type_is_floating_point(t_1);
101-
let t_1_is_c_enum = ty::type_is_c_like_enum(fcx.tcx(), t_1);
102+
let t_1_is_c_enum = ty::type_is_c_like_enum(tcx, t_1);
102103
let t1_is_fat_ptr = fcx.type_is_fat_ptr(t_1, span);
103104

104105
// casts to scalars other than `char` and `bare fn` are trivial
@@ -114,7 +115,7 @@ pub fn check_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, cast: &CastCheck<'tcx>) {
114115
}, t_e, None);
115116
}
116117
} else if t_1.sty == ty::ty_bool {
117-
span_err!(fcx.tcx().sess, span, E0054,
118+
span_err!(tcx.sess, span, E0054,
118119
"cannot cast as `bool`, compare with zero instead");
119120
} else if t_e_is_float && (t_1_is_scalar || t_1_is_c_enum) &&
120121
!(t_1_is_integral || t_1_is_float) {
@@ -174,12 +175,16 @@ pub fn check_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, cast: &CastCheck<'tcx>) {
174175
} else if t1_is_fat_ptr {
175176
// FIXME This should be allowed where the lefthandside is also a fat
176177
// pointer and is the same kind of fat pointer, i.e., array to array,
177-
// trait object to trait object.
178-
fcx.type_error_message(span, |actual| {
179-
format!("cast to fat pointer: `{}` as `{}`",
180-
actual,
181-
fcx.infcx().ty_to_string(t_1))
182-
}, t_e, None);
178+
// trait object to trait object. That is a bit looser than the current
179+
// rquirement that they are pointers to the same type.
180+
if !(fcx.type_is_fat_ptr(t_e, span) &&
181+
ty::deref(t_1, true).unwrap().ty == ty::deref(t_e, true).unwrap().ty) {
182+
fcx.type_error_message(span, |actual| {
183+
format!("cast to fat pointer: `{}` as `{}`",
184+
actual,
185+
fcx.infcx().ty_to_string(t_1))
186+
}, t_e, None);
187+
}
183188
} else if !(t_e_is_scalar && t_1_is_trivial) {
184189
fcx.type_error_message(span, |actual| {
185190
format!("non-scalar cast: `{}` as `{}`",

src/librustc_typeck/check/coercion.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,19 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
285285

286286
// Create an obligation for `Source: CoerceUnsized<Target>`.
287287
let cause = ObligationCause::misc(self.origin.span(), self.fcx.body_id);
288-
queue.push_back(predicate_for_trait_def(self.tcx(), cause, coerce_unsized_did,
289-
0, source, vec![target]));
288+
queue.push_back(predicate_for_trait_def(self.tcx(),
289+
cause,
290+
coerce_unsized_did,
291+
0,
292+
source,
293+
vec![target]));
290294

291295
// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
292296
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
293297
// inference might unify those two inner type variables later.
294298
let traits = [coerce_unsized_did, unsize_did];
295299
while let Some(obligation) = queue.pop_front() {
300+
debug!("coerce_unsized resolve step: {}", obligation.repr(self.tcx()));
296301
let trait_ref = match obligation.predicate {
297302
ty::Predicate::Trait(ref tr) if traits.contains(&tr.def_id()) => {
298303
tr.clone()
@@ -305,6 +310,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
305310
match selcx.select(&obligation.with(trait_ref)) {
306311
// Uncertain or unimplemented.
307312
Ok(None) | Err(traits::Unimplemented) => {
313+
debug!("coerce_unsized: early return - can't prove obligation");
308314
return Err(ty::terr_mismatch);
309315
}
310316

src/librustc_typeck/check/regionck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
use astconv::AstConv;
8686
use check::dropck;
8787
use check::FnCtxt;
88+
use middle::free_region::FreeRegionMap;
8889
use middle::implicator;
8990
use middle::mem_categorization as mc;
9091
use middle::region::CodeExtent;

0 commit comments

Comments
 (0)