Skip to content

Commit 8d4ccf9

Browse files
committed
Auto merge of #135524 - lcnr:fix-hang, r=<try>
don't check for overlap if its allowed regardless fixes #135457. I am not a big fan of this tbh, want to figure out why the proof tree visitor is so damn slow here. r? `@compiler-errors`
2 parents 93ba568 + aa75cc2 commit 8d4ccf9

File tree

4 files changed

+67
-51
lines changed

4 files changed

+67
-51
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+33-22
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,39 @@ pub fn overlapping_impls(
116116
return None;
117117
}
118118

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+
}
141152
}
142153

143154
fn fresh_impl_header<'tcx>(infcx: &InferCtxt<'tcx>, impl_def_id: DefId) -> ty::ImplHeader<'tcx> {

compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

+34-25
Original file line numberDiff line numberDiff line change
@@ -138,35 +138,44 @@ impl<'tcx> Children {
138138
};
139139

140140
let last_lint_mut = &mut last_lint;
141-
let (le, ge) = traits::overlapping_impls(
142-
tcx,
143-
possible_sibling,
144-
impl_def_id,
145-
traits::SkipLeakCheck::Yes,
146-
overlap_mode,
147-
)
148-
.map_or(Ok((false, false)), |overlap| {
149-
if let Some(overlap_kind) =
150-
tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling)
151-
{
152-
match overlap_kind {
153-
ty::ImplOverlapKind::Permitted { marker: _ } => {}
154-
ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects => {
155-
*last_lint_mut = Some(FutureCompatOverlapError {
156-
error: create_overlap_error(overlap),
157-
kind: FutureCompatOverlapErrorKind::OrderDepTraitObjects,
158-
});
141+
142+
let overlap_kind = tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling);
143+
let (le, ge) = if let Some(ty::ImplOverlapKind::Permitted { marker: _ }) = overlap_kind
144+
{
145+
(false, false)
146+
} else {
147+
traits::overlapping_impls(
148+
tcx,
149+
possible_sibling,
150+
impl_def_id,
151+
traits::SkipLeakCheck::Yes,
152+
overlap_mode,
153+
)
154+
.map_or(Ok((false, false)), |overlap| {
155+
if let Some(overlap_kind) = overlap_kind {
156+
match overlap_kind {
157+
ty::ImplOverlapKind::Permitted { marker: _ } => {}
158+
ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects => {
159+
*last_lint_mut = Some(FutureCompatOverlapError {
160+
error: create_overlap_error(overlap),
161+
kind: FutureCompatOverlapErrorKind::OrderDepTraitObjects,
162+
});
163+
}
159164
}
160-
}
161165

162-
return Ok((false, false));
163-
}
166+
return Ok((false, false));
167+
}
164168

165-
let le = tcx.specializes((impl_def_id, possible_sibling));
166-
let ge = tcx.specializes((possible_sibling, impl_def_id));
169+
let le = tcx.specializes((impl_def_id, possible_sibling));
170+
let ge = tcx.specializes((possible_sibling, impl_def_id));
167171

168-
if le == ge { report_overlap_error(overlap, last_lint_mut) } else { Ok((le, ge)) }
169-
})?;
172+
if le == ge {
173+
report_overlap_error(overlap, last_lint_mut)
174+
} else {
175+
Ok((le, ge))
176+
}
177+
})?
178+
};
170179

171180
if le && !ge {
172181
debug!(

tests/ui/coherence/occurs-check/associated-type.next.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
22
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
3-
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
4-
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
53
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
64
--> $DIR/associated-type.rs:32:1
75
|

tests/ui/coherence/occurs-check/associated-type.old.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
22
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
3-
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
4-
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
53
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
64
--> $DIR/associated-type.rs:32:1
75
|

0 commit comments

Comments
 (0)