Skip to content

Commit c81c958

Browse files
sgriffrewsxcv
authored andcommitted
Further update with response to feedback
1 parent ddcca79 commit c81c958

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

src/librustc/traits/select.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17361736
if other.evaluation == EvaluatedToOk {
17371737
if let ImplCandidate(victim_def) = victim.candidate {
17381738
let tcx = self.tcx().global_tcx();
1739-
return traits::specializes(tcx, other_def, victim_def);
1739+
return traits::specializes(tcx, other_def, victim_def) ||
1740+
tcx.impls_are_allowed_to_overlap(other_def, victim_def);
17401741
}
17411742
}
17421743

src/librustc/traits/specialize/mod.rs

Lines changed: 0 additions & 5 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,14 +2227,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22272227
queries::impl_trait_ref::get(self, DUMMY_SP, id)
22282228
}
22292229

2230-
/// Returns true if the impl is positive and is for a trait which contains
2231-
/// no items
2232-
pub fn impl_always_allowed_to_overlap(self, def_id: DefId) -> bool {
2233-
self.trait_impl_polarity(def_id) == hir::ImplPolarity::Positive
2234-
&& self.impl_trait_ref(def_id)
2235-
.map_or(false, |trait_ref| {
2236-
self.associated_item_def_ids(trait_ref.def_id).is_empty()
2237-
})
2230+
/// Returns true if the impls are the same polarity and are implementing
2231+
/// a trait which contains no items
2232+
pub fn impls_are_allowed_to_overlap(self, def_id1: DefId, def_id2: DefId) -> bool {
2233+
let trait1_is_empty = self.impl_trait_ref(def_id1)
2234+
.map_or(false, |trait_ref| {
2235+
self.associated_item_def_ids(trait_ref.def_id).is_empty()
2236+
});
2237+
let trait2_is_empty = self.impl_trait_ref(def_id2)
2238+
.map_or(false, |trait_ref| {
2239+
self.associated_item_def_ids(trait_ref.def_id).is_empty()
2240+
});
2241+
self.trait_impl_polarity(def_id1) == self.trait_impl_polarity(def_id2)
2242+
&& trait1_is_empty
2243+
&& trait2_is_empty
22382244
}
22392245

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

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

Lines changed: 1 addition & 0 deletions
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)