Skip to content

Commit 6f28acf

Browse files
foobar
1 parent 3e9e574 commit 6f28acf

File tree

2 files changed

+14
-82
lines changed

2 files changed

+14
-82
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+10-70
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc_middle::traits::DefiningAnchor;
2424
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
2525
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
2626
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
27-
use rustc_session::lint::builtin::COINDUCTIVE_OVERLAP_IN_COHERENCE;
2827
use rustc_span::symbol::sym;
2928
use rustc_span::DUMMY_SP;
3029
use std::fmt::Debug;
@@ -191,7 +190,8 @@ fn overlap<'tcx>(
191190
.intercrate(true)
192191
.with_next_trait_solver(tcx.next_trait_solver_in_coherence())
193192
.build();
194-
let selcx = &mut SelectionContext::new(&infcx);
193+
let selcx =
194+
&mut SelectionContext::with_treat_inductive_cycle_as(&infcx, TreatInductiveCycleAs::Ambig);
195195
if track_ambiguity_causes.is_yes() {
196196
selcx.enable_tracking_intercrate_ambiguity_causes();
197197
}
@@ -211,74 +211,14 @@ fn overlap<'tcx>(
211211
debug!("overlap: unification check succeeded");
212212

213213
if overlap_mode.use_implicit_negative() {
214-
for mode in [TreatInductiveCycleAs::Ambig, TreatInductiveCycleAs::Recur] {
215-
if let Some(failing_obligation) = selcx.with_treat_inductive_cycle_as(mode, |selcx| {
216-
impl_intersection_has_impossible_obligation(
217-
selcx,
218-
param_env,
219-
&impl1_header,
220-
&impl2_header,
221-
&equate_obligations,
222-
)
223-
}) {
224-
if matches!(mode, TreatInductiveCycleAs::Recur) {
225-
let first_local_impl = impl1_header
226-
.impl_def_id
227-
.as_local()
228-
.or(impl2_header.impl_def_id.as_local())
229-
.expect("expected one of the impls to be local");
230-
infcx.tcx.struct_span_lint_hir(
231-
COINDUCTIVE_OVERLAP_IN_COHERENCE,
232-
infcx.tcx.local_def_id_to_hir_id(first_local_impl),
233-
infcx.tcx.def_span(first_local_impl),
234-
format!(
235-
"implementations {} will conflict in the future",
236-
match impl1_header.trait_ref {
237-
Some(trait_ref) => {
238-
let trait_ref = infcx.resolve_vars_if_possible(trait_ref);
239-
format!(
240-
"of `{}` for `{}`",
241-
trait_ref.print_only_trait_path(),
242-
trait_ref.self_ty()
243-
)
244-
}
245-
None => format!(
246-
"for `{}`",
247-
infcx.resolve_vars_if_possible(impl1_header.self_ty)
248-
),
249-
},
250-
),
251-
|lint| {
252-
lint.note(
253-
"impls that are not considered to overlap may be considered to \
254-
overlap in the future",
255-
)
256-
.span_label(
257-
infcx.tcx.def_span(impl1_header.impl_def_id),
258-
"the first impl is here",
259-
)
260-
.span_label(
261-
infcx.tcx.def_span(impl2_header.impl_def_id),
262-
"the second impl is here",
263-
);
264-
if !failing_obligation.cause.span.is_dummy() {
265-
lint.span_label(
266-
failing_obligation.cause.span,
267-
format!(
268-
"`{}` may be considered to hold in future releases, \
269-
causing the impls to overlap",
270-
infcx
271-
.resolve_vars_if_possible(failing_obligation.predicate)
272-
),
273-
);
274-
}
275-
lint
276-
},
277-
);
278-
}
279-
280-
return None;
281-
}
214+
if let Some(_failing_obligation) = impl_intersection_has_impossible_obligation(
215+
selcx,
216+
param_env,
217+
&impl1_header,
218+
&impl2_header,
219+
&equate_obligations,
220+
) {
221+
return None;
282222
}
283223
}
284224

compiler/rustc_trait_selection/src/traits/select/mod.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
233233
}
234234

235235
// Sets the `TreatInductiveCycleAs` mode temporarily in the selection context
236-
pub fn with_treat_inductive_cycle_as<T>(
237-
&mut self,
236+
pub fn with_treat_inductive_cycle_as(
237+
infcx: &'cx InferCtxt<'tcx>,
238238
treat_inductive_cycle: TreatInductiveCycleAs,
239-
f: impl FnOnce(&mut Self) -> T,
240-
) -> T {
241-
// Should be executed in a context where caching is disabled,
242-
// otherwise the cache is poisoned with the temporary result.
243-
assert!(self.is_intercrate());
244-
let treat_inductive_cycle =
245-
std::mem::replace(&mut self.treat_inductive_cycle, treat_inductive_cycle);
246-
let value = f(self);
247-
self.treat_inductive_cycle = treat_inductive_cycle;
248-
value
239+
) -> SelectionContext<'cx, 'tcx> {
240+
SelectionContext { treat_inductive_cycle, ..SelectionContext::new(infcx) }
249241
}
250242

251243
pub fn with_query_mode(

0 commit comments

Comments
 (0)