Skip to content

Commit 8a21d1b

Browse files
Review
1 parent 1f774d7 commit 8a21d1b

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed

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

+18-6
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ where
123123
result: Ok(candidate.result),
124124
},
125125
Err(NoSolution) => inspect::ProbeKind::TraitCandidate {
126-
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
126+
source: CandidateSource::ParamEnv(ParamEnvSource::Global),
127127
result: Err(NoSolution),
128128
},
129129
})
@@ -157,7 +157,7 @@ where
157157
}
158158

159159
/// Try to reject the assumption based off of simple heuristics, such as [`ty::ClauseKind`]
160-
/// and [`I::DefId`].
160+
/// and `DefId`.
161161
fn fast_reject_assumption(
162162
ecx: &mut EvalCtxt<'_, D>,
163163
goal: Goal<I, Self>,
@@ -990,12 +990,26 @@ where
990990
}
991991
}
992992

993+
/// Compute whether a param-env assumption is global or non-global after normalizing it.
994+
///
995+
/// This is necessary because, for example, given:
996+
///
997+
/// ```ignore,rust
998+
/// where
999+
/// T: Trait<Assoc = u32>,
1000+
/// i32: From<T::Assoc>,
1001+
/// ```
1002+
///
1003+
/// The `i32: From<T::Assoc>` bound is non-global before normalization, but is global after.
1004+
/// Since the old trait solver normalized param-envs eagerly, we want to emulate this
1005+
/// behavior lazily.
9931006
fn characterize_param_env_assumption(
9941007
&mut self,
9951008
param_env: I::ParamEnv,
9961009
assumption: I::Clause,
9971010
) -> Result<CandidateSource<I>, NoSolution> {
998-
// FIXME:
1011+
// FIXME: This should be fixed, but it also requires changing the behavior
1012+
// in the old solver which is currently relied on.
9991013
if assumption.has_bound_vars() {
10001014
return Ok(CandidateSource::ParamEnv(ParamEnvSource::NonGlobal));
10011015
}
@@ -1030,7 +1044,6 @@ where
10301044
let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
10311045
return ControlFlow::Break(Err(NoSolution));
10321046
};
1033-
let ty = self.ecx.eager_resolve(ty);
10341047

10351048
if let ty::Placeholder(_) = ty.kind() {
10361049
ControlFlow::Break(Ok(()))
@@ -1043,7 +1056,6 @@ where
10431056
let Ok(ct) = self.ecx.structurally_normalize_const(self.param_env, ct) else {
10441057
return ControlFlow::Break(Err(NoSolution));
10451058
};
1046-
let ct = self.ecx.eager_resolve(ct);
10471059

10481060
if let ty::ConstKind::Placeholder(_) = ct.kind() {
10491061
ControlFlow::Break(Ok(()))
@@ -1053,7 +1065,7 @@ where
10531065
}
10541066

10551067
fn visit_region(&mut self, r: I::Region) -> Self::Result {
1056-
match r.kind() {
1068+
match self.ecx.eager_resolve_region(r).kind() {
10571069
ty::ReStatic | ty::ReError(_) => ControlFlow::Continue(()),
10581070
ty::ReVar(_) | ty::RePlaceholder(_) => ControlFlow::Break(Ok(())),
10591071
ty::ReErased | ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::ReBound(..) => {

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ where
6262
goal: Goal<I, Self>,
6363
assumption: I::Clause,
6464
) -> Result<(), NoSolution> {
65-
let Some(host_clause) = assumption.as_host_effect_clause() else {
66-
panic!("fast_reject_assumption should have avoided this");
67-
};
65+
let host_clause = assumption.as_host_effect_clause().unwrap();
6866

6967
let assumption_trait_pred = ecx.instantiate_binder_with_infer(host_clause);
7068
ecx.eq(goal.param_env, goal.predicate.trait_ref, assumption_trait_pred.trait_ref)?;

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use tracing::{debug, instrument, trace};
1919
use super::has_only_region_constraints;
2020
use crate::coherence;
2121
use crate::delegate::SolverDelegate;
22-
use crate::resolve::EagerResolver;
2322
use crate::solve::inspect::{self, ProofTreeBuilder};
2423
use crate::solve::search_graph::SearchGraph;
2524
use crate::solve::{
@@ -1001,11 +1000,12 @@ where
10011000
self.delegate.resolve_vars_if_possible(value)
10021001
}
10031002

1004-
pub(super) fn eager_resolve<T>(&self, value: T) -> T
1005-
where
1006-
T: TypeFoldable<I>,
1007-
{
1008-
value.fold_with(&mut EagerResolver::new(self.delegate))
1003+
pub(super) fn eager_resolve_region(&self, r: I::Region) -> I::Region {
1004+
if let ty::ReVar(vid) = r.kind() {
1005+
self.delegate.opportunistic_resolve_lt_var(vid)
1006+
} else {
1007+
r
1008+
}
10091009
}
10101010

10111011
pub(super) fn fresh_args_for_item(&mut self, def_id: I::DefId) -> I::GenericArgs {

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ where
130130
goal: Goal<I, Self>,
131131
assumption: I::Clause,
132132
) -> Result<(), NoSolution> {
133-
let Some(projection_pred) = assumption.as_projection_clause() else {
134-
panic!("fast_reject_assumption should have avoided this");
135-
};
133+
let projection_pred = assumption.as_projection_clause().unwrap();
136134

137135
let assumption_projection_pred = ecx.instantiate_binder_with_infer(projection_pred);
138136
ecx.eq(goal.param_env, goal.predicate.alias, assumption_projection_pred.projection_term)?;

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ where
151151
goal: Goal<I, Self>,
152152
assumption: I::Clause,
153153
) -> Result<(), NoSolution> {
154-
let Some(trait_clause) = assumption.as_trait_clause() else {
155-
panic!("fast_reject_assumption should have avoided this");
156-
};
154+
let trait_clause = assumption.as_trait_clause().unwrap();
157155

158156
let assumption_trait_pred = ecx.instantiate_binder_with_infer(trait_clause);
159157
ecx.eq(goal.param_env, goal.predicate.trait_ref, assumption_trait_pred.trait_ref)?;

compiler/rustc_type_ir/src/solve/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ pub enum CandidateSource<I: Interner> {
147147
/// For a list of all traits with builtin impls, check out the
148148
/// `EvalCtxt::assemble_builtin_impl_candidates` method.
149149
BuiltinImpl(BuiltinImplSource),
150-
/// An assumption from the environment.
151-
///
152-
/// More precisely we've used the `n-th` assumption in the `param_env`.
150+
/// An assumption from the environment. Stores a [`ParamEnvSource`], since we
151+
/// prefer non-global param-env candidates in candidate assembly.
153152
///
154153
/// ## Examples
155154
///

0 commit comments

Comments
 (0)