Skip to content

Commit 04c66c3

Browse files
committed
Merge remote-tracking branch 'origin/master' into gen
2 parents 5dc9d71 + 942711e commit 04c66c3

File tree

24 files changed

+667
-68
lines changed

24 files changed

+667
-68
lines changed

src/libcore/array.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ macro_rules! array_impls {
124124
}
125125

126126
#[stable(feature = "rust1", since = "1.0.0")]
127+
#[cfg(stage0)]
127128
impl<T:Copy> Clone for [T; $N] {
128129
fn clone(&self) -> [T; $N] {
129130
*self

src/libcore/clone.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
/// }
8989
/// ```
9090
#[stable(feature = "rust1", since = "1.0.0")]
91+
#[cfg_attr(not(stage0), lang = "clone")]
9192
pub trait Clone : Sized {
9293
/// Returns a copy of the value.
9394
///
@@ -131,6 +132,7 @@ pub struct AssertParamIsClone<T: Clone + ?Sized> { _field: ::marker::PhantomData
131132
pub struct AssertParamIsCopy<T: Copy + ?Sized> { _field: ::marker::PhantomData<T> }
132133

133134
#[stable(feature = "rust1", since = "1.0.0")]
135+
#[cfg(stage0)]
134136
impl<'a, T: ?Sized> Clone for &'a T {
135137
/// Returns a shallow copy of the reference.
136138
#[inline]
@@ -140,6 +142,7 @@ impl<'a, T: ?Sized> Clone for &'a T {
140142
macro_rules! clone_impl {
141143
($t:ty) => {
142144
#[stable(feature = "rust1", since = "1.0.0")]
145+
#[cfg(stage0)]
143146
impl Clone for $t {
144147
/// Returns a deep copy of the value.
145148
#[inline]

src/libcore/ptr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool {
876876
}
877877

878878
#[stable(feature = "rust1", since = "1.0.0")]
879+
#[cfg(stage0)]
879880
impl<T: ?Sized> Clone for *const T {
880881
#[inline]
881882
fn clone(&self) -> *const T {
@@ -884,6 +885,7 @@ impl<T: ?Sized> Clone for *const T {
884885
}
885886

886887
#[stable(feature = "rust1", since = "1.0.0")]
888+
#[cfg(stage0)]
887889
impl<T: ?Sized> Clone for *mut T {
888890
#[inline]
889891
fn clone(&self) -> *mut T {
@@ -895,6 +897,7 @@ impl<T: ?Sized> Clone for *mut T {
895897
macro_rules! fnptr_impls_safety_abi {
896898
($FnTy: ty, $($Arg: ident),*) => {
897899
#[stable(feature = "rust1", since = "1.0.0")]
900+
#[cfg(stage0)]
898901
impl<Ret, $($Arg),*> Clone for $FnTy {
899902
#[inline]
900903
fn clone(&self) -> Self {

src/libcore/tuple.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ macro_rules! tuple_impls {
2222
)+) => {
2323
$(
2424
#[stable(feature = "rust1", since = "1.0.0")]
25+
#[cfg(stage0)]
2526
impl<$($T:Clone),+> Clone for ($($T,)+) {
2627
fn clone(&self) -> ($($T,)+) {
2728
($(self.$idx.clone(),)+)

src/librustc/ich/impls_ty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ty::In
677677
def_id.hash_stable(hcx, hasher);
678678
t.hash_stable(hcx, hasher);
679679
}
680+
ty::InstanceDef::CloneShim(def_id, t) => {
681+
def_id.hash_stable(hcx, hasher);
682+
t.hash_stable(hcx, hasher);
683+
}
680684
}
681685
}
682686
}

src/librustc/middle/lang_items.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ language_item_table! {
274274
SizedTraitLangItem, "sized", sized_trait;
275275
UnsizeTraitLangItem, "unsize", unsize_trait;
276276
CopyTraitLangItem, "copy", copy_trait;
277+
CloneTraitLangItem, "clone", clone_trait;
277278
SyncTraitLangItem, "sync", sync_trait;
278279
FreezeTraitLangItem, "freeze", freeze_trait;
279280

src/librustc/traits/select.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
13061306
} else if self.tcx().lang_items.unsize_trait() == Some(def_id) {
13071307
self.assemble_candidates_for_unsizing(obligation, &mut candidates);
13081308
} else {
1309+
if self.tcx().lang_items.clone_trait() == Some(def_id) {
1310+
// Same builtin conditions as `Copy`, i.e. every type which has builtin support
1311+
// for `Copy` also has builtin support for `Clone`, + tuples and arrays of `Clone`
1312+
// types have builtin support for `Clone`.
1313+
let clone_conditions = self.copy_conditions(obligation);
1314+
self.assemble_builtin_bound_candidates(clone_conditions, &mut candidates)?;
1315+
}
1316+
13091317
self.assemble_generator_candidates(obligation, &mut candidates)?;
13101318
self.assemble_closure_candidates(obligation, &mut candidates)?;
13111319
self.assemble_fn_pointer_candidates(obligation, &mut candidates)?;
@@ -2213,8 +2221,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
22132221

22142222
match candidate {
22152223
BuiltinCandidate { has_nested } => {
2216-
Ok(VtableBuiltin(
2217-
self.confirm_builtin_candidate(obligation, has_nested)))
2224+
let data = self.confirm_builtin_candidate(obligation, has_nested);
2225+
Ok(VtableBuiltin(data))
22182226
}
22192227

22202228
ParamCandidate(param) => {
@@ -2326,6 +2334,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
23262334
_ if Some(trait_def) == self.tcx().lang_items.copy_trait() => {
23272335
self.copy_conditions(obligation)
23282336
}
2337+
_ if Some(trait_def) == self.tcx().lang_items.clone_trait() => {
2338+
self.copy_conditions(obligation)
2339+
}
23292340
_ => bug!("unexpected builtin trait {:?}", trait_def)
23302341
};
23312342
let nested = match conditions {
@@ -2346,6 +2357,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
23462357

23472358
debug!("confirm_builtin_candidate: obligations={:?}",
23482359
obligations);
2360+
23492361
VtableBuiltinData { nested: obligations }
23502362
}
23512363

@@ -2687,8 +2699,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26872699

26882700
fn confirm_builtin_unsize_candidate(&mut self,
26892701
obligation: &TraitObligation<'tcx>,)
2690-
-> Result<VtableBuiltinData<PredicateObligation<'tcx>>,
2691-
SelectionError<'tcx>> {
2702+
-> Result<VtableBuiltinData<PredicateObligation<'tcx>>, SelectionError<'tcx>>
2703+
{
26922704
let tcx = self.tcx();
26932705

26942706
// assemble_candidates_for_unsizing should ensure there are no late bound

src/librustc/traits/structural_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::Vtable<'a, ()> {
325325
})
326326
}
327327
traits::VtableParam(n) => Some(traits::VtableParam(n)),
328-
traits::VtableBuiltin(d) => Some(traits::VtableBuiltin(d)),
328+
traits::VtableBuiltin(n) => Some(traits::VtableBuiltin(n)),
329329
traits::VtableObject(traits::VtableObjectData {
330330
upcast_trait_ref,
331331
vtable_base,

src/librustc/ty/instance.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,22 @@ pub struct Instance<'tcx> {
2424
pub enum InstanceDef<'tcx> {
2525
Item(DefId),
2626
Intrinsic(DefId),
27-
// <fn() as FnTrait>::call_*
28-
// def-id is FnTrait::call_*
27+
28+
/// <fn() as FnTrait>::call_*
29+
/// def-id is FnTrait::call_*
2930
FnPtrShim(DefId, Ty<'tcx>),
30-
// <Trait as Trait>::fn
31+
32+
/// <Trait as Trait>::fn
3133
Virtual(DefId, usize),
32-
// <[mut closure] as FnOnce>::call_once
34+
35+
/// <[mut closure] as FnOnce>::call_once
3336
ClosureOnceShim { call_once: DefId },
34-
// drop_in_place::<T>; None for empty drop glue.
37+
38+
/// drop_in_place::<T>; None for empty drop glue.
3539
DropGlue(DefId, Option<Ty<'tcx>>),
40+
41+
/// Builtin method implementation, e.g. `Clone::clone`.
42+
CloneShim(DefId, Ty<'tcx>),
3643
}
3744

3845
impl<'tcx> InstanceDef<'tcx> {
@@ -43,9 +50,9 @@ impl<'tcx> InstanceDef<'tcx> {
4350
InstanceDef::FnPtrShim(def_id, _) |
4451
InstanceDef::Virtual(def_id, _) |
4552
InstanceDef::Intrinsic(def_id, ) |
46-
InstanceDef::ClosureOnceShim { call_once: def_id }
47-
=> def_id,
48-
InstanceDef::DropGlue(def_id, _) => def_id
53+
InstanceDef::ClosureOnceShim { call_once: def_id } |
54+
InstanceDef::DropGlue(def_id, _) |
55+
InstanceDef::CloneShim(def_id, _) => def_id
4956
}
5057
}
5158

@@ -80,6 +87,9 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
8087
InstanceDef::DropGlue(_, ty) => {
8188
write!(f, " - shim({:?})", ty)
8289
}
90+
InstanceDef::CloneShim(_, ty) => {
91+
write!(f, " - shim({:?})", ty)
92+
}
8393
}
8494
}
8595
}

src/librustc/ty/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22362236
ty::InstanceDef::FnPtrShim(..) |
22372237
ty::InstanceDef::Virtual(..) |
22382238
ty::InstanceDef::ClosureOnceShim { .. } |
2239-
ty::InstanceDef::DropGlue(..) => {
2239+
ty::InstanceDef::DropGlue(..) |
2240+
ty::InstanceDef::CloneShim(..) => {
22402241
self.mir_shims(instance)
22412242
}
22422243
}

0 commit comments

Comments
 (0)