Skip to content

Commit caae1e0

Browse files
committed
Add guard checking for associated types before computing intercrate ambiguity of projections. Bless test with more specific notes on the ambiguity cause.
1 parent 60d99ab commit caae1e0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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)