Auto merge of #135618 - lcnr:coherence-unknown, r= · rust-lang/rust@1a372d6 (original) (raw)
`@@ -6,7 +6,7 @@
`
6
6
``
7
7
`use std::fmt::Debug;
`
8
8
``
9
``
`-
use rustc_data_structures::fx::FxIndexSet;
`
``
9
`+
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
`
10
10
`use rustc_errors::{Diag, EmissionGuarantee};
`
11
11
`use rustc_hir::def::DefKind;
`
12
12
`use rustc_hir::def_id::DefId;
`
`@@ -116,28 +116,39 @@ pub fn overlapping_impls(
`
116
116
`return None;
`
117
117
`}
`
118
118
``
119
``
`-
let _overlap_with_bad_diagnostics = overlap(
`
120
``
`-
tcx,
`
121
``
`-
TrackAmbiguityCauses::No,
`
122
``
`-
skip_leak_check,
`
123
``
`-
impl1_def_id,
`
124
``
`-
impl2_def_id,
`
125
``
`-
overlap_mode,
`
126
``
`-
)?;
`
127
``
-
128
``
`-
// In the case where we detect an error, run the check again, but
`
129
``
`-
// this time tracking intercrate ambiguity causes for better
`
130
``
`-
// diagnostics. (These take time and can lead to false errors.)
`
131
``
`-
let overlap = overlap(
`
132
``
`-
tcx,
`
133
``
`-
TrackAmbiguityCauses::Yes,
`
134
``
`-
skip_leak_check,
`
135
``
`-
impl1_def_id,
`
136
``
`-
impl2_def_id,
`
137
``
`-
overlap_mode,
`
138
``
`-
)
`
139
``
`-
.unwrap();
`
140
``
`-
Some(overlap)
`
``
119
`+
if tcx.next_trait_solver_in_coherence() {
`
``
120
`+
overlap(
`
``
121
`+
tcx,
`
``
122
`+
TrackAmbiguityCauses::Yes,
`
``
123
`+
skip_leak_check,
`
``
124
`+
impl1_def_id,
`
``
125
`+
impl2_def_id,
`
``
126
`+
overlap_mode,
`
``
127
`+
)
`
``
128
`+
} else {
`
``
129
`+
let _overlap_with_bad_diagnostics = overlap(
`
``
130
`+
tcx,
`
``
131
`+
TrackAmbiguityCauses::No,
`
``
132
`+
skip_leak_check,
`
``
133
`+
impl1_def_id,
`
``
134
`+
impl2_def_id,
`
``
135
`+
overlap_mode,
`
``
136
`+
)?;
`
``
137
+
``
138
`+
// In the case where we detect an error, run the check again, but
`
``
139
`+
// this time tracking intercrate ambiguity causes for better
`
``
140
`+
// diagnostics. (These take time and can lead to false errors.)
`
``
141
`+
let overlap = overlap(
`
``
142
`+
tcx,
`
``
143
`+
TrackAmbiguityCauses::Yes,
`
``
144
`+
skip_leak_check,
`
``
145
`+
impl1_def_id,
`
``
146
`+
impl2_def_id,
`
``
147
`+
overlap_mode,
`
``
148
`+
)
`
``
149
`+
.unwrap();
`
``
150
`+
Some(overlap)
`
``
151
`+
}
`
141
152
`}
`
142
153
``
143
154
`fn fresh_impl_header<'tcx>(infcx: &InferCtxt<'tcx>, impl_def_id: DefId) -> ty::ImplHeader<'tcx> {
`
`@@ -615,6 +626,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>(
`
615
626
`}
`
616
627
``
617
628
`struct AmbiguityCausesVisitor<'a, 'tcx> {
`
``
629
`+
cache: FxHashSet<Goal<'tcx, ty::Predicate<'tcx>>>,
`
618
630
`causes: &'a mut FxIndexSet<IntercrateAmbiguityCause<'tcx>>,
`
619
631
`}
`
620
632
``
`@@ -624,6 +636,10 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
`
624
636
`}
`
625
637
``
626
638
`fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) {
`
``
639
`+
if !self.cache.insert(goal.goal()) {
`
``
640
`+
return;
`
``
641
`+
}
`
``
642
+
627
643
`let infcx = goal.infcx();
`
628
644
`for cand in goal.candidates() {
`
629
645
` cand.visit_nested_in_probe(self);
`
`@@ -748,5 +764,10 @@ fn search_ambiguity_causes<'tcx>(
`
748
764
`goal: Goal<'tcx, ty::Predicate<'tcx>>,
`
749
765
`causes: &mut FxIndexSet<IntercrateAmbiguityCause<'tcx>>,
`
750
766
`) {
`
751
``
`-
infcx.probe(|_| infcx.visit_proof_tree(goal, &mut AmbiguityCausesVisitor { causes }));
`
``
767
`+
infcx.probe(|_| {
`
``
768
`+
infcx.visit_proof_tree(goal, &mut AmbiguityCausesVisitor {
`
``
769
`+
cache: Default::default(),
`
``
770
`+
causes,
`
``
771
`+
})
`
``
772
`+
});
`
752
773
`}
`