Skip to content

Commit 3dff9bf

Browse files
committed
---
yaml --- r: 187627 b: refs/heads/tmp c: a962d47 h: refs/heads/master i: 187625: ad4f010 187623: 7213d93 v: v3
1 parent 6cd5cf4 commit 3dff9bf

File tree

11 files changed

+76
-9
lines changed

11 files changed

+76
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 4148d5361a7d0ace1cf3b64d07c6252bbce087af
37+
refs/heads/tmp: a962d47ef8a93ad125571a5628a883d0b50a97e7
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/tmp/src/librustc/metadata/csearch.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,7 @@ pub fn is_associated_type(cstore: &cstore::CStore, def: ast::DefId) -> bool {
410410
decoder::is_associated_type(&*cdata, def.node)
411411
}
412412

413+
pub fn is_default_trait(cstore: &cstore::CStore, def: ast::DefId) -> bool {
414+
let cdata = cstore.get_crate_data(def.krate);
415+
decoder::is_default_trait(&*cdata, def.node)
416+
}

branches/tmp/src/librustc/metadata/decoder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,3 +1563,12 @@ pub fn is_associated_type(cdata: Cmd, id: ast::NodeId) -> bool {
15631563
Some(item) => item_sort(item) == 't',
15641564
}
15651565
}
1566+
1567+
1568+
pub fn is_default_trait<'tcx>(cdata: Cmd, id: ast::NodeId) -> bool {
1569+
let item_doc = lookup_item(id, cdata.data());
1570+
match item_family(item_doc) {
1571+
Family::DefTrait => true,
1572+
_ => false
1573+
}
1574+
}

branches/tmp/src/librustc/middle/traits/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ pub enum Vtable<'tcx, N> {
221221
/// Vtable identifying a particular impl.
222222
VtableImpl(VtableImplData<'tcx, N>),
223223

224+
/// Vtable for default trait implementations
225+
VtableDefaultTrait(ast::DefId),
226+
224227
/// Successful resolution to an obligation provided by the caller
225228
/// for some type parameter. The `Vec<N>` represents the
226229
/// obligations incurred from normalizing the where-clause (if
@@ -513,17 +516,18 @@ impl<'tcx, N> Vtable<'tcx, N> {
513516
pub fn iter_nested(&self) -> Iter<N> {
514517
match *self {
515518
VtableImpl(ref i) => i.iter_nested(),
516-
VtableFnPointer(..) => (&[]).iter(),
517-
VtableClosure(..) => (&[]).iter(),
518519
VtableParam(ref n) => n.iter(),
519-
VtableObject(_) => (&[]).iter(),
520520
VtableBuiltin(ref i) => i.iter_nested(),
521+
VtableObject(_) |
522+
VtableDefaultTrait(..) | VtableFnPointer(..) |
523+
VtableClosure(..) => (&[]).iter(),
521524
}
522525
}
523526

524527
pub fn map_nested<M, F>(&self, op: F) -> Vtable<'tcx, M> where F: FnMut(&N) -> M {
525528
match *self {
526529
VtableImpl(ref i) => VtableImpl(i.map_nested(op)),
530+
VtableDefaultTrait(t) => VtableDefaultTrait(t),
527531
VtableFnPointer(ref sig) => VtableFnPointer((*sig).clone()),
528532
VtableClosure(d, ref s) => VtableClosure(d, s.clone()),
529533
VtableParam(ref n) => VtableParam(n.iter().map(op).collect()),
@@ -539,6 +543,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
539543
VtableImpl(i) => VtableImpl(i.map_move_nested(op)),
540544
VtableFnPointer(sig) => VtableFnPointer(sig),
541545
VtableClosure(d, s) => VtableClosure(d, s),
546+
VtableDefaultTrait(t) => VtableDefaultTrait(t),
542547
VtableParam(n) => VtableParam(n.into_iter().map(op).collect()),
543548
VtableObject(p) => VtableObject(p),
544549
VtableBuiltin(no) => VtableBuiltin(no.map_move_nested(op)),

branches/tmp/src/librustc/middle/traits/project.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ fn assemble_candidates_from_impls<'cx,'tcx>(
709709
// projection. And the projection where clause is handled
710710
// in `assemble_candidates_from_param_env`.
711711
}
712+
super::VtableDefaultTrait(..) |
712713
super::VtableBuiltin(..) => {
713714
// These traits have no associated types.
714715
selcx.tcx().sess.span_bug(

branches/tmp/src/librustc/middle/traits/select.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use super::{SelectionError, Unimplemented, Overflow, OutputTypeParameterMismatch
2626
use super::{Selection};
2727
use super::{SelectionResult};
2828
use super::{VtableBuiltin, VtableImpl, VtableParam, VtableClosure,
29-
VtableFnPointer, VtableObject};
29+
VtableFnPointer, VtableObject, VtableDefaultTrait};
3030
use super::{VtableImplData, VtableObjectData, VtableBuiltinData};
3131
use super::object_safety;
3232
use super::{util};
@@ -136,6 +136,7 @@ enum SelectionCandidate<'tcx> {
136136
BuiltinCandidate(ty::BuiltinBound),
137137
ParamCandidate(ty::PolyTraitRef<'tcx>),
138138
ImplCandidate(ast::DefId),
139+
DefaultTraitCandidate(ast::DefId),
139140

140141
/// This is a trait matching with a projected type as `Self`, and
141142
/// we found an applicable bound in the trait definition.
@@ -1130,7 +1131,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11301131
let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
11311132
debug!("assemble_candidates_from_impls(self_ty={})", self_ty.repr(self.tcx()));
11321133

1133-
let all_impls = self.all_impls(obligation.predicate.def_id());
1134+
let def_id = obligation.predicate.def_id();
1135+
let all_impls = self.all_impls(def_id);
11341136
for &impl_def_id in &all_impls {
11351137
self.infcx.probe(|snapshot| {
11361138
let (skol_obligation_trait_pred, skol_map) =
@@ -1144,6 +1146,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11441146
}
11451147
});
11461148
}
1149+
1150+
if self.tcx().default_trait_impls.borrow().contains(&def_id) {
1151+
candidates.vec.push(DefaultTraitCandidate(def_id.clone()))
1152+
}
1153+
11471154
Ok(())
11481155
}
11491156

@@ -1646,6 +1653,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16461653
Ok(VtableParam(obligations))
16471654
}
16481655

1656+
DefaultTraitCandidate(trait_def_id) => {
1657+
Ok(VtableDefaultTrait(trait_def_id))
1658+
}
1659+
16491660
ImplCandidate(impl_def_id) => {
16501661
let vtable_impl =
16511662
try!(self.confirm_impl_candidate(obligation, impl_def_id));
@@ -2308,6 +2319,7 @@ impl<'tcx> Repr<'tcx> for SelectionCandidate<'tcx> {
23082319
BuiltinCandidate(b) => format!("BuiltinCandidate({:?})", b),
23092320
ParamCandidate(ref a) => format!("ParamCandidate({})", a.repr(tcx)),
23102321
ImplCandidate(a) => format!("ImplCandidate({})", a.repr(tcx)),
2322+
DefaultTraitCandidate(t) => format!("DefaultTraitCandidate({:?})", t),
23112323
ProjectionCandidate => format!("ProjectionCandidate"),
23122324
FnPointerCandidate => format!("FnPointerCandidate"),
23132325
ObjectCandidate => {

branches/tmp/src/librustc/middle/traits/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ impl<'tcx, N:Repr<'tcx>> Repr<'tcx> for super::Vtable<'tcx, N> {
444444
super::VtableImpl(ref v) =>
445445
v.repr(tcx),
446446

447+
super::VtableDefaultTrait(ref t) =>
448+
format!("VtableDefaultTrait({:?})", t),
449+
447450
super::VtableClosure(ref d, ref s) =>
448451
format!("VtableClosure({},{})",
449452
d.repr(tcx),

branches/tmp/src/librustc/middle/ty.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,9 @@ pub struct ctxt<'tcx> {
757757
/// Maps a trait onto a list of impls of that trait.
758758
pub trait_impls: RefCell<DefIdMap<Rc<RefCell<Vec<ast::DefId>>>>>,
759759

760+
/// Maps a trait onto a list of *default* trait implementations
761+
pub default_trait_impls: RefCell<DefIdSet>,
762+
760763
/// Maps a DefId of a type to a list of its inherent impls.
761764
/// Contains implementations of methods that are inherent to a type.
762765
/// Methods in these implementations don't need to be exported.
@@ -2493,6 +2496,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
24932496
destructor_for_type: RefCell::new(DefIdMap()),
24942497
destructors: RefCell::new(DefIdSet()),
24952498
trait_impls: RefCell::new(DefIdMap()),
2499+
default_trait_impls: RefCell::new(DefIdSet()),
24962500
inherent_impls: RefCell::new(DefIdMap()),
24972501
impl_items: RefCell::new(DefIdMap()),
24982502
used_unsafe: RefCell::new(NodeSet()),
@@ -5992,6 +5996,18 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
59925996
|| Rc::new(csearch::get_item_variances(&tcx.sess.cstore, item_id)))
59935997
}
59945998

5999+
/// Records a trait-to-implementation mapping.
6000+
pub fn record_default_trait_implementation(tcx: &ctxt, trait_def_id: DefId) {
6001+
6002+
//assert!(did.krate != ast::LOCAL_CRATE);
6003+
if tcx.default_trait_impls.borrow().contains(&trait_def_id) {
6004+
return;
6005+
}
6006+
6007+
tcx.default_trait_impls.borrow_mut().insert(trait_def_id);
6008+
}
6009+
6010+
59956011
/// Records a trait-to-implementation mapping.
59966012
pub fn record_trait_implementation(tcx: &ctxt,
59976013
trait_def_id: DefId,
@@ -6074,11 +6090,21 @@ pub fn populate_implementations_for_trait_if_necessary(
60746090
}
60756091

60766092
csearch::each_implementation_for_trait(&tcx.sess.cstore, trait_id,
6077-
|implementation_def_id| {
6093+
|implementation_def_id|{
60786094
let impl_items = csearch::get_impl_items(&tcx.sess.cstore, implementation_def_id);
60796095

6080-
// Record the trait->implementation mapping.
6081-
record_trait_implementation(tcx, trait_id, implementation_def_id);
6096+
if csearch::is_default_trait(&tcx.sess.cstore, implementation_def_id) {
6097+
record_default_trait_implementation(tcx, trait_id);
6098+
tcx.populated_external_traits.borrow_mut().insert(trait_id);
6099+
6100+
// Nothing else to do for default trait implementations since
6101+
// they are not allowed to have type parameters, methods, or any
6102+
// other item that could be associated to a trait implementation.
6103+
return;
6104+
} else {
6105+
// Record the trait->implementation mapping.
6106+
record_trait_implementation(tcx, trait_id, implementation_def_id);
6107+
}
60826108

60836109
// For any methods that use a default implementation, add them to
60846110
// the map. This is a bit unfortunate.

branches/tmp/src/librustc/middle/ty_fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Vtable<'tcx, N>
519519
fn fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::Vtable<'tcx, N> {
520520
match *self {
521521
traits::VtableImpl(ref v) => traits::VtableImpl(v.fold_with(folder)),
522+
traits::VtableDefaultTrait(t) => traits::VtableDefaultTrait(t),
522523
traits::VtableClosure(d, ref s) => {
523524
traits::VtableClosure(d, s.fold_with(folder))
524525
}

branches/tmp/src/librustc_trans/trans/meth.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ fn trans_monomorphized_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
390390
Callee { bcx: bcx, data: Fn(llfn) }
391391
}
392392
traits::VtableBuiltin(..) |
393+
traits::VtableDefaultTrait(..) |
393394
traits::VtableParam(..) => {
394395
bcx.sess().bug(
395396
&format!("resolved vtable bad vtable {} in trans",
@@ -714,6 +715,8 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
714715
let methods = traits::supertraits(tcx, trait_ref.clone()).flat_map(|trait_ref| {
715716
let vtable = fulfill_obligation(ccx, DUMMY_SP, trait_ref.clone());
716717
match vtable {
718+
// Should default trait error here?
719+
traits::VtableDefaultTrait(_) |
717720
traits::VtableBuiltin(_) => {
718721
Vec::new().into_iter()
719722
}

branches/tmp/src/librustc_typeck/collect.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,10 @@ fn convert_item(ccx: &CollectCtxt, it: &ast::Item) {
649649
&enum_definition.variants);
650650
},
651651
ast::ItemDefTrait(_, ref ast_trait_ref) => {
652+
let trait_ref = astconv::instantiate_trait_ref(ccx, &ExplicitRscope,
653+
ast_trait_ref, None, None);
652654

655+
ty::record_default_trait_implementation(tcx, trait_ref.def_id)
653656
}
654657
ast::ItemImpl(_, _,
655658
ref generics,

0 commit comments

Comments
 (0)