Skip to content

Commit d215411

Browse files
committed
Make Send/Sync go through the default implementation path
1 parent 1e3ed61 commit d215411

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/librustc/middle/traits/select.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -824,24 +824,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
824824
stack,
825825
&mut candidates));
826826
}
827-
Some(bound @ ty::BoundSend) |
828-
Some(bound @ ty::BoundSync) => {
829-
// Ideally, we shouldn't sepcial case Send/Sync. This will be unified
830-
// as soon as default trait implementations for these traits land.
831-
try!(self.assemble_candidates_from_impls(obligation, &mut candidates));
832-
833-
// No explicit impls were declared for this type, consider the fallback rules.
834-
if candidates.vec.is_empty() && !candidates.ambiguous {
835-
try!(self.assemble_builtin_bound_candidates(bound, stack, &mut candidates));
836-
}
837-
}
838-
839827
Some(bound @ ty::BoundSized) => {
840828
// Sized and Copy are always automatically computed.
841829
try!(self.assemble_builtin_bound_candidates(bound, stack, &mut candidates));
842830
}
843831

844-
None => {
832+
_ => {
845833
// For the time being, we ignore user-defined impls for builtin-bounds, other than
846834
// `Copy`.
847835
// (And unboxed candidates only apply to the Fn/FnMut/etc traits.)
@@ -1149,8 +1137,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11491137
});
11501138
}
11511139

1152-
if ty::trait_has_default_impl(self.tcx(), def_id) {
1153-
candidates.vec.push(DefaultImplCandidate(def_id.clone()))
1140+
match self_ty.sty {
1141+
ty::ty_infer(ty::TyVar(_)) |
1142+
ty::ty_trait(..) => {},
1143+
_ => {
1144+
if ty::trait_has_default_impl(self.tcx(), def_id) {
1145+
candidates.vec.push(DefaultImplCandidate(def_id.clone()))
1146+
}
1147+
}
11541148
}
11551149

11561150
Ok(())
@@ -1179,6 +1173,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11791173

11801174
let poly_trait_ref = match self_ty.sty {
11811175
ty::ty_trait(ref data) => {
1176+
match self.tcx().lang_items.to_builtin_kind(obligation.predicate.def_id()) {
1177+
Some(bound @ ty::BoundSend) | Some(bound @ ty::BoundSync) => {
1178+
if data.bounds.builtin_bounds.contains(&bound) {
1179+
debug!("assemble_candidates_from_object_ty: matched builtin bound, \
1180+
pushing candidate");
1181+
candidates.vec.push(BuiltinCandidate(bound));
1182+
return;
1183+
}
1184+
}
1185+
_ => {}
1186+
}
1187+
11821188
data.principal_trait_ref_with_self_ty(self.tcx(), self_ty)
11831189
}
11841190
ty::ty_infer(ty::TyVar(_)) => {
@@ -1622,13 +1628,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16221628
ty::ty_bare_fn(..) |
16231629
ty::ty_str |
16241630
ty::ty_err |
1631+
ty::ty_param(..) |
16251632
ty::ty_char => {
16261633
Vec::new()
16271634
}
16281635

16291636
ty::ty_trait(..) |
16301637
ty::ty_projection(..) |
1631-
ty::ty_param(..) |
16321638
ty::ty_infer(..) => {
16331639
self.tcx().sess.bug(
16341640
&format!(

src/librustc/middle/ty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6007,7 +6007,10 @@ pub fn trait_default_impl(tcx: &ctxt, trait_def_id: DefId) -> Option<ast::DefId>
60076007
}
60086008

60096009
pub fn trait_has_default_impl(tcx: &ctxt, trait_def_id: DefId) -> bool {
6010-
tcx.default_trait_impls.borrow().contains_key(&trait_def_id)
6010+
match tcx.lang_items.to_builtin_kind(trait_def_id) {
6011+
Some(BoundSend) | Some(BoundSync) => true,
6012+
_ => tcx.default_trait_impls.borrow().contains_key(&trait_def_id)
6013+
}
60116014
}
60126015

60136016
/// Records a trait-to-implementation mapping.

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2989,7 +2989,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29892989
// check for imports shadowing primitive types
29902990
if let ast::ViewPathSimple(ident, _) = view_path.node {
29912991
match self.def_map.borrow().get(&item.id) {
2992-
Some(&DefTy(..)) | Some(&DefStruct(..)) | Some(&DefTrait(..)) | None => {
2992+
Some(&DefTy(..)) | Some(&DefStruct(..)) | Some(&DefaultImpl(..)) | None => {
29932993
self.check_if_primitive_type_name(ident.name, item.span);
29942994
}
29952995
_ => {}

0 commit comments

Comments
 (0)