Skip to content

Commit c3d49c9

Browse files
sgrifnikomatsakis
authored andcommitted
Further update with response to feedback
1 parent 333a1cd commit c3d49c9

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

src/librustc/traits/select.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17241724
if other.evaluation == EvaluatedToOk {
17251725
if let ImplCandidate(victim_def) = victim.candidate {
17261726
let tcx = self.tcx().global_tcx();
1727-
return traits::specializes(tcx, other_def, victim_def);
1727+
return traits::specializes(tcx, other_def, victim_def) ||
1728+
tcx.impls_are_allowed_to_overlap(other_def, victim_def);
17281729
}
17291730
}
17301731

src/librustc/traits/specialize/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
155155
return r;
156156
}
157157

158-
if tcx.impl_always_allowed_to_overlap(impl1_def_id)
159-
&& tcx.impl_always_allowed_to_overlap(impl2_def_id) {
160-
return true;
161-
}
162-
163158
// The feature gate should prevent introducing new specializations, but not
164159
// taking advantage of upstream ones.
165160
if !tcx.sess.features.borrow().specialization &&

src/librustc/traits/specialize/specialization_graph.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ impl<'a, 'gcx, 'tcx> Children {
113113
possible_sibling,
114114
impl_def_id);
115115
if let Some(impl_header) = overlap {
116-
if tcx.impl_always_allowed_to_overlap(impl_def_id)
117-
&& tcx.impl_always_allowed_to_overlap(possible_sibling) {
118-
return Ok((true, true));
116+
if tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) {
117+
return Ok((false, false));
119118
}
120119

121120
let le = specializes(tcx, impl_def_id, possible_sibling);

src/librustc/ty/mod.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -2158,14 +2158,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
21582158
queries::impl_trait_ref::get(self, DUMMY_SP, id)
21592159
}
21602160

2161-
/// Returns true if the impl is positive and is for a trait which contains
2162-
/// no items
2163-
pub fn impl_always_allowed_to_overlap(self, def_id: DefId) -> bool {
2164-
self.trait_impl_polarity(def_id) == hir::ImplPolarity::Positive
2165-
&& self.impl_trait_ref(def_id)
2166-
.map_or(false, |trait_ref| {
2167-
self.associated_item_def_ids(trait_ref.def_id).is_empty()
2168-
})
2161+
/// Returns true if the impls are the same polarity and are implementing
2162+
/// a trait which contains no items
2163+
pub fn impls_are_allowed_to_overlap(self, def_id1: DefId, def_id2: DefId) -> bool {
2164+
let trait1_is_empty = self.impl_trait_ref(def_id1)
2165+
.map_or(false, |trait_ref| {
2166+
self.associated_item_def_ids(trait_ref.def_id).is_empty()
2167+
});
2168+
let trait2_is_empty = self.impl_trait_ref(def_id2)
2169+
.map_or(false, |trait_ref| {
2170+
self.associated_item_def_ids(trait_ref.def_id).is_empty()
2171+
});
2172+
self.trait_impl_polarity(def_id1) == self.trait_impl_polarity(def_id2)
2173+
&& trait1_is_empty
2174+
&& trait2_is_empty
21692175
}
21702176

21712177
// Returns `ty::VariantDef` if `def` refers to a struct,

src/test/compile-fail/auxiliary/trait_impl_conflict.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
pub trait Foo {
12+
fn foo() {}
1213
}
1314

1415
impl Foo for isize {

0 commit comments

Comments
 (0)