Skip to content

Commit 11e8a21

Browse files
committed
rarw
1 parent 18809a2 commit 11e8a21

File tree

4 files changed

+42
-31
lines changed

4 files changed

+42
-31
lines changed

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

+13-16
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ where
292292
pub(super) fn assemble_and_evaluate_candidates<G: GoalKind<D>>(
293293
&mut self,
294294
goal: Goal<I, G>,
295+
proven_via: Option<TraitGoalProvenVia>,
295296
) -> Vec<Candidate<I>> {
296297
let Ok(normalized_self_ty) =
297298
self.structurally_normalize_ty(goal.param_env, goal.predicate.self_ty())
@@ -318,15 +319,18 @@ where
318319
}
319320
}
320321

321-
self.assemble_impl_candidates(goal, &mut candidates);
322-
323-
self.assemble_builtin_impl_candidates(goal, &mut candidates);
324-
325-
self.assemble_alias_bound_candidates(goal, &mut candidates);
326-
327-
self.assemble_object_bound_candidates(goal, &mut candidates);
328-
329322
self.assemble_param_env_candidates(goal, &mut candidates);
323+
self.assemble_alias_bound_candidates(goal, &mut candidates);
324+
if candidates.is_empty()
325+
&& !matches!(
326+
proven_via,
327+
Some(TraitGoalProvenVia::ParamEnv | TraitGoalProvenVia::AliasBound)
328+
)
329+
{
330+
self.assemble_impl_candidates(goal, &mut candidates);
331+
self.assemble_builtin_impl_candidates(goal, &mut candidates);
332+
self.assemble_object_bound_candidates(goal, &mut candidates);
333+
}
330334

331335
candidates
332336
}
@@ -780,17 +784,10 @@ where
780784
#[instrument(level = "debug", skip(self, inject_normalize_to_rigid_candidate), ret)]
781785
pub(super) fn merge_candidates(
782786
&mut self,
783-
proven_via: Option<TraitGoalProvenVia>,
787+
proven_via: TraitGoalProvenVia,
784788
candidates: Vec<Candidate<I>>,
785789
inject_normalize_to_rigid_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
786790
) -> QueryResult<I> {
787-
let Some(proven_via) = proven_via else {
788-
// We don't care about overflow. If proving the trait goal overflowed, then
789-
// it's enough to report an overflow error for that, we don't also have to
790-
// overflow during normalization.
791-
return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Ambiguity));
792-
};
793-
794791
match proven_via {
795792
// Even when a trait bound has been proven using a where-bound, we
796793
// still need to consider alias-bounds for normalization, see

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use tracing::instrument;
1111
use super::assembly::{Candidate, structural_traits};
1212
use crate::delegate::SolverDelegate;
1313
use crate::solve::{
14-
BuiltinImplSource, CandidateSource, Certainty, EvalCtxt, Goal, GoalSource, NoSolution,
15-
QueryResult, assembly,
14+
BuiltinImplSource, CandidateSource, Certainty, EvalCtxt, Goal, GoalSource, MaybeCause,
15+
NoSolution, QueryResult, assembly,
1616
};
1717

1818
impl<D, I> assembly::GoalKind<D> for ty::HostEffectPredicate<I>
@@ -399,12 +399,19 @@ where
399399
&mut self,
400400
goal: Goal<I, ty::HostEffectPredicate<I>>,
401401
) -> QueryResult<I> {
402-
let candidates = self.assemble_and_evaluate_candidates(goal);
403402
let (_, proven_via) = self.probe(|_| ProbeKind::ShadowedEnvProbing).enter(|ecx| {
404403
let trait_goal: Goal<I, ty::TraitPredicate<I>> =
405404
goal.with(ecx.cx(), goal.predicate.trait_ref);
406405
ecx.compute_trait_goal(trait_goal)
407406
})?;
408-
self.merge_candidates(proven_via, candidates, |_ecx| Err(NoSolution))
407+
if let Some(proven_via) = proven_via {
408+
let candidates = self.assemble_and_evaluate_candidates(goal, Some(proven_via));
409+
self.merge_candidates(proven_via, candidates, |_ecx| Err(NoSolution))
410+
} else {
411+
// We don't care about overflow. If proving the trait goal overflowed, then
412+
// it's enough to report an overflow error for that, we don't also have to
413+
// overflow during normalization.
414+
Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Ambiguity))
415+
}
409416
}
410417
}

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,30 @@ where
3232
let cx = self.cx();
3333
match goal.predicate.alias.kind(cx) {
3434
ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst => {
35-
let candidates = self.assemble_and_evaluate_candidates(goal);
3635
let trait_ref = goal.predicate.alias.trait_ref(cx);
3736
let (_, proven_via) =
3837
self.probe(|_| ProbeKind::ShadowedEnvProbing).enter(|ecx| {
3938
let trait_goal: Goal<I, ty::TraitPredicate<I>> = goal.with(cx, trait_ref);
4039
ecx.compute_trait_goal(trait_goal)
4140
})?;
42-
self.merge_candidates(proven_via, candidates, |ecx| {
43-
ecx.probe(|&result| ProbeKind::RigidAlias { result }).enter(|this| {
44-
this.structurally_instantiate_normalizes_to_term(
45-
goal,
46-
goal.predicate.alias,
47-
);
48-
this.add_goal(GoalSource::AliasWellFormed, goal.with(cx, trait_ref));
49-
this.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
41+
if let Some(proven_via) = proven_via {
42+
let candidates = self.assemble_and_evaluate_candidates(goal, Some(proven_via));
43+
self.merge_candidates(proven_via, candidates, |ecx| {
44+
ecx.probe(|&result| ProbeKind::RigidAlias { result }).enter(|this| {
45+
this.structurally_instantiate_normalizes_to_term(
46+
goal,
47+
goal.predicate.alias,
48+
);
49+
this.add_goal(GoalSource::AliasWellFormed, goal.with(cx, trait_ref));
50+
this.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
51+
})
5052
})
51-
})
53+
} else {
54+
// We don't care about overflow. If proving the trait goal overflowed, then
55+
// it's enough to report an overflow error for that, we don't also have to
56+
// overflow during normalization.
57+
Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Ambiguity))
58+
}
5259
}
5360
ty::AliasTermKind::InherentTy => self.normalize_inherent_associated_type(goal),
5461
ty::AliasTermKind::OpaqueTy => self.normalize_opaque_type(goal),

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ where
13771377
&mut self,
13781378
goal: Goal<I, TraitPredicate<I>>,
13791379
) -> Result<(CanonicalResponse<I>, Option<TraitGoalProvenVia>), NoSolution> {
1380-
let candidates = self.assemble_and_evaluate_candidates(goal);
1380+
let candidates = self.assemble_and_evaluate_candidates(goal, None);
13811381
self.merge_trait_candidates(goal, candidates)
13821382
}
13831383
}

0 commit comments

Comments
 (0)