1
Fork 0

Merge HostPolarity and BoundConstness

This commit is contained in:
Michael Goulet 2024-10-29 23:42:59 +00:00
parent 298c7462c3
commit 802f3a78a6
16 changed files with 66 additions and 81 deletions

View file

@ -545,10 +545,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
polarity: ty::PredicatePolarity::Positive,
}),
None,
Some(match predicate.host {
ty::HostPolarity::Maybe => ty::BoundConstness::ConstIfConst,
ty::HostPolarity::Const => ty::BoundConstness::Const,
}),
Some(predicate.constness),
None,
String::new(),
);
@ -2238,18 +2235,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
(None, _) => Some(cannot_do_this),
// suggested using default post message
(
Some(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst),
Some(ty::BoundConstness::Const | ty::BoundConstness::Maybe),
Some(AppendConstMessage::Default),
) => Some(format!("{cannot_do_this} in const contexts")),
// overridden post message
(
Some(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst),
Some(ty::BoundConstness::Const | ty::BoundConstness::Maybe),
Some(AppendConstMessage::Custom(custom_msg, _)),
) => Some(format!("{cannot_do_this}{custom_msg}")),
// fallback to generic message
(Some(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst), None) => {
None
}
(Some(ty::BoundConstness::Const | ty::BoundConstness::Maybe), None) => None,
}
})
.unwrap_or_else(|| {

View file

@ -47,7 +47,7 @@ fn match_candidate<'tcx>(
obligation: &HostEffectObligation<'tcx>,
candidate: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>,
) -> Result<ThinVec<PredicateObligation<'tcx>>, NoSolution> {
if !candidate.skip_binder().host.satisfies(obligation.predicate.host) {
if !candidate.skip_binder().constness.satisfies(obligation.predicate.constness) {
return Err(NoSolution);
}
@ -135,7 +135,8 @@ fn evaluate_host_effect_from_selection_candiate<'tcx>(
.map(|(trait_ref, _)| {
obligation.with(
tcx,
trait_ref.to_host_effect_clause(tcx, obligation.predicate.host),
trait_ref
.to_host_effect_clause(tcx, obligation.predicate.constness),
)
}),
);