Skip to content

Commit aaa58c7

Browse files
committed
self ty infer ambiguity: add proof tree cand
1 parent 79e961f commit aaa58c7

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
263263
) -> Vec<Candidate<'tcx>> {
264264
debug_assert_eq!(goal, self.resolve_vars_if_possible(goal));
265265
if let Some(ambig) = self.assemble_self_ty_infer_ambiguity_response(goal) {
266-
return ambig;
266+
return vec![ambig];
267267
}
268268

269269
let mut candidates = self.assemble_candidates_via_self_ty(goal, 0);
@@ -288,15 +288,20 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
288288
fn assemble_self_ty_infer_ambiguity_response<G: GoalKind<'tcx>>(
289289
&mut self,
290290
goal: Goal<'tcx, G>,
291-
) -> Option<Vec<Candidate<'tcx>>> {
292-
goal.predicate.self_ty().is_ty_var().then(|| {
293-
vec![Candidate {
294-
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
295-
result: self
296-
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
297-
.unwrap(),
298-
}]
299-
})
291+
) -> Option<Candidate<'tcx>> {
292+
if goal.predicate.self_ty().is_ty_var() {
293+
debug!("adding self_ty_infer_ambiguity_response");
294+
let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
295+
let result = self
296+
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
297+
.unwrap();
298+
let mut dummy_probe = self.inspect.new_probe();
299+
dummy_probe.probe_kind(ProbeKind::TraitCandidate { source, result: Ok(result) });
300+
self.inspect.finish_probe(dummy_probe);
301+
Some(Candidate { source, result })
302+
} else {
303+
None
304+
}
300305
}
301306

302307
/// Assemble candidates which apply to the self type. This only looks at candidate which
@@ -310,7 +315,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
310315
) -> Vec<Candidate<'tcx>> {
311316
debug_assert_eq!(goal, self.resolve_vars_if_possible(goal));
312317
if let Some(ambig) = self.assemble_self_ty_infer_ambiguity_response(goal) {
313-
return ambig;
318+
return vec![ambig];
314319
}
315320

316321
let mut candidates = Vec::new();

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

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ 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
119

1210
error: aborting due to previous error
1311

tests/ui/traits/new-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ LL | impl<T: Copy> Trait for T {}
66
LL | struct LocalTy;
77
LL | impl Trait for <LocalTy as Overflow>::Assoc {}
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `<LocalTy as Overflow>::Assoc`
9-
|
10-
= note: downstream crates may implement trait `std::marker::Sized` for type `<LocalTy as Overflow>::Assoc`
11-
= note: downstream crates may implement trait `std::marker::Copy` for type `<LocalTy as Overflow>::Assoc`
129

1310
error: aborting due to previous error
1411

0 commit comments

Comments
 (0)