Skip to content

Commit dc47214

Browse files
committed
don't pass Certainty which is always Yes
1 parent e2477fb commit dc47214

4 files changed

Lines changed: 21 additions & 35 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ where
213213
ecx: &mut EvalCtxt<'_, D>,
214214
goal: Goal<I, Self>,
215215
impl_def_id: I::ImplId,
216-
then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResultOrRerunNonErased<I>,
216+
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
217217
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased>;
218218

219219
/// If the predicate contained an error, we want to avoid emitting unnecessary trait
@@ -552,8 +552,8 @@ where
552552
if cx.impl_is_default(impl_def_id) {
553553
return Ok(());
554554
}
555-
match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
556-
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
555+
match G::consider_impl_candidate(self, goal, impl_def_id, |ecx| {
556+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
557557
})
558558
.map_err_to_rerun()?
559559
{
@@ -1173,11 +1173,10 @@ where
11731173
return Ok(());
11741174
}
11751175

1176-
match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
1176+
match G::consider_impl_candidate(self, goal, impl_def_id, |ecx| {
11771177
if ecx.shallow_resolve(self_ty).is_ty_var() {
11781178
// We force the certainty of impl candidates to be `Maybe`.
1179-
let certainty = certainty.and(Certainty::AMBIGUOUS);
1180-
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
1179+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
11811180
} else {
11821181
// We don't want to use impls if they constrain the opaque.
11831182
//

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ where
137137
ecx: &mut EvalCtxt<'_, D>,
138138
goal: Goal<I, Self>,
139139
impl_def_id: I::ImplId,
140-
then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResultOrRerunNonErased<I>,
140+
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
141141
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
142142
let cx = ecx.cx();
143143

@@ -148,11 +148,9 @@ where
148148
return Err(NoSolution.into());
149149
}
150150

151-
// TODO: certainty can only be yes here...
152-
let impl_polarity = cx.impl_polarity(impl_def_id);
153-
let certainty = match impl_polarity {
151+
match cx.impl_polarity(impl_def_id) {
154152
ty::ImplPolarity::Negative => return Err(NoSolution.into()),
155-
ty::ImplPolarity::Positive => Certainty::Yes,
153+
ty::ImplPolarity::Positive => (),
156154
};
157155

158156
if !cx.impl_is_const(impl_def_id) {
@@ -186,7 +184,7 @@ where
186184
});
187185
ecx.add_goals(GoalSource::ImplWhereBound, const_conditions)?;
188186

189-
then(ecx, certainty)
187+
then(ecx)
190188
})
191189
}
192190

compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ where
254254
ecx: &mut EvalCtxt<'_, D>,
255255
goal: Goal<I, NormalizesTo<I>>,
256256
impl_def_id: I::ImplId,
257-
then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResultOrRerunNonErased<I>,
257+
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
258258
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
259259
let cx = ecx.cx();
260260

@@ -379,10 +379,10 @@ where
379379
// This is not the case here and we only prefer adding an ambiguous
380380
// nested goal for consistency.
381381
ecx.add_goal(GoalSource::Misc, goal.with(cx, PredicateKind::Ambiguous))?;
382-
return then(ecx, Certainty::Yes);
382+
return then(ecx);
383383
} else {
384384
ecx.instantiate_normalizes_to_as_rigid(goal)?;
385-
return then(ecx, Certainty::Yes);
385+
return then(ecx);
386386
}
387387
} else {
388388
return error_response(ecx, cx.delay_bug("missing item"));

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ where
6161
ecx: &mut EvalCtxt<'_, D>,
6262
goal: Goal<I, TraitPredicate<I>>,
6363
impl_def_id: I::ImplId,
64-
then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResultOrRerunNonErased<I>,
64+
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
6565
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
6666
let cx = ecx.cx();
6767

@@ -72,29 +72,18 @@ where
7272
return Err(NoSolution.into());
7373
}
7474

75-
// TODO: this comment is no longer true and maximal_certainty can only be `Yes`
76-
// An upper bound of the certainty of this goal, used to lower the certainty
77-
// of reservation impl to ambiguous during coherence.
78-
let impl_polarity = cx.impl_polarity(impl_def_id);
79-
let maximal_certainty = match (impl_polarity, goal.predicate.polarity) {
80-
// Impl matches polarity
81-
(ty::ImplPolarity::Positive, ty::PredicatePolarity::Positive)
82-
| (ty::ImplPolarity::Negative, ty::PredicatePolarity::Negative) => {
83-
if ecx.typing_mode().is_reflection()
84-
&& !cx.is_fully_generic_for_reflection(impl_def_id)
85-
{
86-
return Err(NoSolution.into());
87-
} else {
88-
Certainty::Yes
89-
}
90-
}
91-
75+
match (cx.impl_polarity(impl_def_id), goal.predicate.polarity) {
9276
// Impl doesn't match polarity
9377
(ty::ImplPolarity::Positive, ty::PredicatePolarity::Negative)
9478
| (ty::ImplPolarity::Negative, ty::PredicatePolarity::Positive) => {
9579
return Err(NoSolution.into());
9680
}
97-
};
81+
_ => {}
82+
}
83+
84+
if ecx.typing_mode().is_reflection() && !cx.is_fully_generic_for_reflection(impl_def_id) {
85+
return Err(NoSolution.into());
86+
}
9887

9988
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
10089
let impl_args = ecx.fresh_args_for_item(impl_def_id.into());
@@ -120,7 +109,7 @@ where
120109
.map(|pred| goal.with(cx, pred)),
121110
)?;
122111

123-
then(ecx, maximal_certainty)
112+
then(ecx)
124113
})
125114
}
126115

0 commit comments

Comments
 (0)