Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fd1621c

Browse files
committedApr 28, 2024
Actually use probes when needed and stop relying on existing outer probes
1 parent 88e3986 commit fd1621c

File tree

11 files changed

+350
-335
lines changed

11 files changed

+350
-335
lines changed
 

‎compiler/rustc_middle/src/traits/solve.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,9 @@ pub enum CandidateSource {
332332
/// }
333333
/// ```
334334
AliasBound,
335+
/// A candidate that is registered only during coherence to represent some
336+
/// yet-unknown impl that could be produced downstream without violating orphan
337+
/// rules.
338+
// FIXME: Merge this with the forced ambiguity candidates, so those don't use `Misc`.
339+
CoherenceUnknowable,
335340
}

‎compiler/rustc_middle/src/traits/solve/inspect.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ pub enum ProbeKind<'tcx> {
141141
TryNormalizeNonRigid { result: QueryResult<'tcx> },
142142
/// Probe entered when normalizing the self ty during candidate assembly
143143
NormalizedSelfTyAssembly,
144-
/// Some candidate to prove the current goal.
145-
///
146-
/// FIXME: Remove this in favor of always using more strongly typed variants.
147-
MiscCandidate { name: &'static str, result: QueryResult<'tcx> },
148144
/// A candidate for proving a trait or alias-relate goal.
149145
TraitCandidate { source: CandidateSource, result: QueryResult<'tcx> },
150146
/// Used in the probe that wraps normalizing the non-self type for the unsize
@@ -154,4 +150,6 @@ pub enum ProbeKind<'tcx> {
154150
/// do a probe to find out what projection type(s) may be used to prove that
155151
/// the source type upholds all of the target type's object bounds.
156152
UpcastProjectionCompatibility,
153+
/// Try to unify an opaque type with an existing
154+
OpaqueTypeStorageLookup,
157155
}

‎compiler/rustc_middle/src/traits/solve/inspect/format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
112112
ProbeKind::UpcastProjectionCompatibility => {
113113
write!(self.f, "PROBING FOR PROJECTION COMPATIBILITY FOR UPCASTING:")
114114
}
115-
ProbeKind::MiscCandidate { name, result } => {
116-
write!(self.f, "CANDIDATE {name}: {result:?}")
115+
ProbeKind::OpaqueTypeStorageLookup => {
116+
write!(self.f, "PROBING FOR AN EXISTING OPAQUE:")
117117
}
118118
ProbeKind::TraitCandidate { source, result } => {
119119
write!(self.f, "CANDIDATE {source:?}: {result:?}")

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

Lines changed: 74 additions & 92 deletions
Large diffs are not rendered by default.

‎compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -998,19 +998,21 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
998998
if candidate_key.def_id != key.def_id {
999999
continue;
10001000
}
1001-
values.extend(self.probe_misc_candidate("opaque type storage").enter(|ecx| {
1002-
for (a, b) in std::iter::zip(candidate_key.args, key.args) {
1003-
ecx.eq(param_env, a, b)?;
1004-
}
1005-
ecx.eq(param_env, candidate_ty, ty)?;
1006-
ecx.add_item_bounds_for_hidden_type(
1007-
candidate_key.def_id.to_def_id(),
1008-
candidate_key.args,
1009-
param_env,
1010-
candidate_ty,
1011-
);
1012-
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1013-
}));
1001+
values.extend(self.probe(|_| inspect::ProbeKind::OpaqueTypeStorageLookup).enter(
1002+
|ecx| {
1003+
for (a, b) in std::iter::zip(candidate_key.args, key.args) {
1004+
ecx.eq(param_env, a, b)?;
1005+
}
1006+
ecx.eq(param_env, candidate_ty, ty)?;
1007+
ecx.add_item_bounds_for_hidden_type(
1008+
candidate_key.def_id.to_def_id(),
1009+
candidate_key.args,
1010+
param_env,
1011+
candidate_ty,
1012+
);
1013+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1014+
},
1015+
));
10141016
}
10151017
values
10161018
}

‎compiler/rustc_trait_selection/src/solve/eval_ctxt/probe.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::solve::assembly::Candidate;
22

33
use super::EvalCtxt;
4+
use rustc_infer::traits::BuiltinImplSource;
45
use rustc_middle::traits::{
56
query::NoSolution,
67
solve::{inspect, CandidateSource, QueryResult},
@@ -75,24 +76,12 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
7576
ProbeCtxt { ecx: self, probe_kind, _result: PhantomData }
7677
}
7778

78-
pub(in crate::solve) fn probe_misc_candidate(
79+
pub(in crate::solve) fn probe_builtin_trait_candidate(
7980
&mut self,
80-
name: &'static str,
81-
) -> ProbeCtxt<
82-
'_,
83-
'a,
84-
'tcx,
85-
impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<'tcx>,
86-
QueryResult<'tcx>,
87-
> {
88-
ProbeCtxt {
89-
ecx: self,
90-
probe_kind: move |result: &QueryResult<'tcx>| inspect::ProbeKind::MiscCandidate {
91-
name,
92-
result: *result,
93-
},
94-
_result: PhantomData,
95-
}
81+
source: BuiltinImplSource,
82+
) -> TraitProbeCtxt<'_, 'a, 'tcx, impl FnOnce(&QueryResult<'tcx>) -> inspect::ProbeKind<'tcx>>
83+
{
84+
self.probe_trait_candidate(CandidateSource::BuiltinImpl(source))
9685
}
9786

9887
pub(in crate::solve) fn probe_trait_candidate(

‎compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ impl<'tcx> InferCtxt<'tcx> {
107107
Ok(Some(ImplSource::Param(vec![])))
108108
}
109109

110+
(_, CandidateSource::CoherenceUnknowable) => bug!(),
111+
110112
(Certainty::Maybe(_), _) => Ok(None),
111113
}
112114
})

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
198198
match probe.kind {
199199
inspect::ProbeKind::NormalizedSelfTyAssembly
200200
| inspect::ProbeKind::UnsizeAssembly
201-
| inspect::ProbeKind::UpcastProjectionCompatibility => (),
201+
| inspect::ProbeKind::UpcastProjectionCompatibility
202+
| inspect::ProbeKind::OpaqueTypeStorageLookup => (),
202203
// We add a candidate for the root evaluation if there
203204
// is only one way to prove a given goal, e.g. for `WellFormed`.
204205
//
@@ -218,8 +219,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
218219
})
219220
}
220221
}
221-
inspect::ProbeKind::MiscCandidate { name: _, result }
222-
| inspect::ProbeKind::TraitCandidate { source: _, result } => {
222+
inspect::ProbeKind::TraitCandidate { source: _, result } => {
223223
candidates.push(InspectCandidate {
224224
goal: self,
225225
kind: probe.kind,

‎compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ use rustc_hir::def_id::DefId;
88
use rustc_hir::LangItem;
99
use rustc_infer::traits::query::NoSolution;
1010
use rustc_infer::traits::solve::inspect::ProbeKind;
11+
use rustc_infer::traits::solve::MaybeCause;
1112
use rustc_infer::traits::specialization_graph::LeafDef;
1213
use rustc_infer::traits::Reveal;
13-
use rustc_middle::traits::solve::{
14-
CandidateSource, CanonicalResponse, Certainty, Goal, QueryResult,
15-
};
14+
use rustc_middle::traits::solve::{CandidateSource, Certainty, Goal, QueryResult};
1615
use rustc_middle::traits::BuiltinImplSource;
1716
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
1817
use rustc_middle::ty::NormalizesTo;
@@ -119,14 +118,15 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
119118

120119
fn probe_and_match_goal_against_assumption(
121120
ecx: &mut EvalCtxt<'_, 'tcx>,
121+
source: CandidateSource,
122122
goal: Goal<'tcx, Self>,
123123
assumption: ty::Clause<'tcx>,
124124
then: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> QueryResult<'tcx>,
125-
) -> QueryResult<'tcx> {
125+
) -> Result<Candidate<'tcx>, NoSolution> {
126126
if let Some(projection_pred) = assumption.as_projection_clause() {
127127
if projection_pred.projection_def_id() == goal.predicate.def_id() {
128128
let tcx = ecx.tcx();
129-
ecx.probe_misc_candidate("assumption").enter(|ecx| {
129+
ecx.probe_trait_candidate(source).enter(|ecx| {
130130
let assumption_projection_pred =
131131
ecx.instantiate_binder_with_infer(projection_pred);
132132
ecx.eq(
@@ -300,14 +300,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
300300
fn consider_error_guaranteed_candidate(
301301
_ecx: &mut EvalCtxt<'_, 'tcx>,
302302
_guar: ErrorGuaranteed,
303-
) -> QueryResult<'tcx> {
303+
) -> Result<Candidate<'tcx>, NoSolution> {
304304
Err(NoSolution)
305305
}
306306

307307
fn consider_auto_trait_candidate(
308308
ecx: &mut EvalCtxt<'_, 'tcx>,
309309
goal: Goal<'tcx, Self>,
310-
) -> QueryResult<'tcx> {
310+
) -> Result<Candidate<'tcx>, NoSolution> {
311311
ecx.tcx().dcx().span_delayed_bug(
312312
ecx.tcx().def_span(goal.predicate.def_id()),
313313
"associated types not allowed on auto traits",
@@ -318,43 +318,43 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
318318
fn consider_trait_alias_candidate(
319319
_ecx: &mut EvalCtxt<'_, 'tcx>,
320320
goal: Goal<'tcx, Self>,
321-
) -> QueryResult<'tcx> {
321+
) -> Result<Candidate<'tcx>, NoSolution> {
322322
bug!("trait aliases do not have associated types: {:?}", goal);
323323
}
324324

325325
fn consider_builtin_sized_candidate(
326326
_ecx: &mut EvalCtxt<'_, 'tcx>,
327327
goal: Goal<'tcx, Self>,
328-
) -> QueryResult<'tcx> {
328+
) -> Result<Candidate<'tcx>, NoSolution> {
329329
bug!("`Sized` does not have an associated type: {:?}", goal);
330330
}
331331

332332
fn consider_builtin_copy_clone_candidate(
333333
_ecx: &mut EvalCtxt<'_, 'tcx>,
334334
goal: Goal<'tcx, Self>,
335-
) -> QueryResult<'tcx> {
335+
) -> Result<Candidate<'tcx>, NoSolution> {
336336
bug!("`Copy`/`Clone` does not have an associated type: {:?}", goal);
337337
}
338338

339339
fn consider_builtin_pointer_like_candidate(
340340
_ecx: &mut EvalCtxt<'_, 'tcx>,
341341
goal: Goal<'tcx, Self>,
342-
) -> QueryResult<'tcx> {
342+
) -> Result<Candidate<'tcx>, NoSolution> {
343343
bug!("`PointerLike` does not have an associated type: {:?}", goal);
344344
}
345345

346346
fn consider_builtin_fn_ptr_trait_candidate(
347347
_ecx: &mut EvalCtxt<'_, 'tcx>,
348348
goal: Goal<'tcx, Self>,
349-
) -> QueryResult<'tcx> {
349+
) -> Result<Candidate<'tcx>, NoSolution> {
350350
bug!("`FnPtr` does not have an associated type: {:?}", goal);
351351
}
352352

353353
fn consider_builtin_fn_trait_candidates(
354354
ecx: &mut EvalCtxt<'_, 'tcx>,
355355
goal: Goal<'tcx, Self>,
356356
goal_kind: ty::ClosureKind,
357-
) -> QueryResult<'tcx> {
357+
) -> Result<Candidate<'tcx>, NoSolution> {
358358
let tcx = ecx.tcx();
359359
let tupled_inputs_and_output =
360360
match structural_traits::extract_tupled_inputs_and_output_from_callable(
@@ -364,8 +364,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
364364
)? {
365365
Some(tupled_inputs_and_output) => tupled_inputs_and_output,
366366
None => {
367-
return ecx
368-
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
367+
return ecx.forced_ambiguity(MaybeCause::Ambiguity);
369368
}
370369
};
371370
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
@@ -387,6 +386,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
387386
// (FIXME: technically we only need to check this if the type is a fn ptr...)
388387
Self::probe_and_consider_implied_clause(
389388
ecx,
389+
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
390390
goal,
391391
pred,
392392
[goal.with(tcx, output_is_sized_pred)],
@@ -397,7 +397,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
397397
ecx: &mut EvalCtxt<'_, 'tcx>,
398398
goal: Goal<'tcx, Self>,
399399
goal_kind: ty::ClosureKind,
400-
) -> QueryResult<'tcx> {
400+
) -> Result<Candidate<'tcx>, NoSolution> {
401401
let tcx = ecx.tcx();
402402

403403
let env_region = match goal_kind {
@@ -468,6 +468,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
468468
// (FIXME: technically we only need to check this if the type is a fn ptr...)
469469
Self::probe_and_consider_implied_clause(
470470
ecx,
471+
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
471472
goal,
472473
pred,
473474
[goal.with(tcx, output_is_sized_pred)]
@@ -479,7 +480,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
479480
fn consider_builtin_async_fn_kind_helper_candidate(
480481
ecx: &mut EvalCtxt<'_, 'tcx>,
481482
goal: Goal<'tcx, Self>,
482-
) -> QueryResult<'tcx> {
483+
) -> Result<Candidate<'tcx>, NoSolution> {
483484
let [
484485
closure_fn_kind_ty,
485486
goal_kind_ty,
@@ -494,7 +495,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
494495

495496
// Bail if the upvars haven't been constrained.
496497
if tupled_upvars_ty.expect_ty().is_ty_var() {
497-
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
498+
return ecx.forced_ambiguity(MaybeCause::Ambiguity);
498499
}
499500

500501
let Some(closure_kind) = closure_fn_kind_ty.expect_ty().to_opt_closure_kind() else {
@@ -517,25 +518,27 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
517518
borrow_region.expect_region(),
518519
);
519520

520-
ecx.instantiate_normalizes_to_term(goal, upvars_ty.into());
521-
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
521+
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
522+
ecx.instantiate_normalizes_to_term(goal, upvars_ty.into());
523+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
524+
})
522525
}
523526

524527
fn consider_builtin_tuple_candidate(
525528
_ecx: &mut EvalCtxt<'_, 'tcx>,
526529
goal: Goal<'tcx, Self>,
527-
) -> QueryResult<'tcx> {
530+
) -> Result<Candidate<'tcx>, NoSolution> {
528531
bug!("`Tuple` does not have an associated type: {:?}", goal);
529532
}
530533

531534
fn consider_builtin_pointee_candidate(
532535
ecx: &mut EvalCtxt<'_, 'tcx>,
533536
goal: Goal<'tcx, Self>,
534-
) -> QueryResult<'tcx> {
537+
) -> Result<Candidate<'tcx>, NoSolution> {
535538
let tcx = ecx.tcx();
536539
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None);
537540
assert_eq!(metadata_def_id, goal.predicate.def_id());
538-
ecx.probe_misc_candidate("builtin pointee").enter(|ecx| {
541+
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
539542
let metadata_ty = match goal.predicate.self_ty().kind() {
540543
ty::Bool
541544
| ty::Char
@@ -614,7 +617,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
614617
fn consider_builtin_future_candidate(
615618
ecx: &mut EvalCtxt<'_, 'tcx>,
616619
goal: Goal<'tcx, Self>,
617-
) -> QueryResult<'tcx> {
620+
) -> Result<Candidate<'tcx>, NoSolution> {
618621
let self_ty = goal.predicate.self_ty();
619622
let ty::Coroutine(def_id, args) = *self_ty.kind() else {
620623
return Err(NoSolution);
@@ -630,6 +633,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
630633

631634
Self::probe_and_consider_implied_clause(
632635
ecx,
636+
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
633637
goal,
634638
ty::ProjectionPredicate {
635639
projection_ty: ty::AliasTy::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
@@ -645,7 +649,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
645649
fn consider_builtin_iterator_candidate(
646650
ecx: &mut EvalCtxt<'_, 'tcx>,
647651
goal: Goal<'tcx, Self>,
648-
) -> QueryResult<'tcx> {
652+
) -> Result<Candidate<'tcx>, NoSolution> {
649653
let self_ty = goal.predicate.self_ty();
650654
let ty::Coroutine(def_id, args) = *self_ty.kind() else {
651655
return Err(NoSolution);
@@ -661,6 +665,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
661665

662666
Self::probe_and_consider_implied_clause(
663667
ecx,
668+
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
664669
goal,
665670
ty::ProjectionPredicate {
666671
projection_ty: ty::AliasTy::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
@@ -676,14 +681,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
676681
fn consider_builtin_fused_iterator_candidate(
677682
_ecx: &mut EvalCtxt<'_, 'tcx>,
678683
goal: Goal<'tcx, Self>,
679-
) -> QueryResult<'tcx> {
684+
) -> Result<Candidate<'tcx>, NoSolution> {
680685
bug!("`FusedIterator` does not have an associated type: {:?}", goal);
681686
}
682687

683688
fn consider_builtin_async_iterator_candidate(
684689
ecx: &mut EvalCtxt<'_, 'tcx>,
685690
goal: Goal<'tcx, Self>,
686-
) -> QueryResult<'tcx> {
691+
) -> Result<Candidate<'tcx>, NoSolution> {
687692
let self_ty = goal.predicate.self_ty();
688693
let ty::Coroutine(def_id, args) = *self_ty.kind() else {
689694
return Err(NoSolution);
@@ -695,7 +700,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
695700
return Err(NoSolution);
696701
}
697702

698-
ecx.probe_misc_candidate("builtin AsyncIterator kind").enter(|ecx| {
703+
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
699704
let expected_ty = ecx.next_ty_infer();
700705
// Take `AsyncIterator<Item = I>` and turn it into the corresponding
701706
// coroutine yield ty `Poll<Option<I>>`.
@@ -719,7 +724,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
719724
fn consider_builtin_coroutine_candidate(
720725
ecx: &mut EvalCtxt<'_, 'tcx>,
721726
goal: Goal<'tcx, Self>,
722-
) -> QueryResult<'tcx> {
727+
) -> Result<Candidate<'tcx>, NoSolution> {
723728
let self_ty = goal.predicate.self_ty();
724729
let ty::Coroutine(def_id, args) = *self_ty.kind() else {
725730
return Err(NoSolution);
@@ -744,6 +749,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
744749

745750
Self::probe_and_consider_implied_clause(
746751
ecx,
752+
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
747753
goal,
748754
ty::ProjectionPredicate {
749755
projection_ty: ty::AliasTy::new(
@@ -763,14 +769,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
763769
fn consider_structural_builtin_unsize_candidates(
764770
_ecx: &mut EvalCtxt<'_, 'tcx>,
765771
goal: Goal<'tcx, Self>,
766-
) -> Vec<(CanonicalResponse<'tcx>, BuiltinImplSource)> {
772+
) -> Vec<Candidate<'tcx>> {
767773
bug!("`Unsize` does not have an associated type: {:?}", goal);
768774
}
769775

770776
fn consider_builtin_discriminant_kind_candidate(
771777
ecx: &mut EvalCtxt<'_, 'tcx>,
772778
goal: Goal<'tcx, Self>,
773-
) -> QueryResult<'tcx> {
779+
) -> Result<Candidate<'tcx>, NoSolution> {
774780
let self_ty = goal.predicate.self_ty();
775781
let discriminant_ty = match *self_ty.kind() {
776782
ty::Bool
@@ -813,7 +819,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
813819
),
814820
};
815821

816-
ecx.probe_misc_candidate("builtin discriminant kind").enter(|ecx| {
822+
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
817823
ecx.instantiate_normalizes_to_term(goal, discriminant_ty.into());
818824
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
819825
})
@@ -822,7 +828,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
822828
fn consider_builtin_async_destruct_candidate(
823829
ecx: &mut EvalCtxt<'_, 'tcx>,
824830
goal: Goal<'tcx, Self>,
825-
) -> QueryResult<'tcx> {
831+
) -> Result<Candidate<'tcx>, NoSolution> {
826832
let self_ty = goal.predicate.self_ty();
827833
let async_destructor_ty = match *self_ty.kind() {
828834
ty::Bool
@@ -865,7 +871,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
865871
),
866872
};
867873

868-
ecx.probe_misc_candidate("builtin async destruct").enter(|ecx| {
874+
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
869875
ecx.eq(goal.param_env, goal.predicate.term, async_destructor_ty.into())
870876
.expect("expected goal term to be fully unconstrained");
871877
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
@@ -875,14 +881,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
875881
fn consider_builtin_destruct_candidate(
876882
_ecx: &mut EvalCtxt<'_, 'tcx>,
877883
goal: Goal<'tcx, Self>,
878-
) -> QueryResult<'tcx> {
884+
) -> Result<Candidate<'tcx>, NoSolution> {
879885
bug!("`Destruct` does not have an associated type: {:?}", goal);
880886
}
881887

882888
fn consider_builtin_transmute_candidate(
883889
_ecx: &mut EvalCtxt<'_, 'tcx>,
884890
goal: Goal<'tcx, Self>,
885-
) -> QueryResult<'tcx> {
891+
) -> Result<Candidate<'tcx>, NoSolution> {
886892
bug!("`BikeshedIntrinsicFrom` does not have an associated type: {:?}", goal)
887893
}
888894
}

‎compiler/rustc_trait_selection/src/solve/trait_goals.rs

Lines changed: 197 additions & 165 deletions
Large diffs are not rendered by default.

‎compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,9 +1078,8 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
10781078
// Add ambiguity causes for unknowable goals.
10791079
let mut ambiguity_cause = None;
10801080
for cand in goal.candidates() {
1081-
// FIXME: boiiii, using string comparisions here sure is scuffed.
1082-
if let inspect::ProbeKind::MiscCandidate {
1083-
name: "coherence unknowable",
1081+
if let inspect::ProbeKind::TraitCandidate {
1082+
source: CandidateSource::CoherenceUnknowable,
10841083
result: Ok(_),
10851084
} = cand.kind()
10861085
{

0 commit comments

Comments
 (0)
Please sign in to comment.