Skip to content

Commit f425852

Browse files
committed
change overlapping_impls to take a tcx and create the infcx
1 parent 8c8b16e commit f425852

File tree

3 files changed

+66
-72
lines changed

3 files changed

+66
-72
lines changed

src/librustc/traits/coherence.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use ty::{self, Ty, TyCtxt};
1919
use ty::fold::TypeFoldable;
2020
use ty::subst::Subst;
2121

22-
use infer::{InferCtxt, InferOk};
22+
use infer::{InferOk};
2323

2424
/// Whether we do the orphan check relative to this crate or
2525
/// to some remote crate.
@@ -43,8 +43,8 @@ pub struct OverlapResult<'tcx> {
4343
/// If there are types that satisfy both impls, invokes `on_overlap`
4444
/// with a suitably-freshened `ImplHeader` with those types
4545
/// substituted. Otherwise, invokes `no_overlap`.
46-
pub fn overlapping_impls<F1, F2, R>(
47-
infcx: &InferCtxt<'_, '_, '_>,
46+
pub fn overlapping_impls<'gcx, F1, F2, R>(
47+
tcx: TyCtxt<'_, 'gcx, 'gcx>,
4848
impl1_def_id: DefId,
4949
impl2_def_id: DefId,
5050
intercrate_mode: IntercrateMode,
@@ -63,12 +63,14 @@ where
6363
impl2_def_id,
6464
intercrate_mode);
6565

66-
let selcx = &mut SelectionContext::intercrate(infcx, intercrate_mode);
67-
if let Some(r) = overlap(selcx, impl1_def_id, impl2_def_id) {
68-
on_overlap(r)
69-
} else {
70-
no_overlap()
71-
}
66+
tcx.infer_ctxt().enter(|infcx| {
67+
let selcx = &mut SelectionContext::intercrate(&infcx, intercrate_mode);
68+
if let Some(r) = overlap(selcx, impl1_def_id, impl2_def_id) {
69+
on_overlap(r)
70+
} else {
71+
no_overlap()
72+
}
73+
})
7274
}
7375

7476
fn with_fresh_ty_vars<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,

src/librustc/traits/specialize/specialization_graph.rs

+29-33
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,27 @@ impl<'a, 'gcx, 'tcx> Children {
133133
};
134134

135135
let tcx = tcx.global_tcx();
136-
let (le, ge) = tcx.infer_ctxt().enter(|infcx| {
137-
traits::overlapping_impls(
138-
&infcx,
139-
possible_sibling,
140-
impl_def_id,
141-
traits::IntercrateMode::Issue43355,
142-
|overlap| {
143-
if tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) {
144-
return Ok((false, false));
145-
}
146-
147-
let le = tcx.specializes((impl_def_id, possible_sibling));
148-
let ge = tcx.specializes((possible_sibling, impl_def_id));
149-
150-
if le == ge {
151-
Err(overlap_error(overlap))
152-
} else {
153-
Ok((le, ge))
154-
}
155-
},
156-
|| Ok((false, false)),
157-
)
158-
})?;
136+
let (le, ge) = traits::overlapping_impls(
137+
tcx,
138+
possible_sibling,
139+
impl_def_id,
140+
traits::IntercrateMode::Issue43355,
141+
|overlap| {
142+
if tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) {
143+
return Ok((false, false));
144+
}
145+
146+
let le = tcx.specializes((impl_def_id, possible_sibling));
147+
let ge = tcx.specializes((possible_sibling, impl_def_id));
148+
149+
if le == ge {
150+
Err(overlap_error(overlap))
151+
} else {
152+
Ok((le, ge))
153+
}
154+
},
155+
|| Ok((false, false)),
156+
)?;
159157

160158
if le && !ge {
161159
debug!("descending as child of TraitRef {:?}",
@@ -172,16 +170,14 @@ impl<'a, 'gcx, 'tcx> Children {
172170
return Ok(Inserted::Replaced(possible_sibling));
173171
} else {
174172
if !tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) {
175-
tcx.infer_ctxt().enter(|infcx| {
176-
traits::overlapping_impls(
177-
&infcx,
178-
possible_sibling,
179-
impl_def_id,
180-
traits::IntercrateMode::Fixed,
181-
|overlap| last_lint = Some(overlap_error(overlap)),
182-
|| (),
183-
)
184-
});
173+
traits::overlapping_impls(
174+
tcx,
175+
possible_sibling,
176+
impl_def_id,
177+
traits::IntercrateMode::Fixed,
178+
|overlap| last_lint = Some(overlap_error(overlap)),
179+
|| (),
180+
);
185181
}
186182

187183
// no overlap (error bailed already via ?)

src/librustc_typeck/coherence/inherent_impls_overlap.rs

+26-30
Original file line numberDiff line numberDiff line change
@@ -82,41 +82,37 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
8282

8383
for (i, &impl1_def_id) in impls.iter().enumerate() {
8484
for &impl2_def_id in &impls[(i + 1)..] {
85-
let used_to_be_allowed = self.tcx.infer_ctxt().enter(|infcx| {
85+
let used_to_be_allowed = traits::overlapping_impls(
86+
self.tcx,
87+
impl1_def_id,
88+
impl2_def_id,
89+
IntercrateMode::Issue43355,
90+
|overlap| {
91+
self.check_for_common_items_in_impls(
92+
impl1_def_id,
93+
impl2_def_id,
94+
overlap,
95+
false,
96+
);
97+
false
98+
},
99+
|| true,
100+
);
101+
102+
if used_to_be_allowed {
86103
traits::overlapping_impls(
87-
&infcx,
104+
self.tcx,
88105
impl1_def_id,
89106
impl2_def_id,
90-
IntercrateMode::Issue43355,
91-
|overlap| {
92-
self.check_for_common_items_in_impls(
93-
impl1_def_id,
94-
impl2_def_id,
95-
overlap,
96-
false,
97-
);
98-
false
99-
},
100-
|| true,
101-
)
102-
});
103-
104-
if used_to_be_allowed {
105-
self.tcx.infer_ctxt().enter(|infcx| {
106-
traits::overlapping_impls(
107-
&infcx,
107+
IntercrateMode::Fixed,
108+
|overlap| self.check_for_common_items_in_impls(
108109
impl1_def_id,
109110
impl2_def_id,
110-
IntercrateMode::Fixed,
111-
|overlap| self.check_for_common_items_in_impls(
112-
impl1_def_id,
113-
impl2_def_id,
114-
overlap,
115-
true,
116-
),
117-
|| (),
118-
);
119-
});
111+
overlap,
112+
true,
113+
),
114+
|| (),
115+
);
120116
}
121117
}
122118
}

0 commit comments

Comments
 (0)