Skip to content

Commit 6b771f6

Browse files
committed
Auto merge of #117878 - gavinleroy:proper-depth-check, r=lcnr
Fix depth check in ProofTreeVisitor. The hack to cutoff overflows and cycles in the new trait solver was incorrect. We want to inspect everything with depth [0..10]. This fix exposed a previously unseen bug, which caused the compiler to ICE when invoking `trait_ref` on a non-assoc type projection. I simply added the guard in the `AmbiguityCausesVisitor`, and updated the expected output for the `auto-trait-coherence` test which now includes the extra note: ```text | = note: upstream crates may add a new impl of trait `std::marker::Send` for type `OpaqueType` in future versions ``` r? `@lcnr`
2 parents 0b24479 + caae1e0 commit 6b771f6

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
5858
visitor: &mut V,
5959
) -> ControlFlow<V::BreakTy> {
6060
// HACK: An arbitrary cutoff to avoid dealing with overflow and cycles.
61-
if self.goal.depth >= 10 {
61+
if self.goal.depth <= 10 {
6262
let infcx = self.goal.infcx;
6363
infcx.probe(|_| {
6464
let mut instantiated_goals = vec![];

compiler/rustc_trait_selection/src/traits/coherence.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::traits::{
2020
};
2121
use rustc_data_structures::fx::FxIndexSet;
2222
use rustc_errors::Diagnostic;
23+
use rustc_hir::def::DefKind;
2324
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
2425
use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, TyCtxtInferExt};
2526
use rustc_infer::traits::{util, TraitEngine};
@@ -1002,7 +1003,12 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a> {
10021003
// and then prove the resulting predicate as a nested goal.
10031004
let trait_ref = match predicate.kind().no_bound_vars() {
10041005
Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(tr))) => tr.trait_ref,
1005-
Some(ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj))) => {
1006+
Some(ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj)))
1007+
if matches!(
1008+
infcx.tcx.def_kind(proj.projection_ty.def_id),
1009+
DefKind::AssocTy | DefKind::AssocConst
1010+
) =>
1011+
{
10061012
proj.projection_ty.trait_ref(infcx.tcx)
10071013
}
10081014
_ => return ControlFlow::Continue(()),

tests/ui/impl-trait/auto-trait-coherence.next.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ LL | impl<T: Send> AnotherTrait for T {}
66
...
77
LL | impl AnotherTrait for D<OpaqueType> {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
9+
|
10+
= note: upstream crates may add a new impl of trait `std::marker::Send` for type `OpaqueType` in future versions
911

1012
error: aborting due to previous error
1113

0 commit comments

Comments
 (0)