Rollup merge of #143066 - compiler-errors:let-chain-solver, r=lcnr
Use let chains in the new solver Self-explanatory Let chains are stable as of today r? lcnr
This commit is contained in:
@@ -383,11 +383,11 @@ where
|
||||
|
||||
let mut candidates = vec![];
|
||||
|
||||
if let TypingMode::Coherence = self.typing_mode() {
|
||||
if let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal) {
|
||||
if let TypingMode::Coherence = self.typing_mode()
|
||||
&& let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal)
|
||||
{
|
||||
return vec![candidate];
|
||||
}
|
||||
}
|
||||
|
||||
self.assemble_alias_bound_candidates(goal, &mut candidates);
|
||||
self.assemble_param_env_candidates(goal, &mut candidates);
|
||||
|
||||
@@ -997,12 +997,12 @@ where
|
||||
}
|
||||
|
||||
fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Ambiguous> {
|
||||
if let ty::Alias(ty::Projection, alias_ty) = ty.kind() {
|
||||
if let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())? {
|
||||
return Ok(term.expect_ty());
|
||||
}
|
||||
}
|
||||
|
||||
if let ty::Alias(ty::Projection, alias_ty) = ty.kind()
|
||||
&& let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())?
|
||||
{
|
||||
Ok(term.expect_ty())
|
||||
} else {
|
||||
ty.try_super_fold_with(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,21 +42,19 @@ where
|
||||
goal: Goal<I, Self>,
|
||||
assumption: I::Clause,
|
||||
) -> Result<(), NoSolution> {
|
||||
if let Some(host_clause) = assumption.as_host_effect_clause() {
|
||||
if host_clause.def_id() == goal.predicate.def_id()
|
||||
if let Some(host_clause) = assumption.as_host_effect_clause()
|
||||
&& host_clause.def_id() == goal.predicate.def_id()
|
||||
&& host_clause.constness().satisfies(goal.predicate.constness)
|
||||
{
|
||||
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
|
||||
&& DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
|
||||
goal.predicate.trait_ref.args,
|
||||
host_clause.skip_binder().trait_ref.args,
|
||||
) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
)
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err(NoSolution)
|
||||
}
|
||||
}
|
||||
|
||||
fn match_assumption(
|
||||
ecx: &mut EvalCtxt<'_, D>,
|
||||
|
||||
@@ -429,8 +429,8 @@ where
|
||||
// If we have run this goal before, and it was stalled, check that any of the goal's
|
||||
// args have changed. Otherwise, we don't need to re-run the goal because it'll remain
|
||||
// stalled, since it'll canonicalize the same way and evaluation is pure.
|
||||
if let Some(stalled_on) = stalled_on {
|
||||
if !stalled_on.stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value))
|
||||
if let Some(stalled_on) = stalled_on
|
||||
&& !stalled_on.stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value))
|
||||
&& !self
|
||||
.delegate
|
||||
.opaque_types_storage_num_entries()
|
||||
@@ -445,7 +445,6 @@ where
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
|
||||
let mut goal_evaluation =
|
||||
@@ -833,15 +832,12 @@ where
|
||||
|
||||
match t.kind() {
|
||||
ty::Infer(ty::TyVar(vid)) => {
|
||||
if let ty::TermKind::Ty(term) = self.term.kind() {
|
||||
if let ty::Infer(ty::TyVar(term_vid)) = term.kind() {
|
||||
if self.delegate.root_ty_var(vid)
|
||||
== self.delegate.root_ty_var(term_vid)
|
||||
if let ty::TermKind::Ty(term) = self.term.kind()
|
||||
&& let ty::Infer(ty::TyVar(term_vid)) = term.kind()
|
||||
&& self.delegate.root_ty_var(vid) == self.delegate.root_ty_var(term_vid)
|
||||
{
|
||||
return ControlFlow::Break(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.check_nameable(self.delegate.universe_of_ty(vid).unwrap())?;
|
||||
}
|
||||
@@ -860,16 +856,13 @@ where
|
||||
fn visit_const(&mut self, c: I::Const) -> Self::Result {
|
||||
match c.kind() {
|
||||
ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
|
||||
if let ty::TermKind::Const(term) = self.term.kind() {
|
||||
if let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
|
||||
{
|
||||
if self.delegate.root_const_var(vid)
|
||||
if let ty::TermKind::Const(term) = self.term.kind()
|
||||
&& let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
|
||||
&& self.delegate.root_const_var(vid)
|
||||
== self.delegate.root_const_var(term_vid)
|
||||
{
|
||||
return ControlFlow::Break(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.check_nameable(self.delegate.universe_of_ct(vid).unwrap())
|
||||
}
|
||||
|
||||
@@ -112,19 +112,18 @@ where
|
||||
goal: Goal<I, Self>,
|
||||
assumption: I::Clause,
|
||||
) -> Result<(), NoSolution> {
|
||||
if let Some(projection_pred) = assumption.as_projection_clause() {
|
||||
if projection_pred.item_def_id() == goal.predicate.def_id() {
|
||||
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
|
||||
if let Some(projection_pred) = assumption.as_projection_clause()
|
||||
&& projection_pred.item_def_id() == goal.predicate.def_id()
|
||||
&& DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
|
||||
goal.predicate.alias.args,
|
||||
projection_pred.skip_binder().projection_term.args,
|
||||
) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
)
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err(NoSolution)
|
||||
}
|
||||
}
|
||||
|
||||
fn match_assumption(
|
||||
ecx: &mut EvalCtxt<'_, D>,
|
||||
|
||||
@@ -127,34 +127,33 @@ where
|
||||
goal: Goal<I, Self>,
|
||||
assumption: I::Clause,
|
||||
) -> Result<(), NoSolution> {
|
||||
if let Some(trait_clause) = assumption.as_trait_clause() {
|
||||
if trait_clause.polarity() != goal.predicate.polarity {
|
||||
return Err(NoSolution);
|
||||
fn trait_def_id_matches<I: Interner>(
|
||||
cx: I,
|
||||
clause_def_id: I::DefId,
|
||||
goal_def_id: I::DefId,
|
||||
) -> bool {
|
||||
clause_def_id == goal_def_id
|
||||
// PERF(sized-hierarchy): Sizedness supertraits aren't elaborated to improve perf, so
|
||||
// check for a `MetaSized` supertrait being matched against a `Sized` assumption.
|
||||
//
|
||||
// `PointeeSized` bounds are syntactic sugar for a lack of bounds so don't need this.
|
||||
|| (cx.is_lang_item(clause_def_id, TraitSolverLangItem::Sized)
|
||||
&& cx.is_lang_item(goal_def_id, TraitSolverLangItem::MetaSized))
|
||||
}
|
||||
|
||||
if trait_clause.def_id() == goal.predicate.def_id() {
|
||||
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
|
||||
if let Some(trait_clause) = assumption.as_trait_clause()
|
||||
&& trait_clause.polarity() == goal.predicate.polarity
|
||||
&& trait_def_id_matches(ecx.cx(), trait_clause.def_id(), goal.predicate.def_id())
|
||||
&& DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
|
||||
goal.predicate.trait_ref.args,
|
||||
trait_clause.skip_binder().trait_ref.args,
|
||||
) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// PERF(sized-hierarchy): Sizedness supertraits aren't elaborated to improve perf, so
|
||||
// check for a `Sized` subtrait when looking for `MetaSized`. `PointeeSized` bounds
|
||||
// are syntactic sugar for a lack of bounds so don't need this.
|
||||
if ecx.cx().is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::MetaSized)
|
||||
&& ecx.cx().is_lang_item(trait_clause.def_id(), TraitSolverLangItem::Sized)
|
||||
)
|
||||
{
|
||||
let meta_sized_clause =
|
||||
trait_predicate_with_def_id(ecx.cx(), trait_clause, goal.predicate.def_id());
|
||||
return Self::fast_reject_assumption(ecx, goal, meta_sized_clause);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
} else {
|
||||
Err(NoSolution)
|
||||
}
|
||||
}
|
||||
|
||||
fn match_assumption(
|
||||
ecx: &mut EvalCtxt<'_, D>,
|
||||
|
||||
@@ -320,12 +320,12 @@ pub fn supertrait_def_ids<I: Interner>(
|
||||
let trait_def_id = stack.pop()?;
|
||||
|
||||
for (predicate, _) in cx.explicit_super_predicates_of(trait_def_id).iter_identity() {
|
||||
if let ty::ClauseKind::Trait(data) = predicate.kind().skip_binder() {
|
||||
if set.insert(data.def_id()) {
|
||||
if let ty::ClauseKind::Trait(data) = predicate.kind().skip_binder()
|
||||
&& set.insert(data.def_id())
|
||||
{
|
||||
stack.push(data.def_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(trait_def_id)
|
||||
})
|
||||
|
||||
@@ -284,12 +284,12 @@ where
|
||||
}
|
||||
|
||||
// If they have no bound vars, relate normally.
|
||||
if let Some(a_inner) = a.no_bound_vars() {
|
||||
if let Some(b_inner) = b.no_bound_vars() {
|
||||
if let Some(a_inner) = a.no_bound_vars()
|
||||
&& let Some(b_inner) = b.no_bound_vars()
|
||||
{
|
||||
self.relate(a_inner, b_inner)?;
|
||||
return Ok(a);
|
||||
}
|
||||
};
|
||||
|
||||
match self.ambient_variance {
|
||||
// Checks whether `for<..> sub <: for<..> sup` holds.
|
||||
|
||||
@@ -80,8 +80,8 @@ impl<X: Cx> GlobalCache<X> {
|
||||
mut candidate_is_applicable: impl FnMut(&NestedGoals<X>) -> bool,
|
||||
) -> Option<CacheData<'a, X>> {
|
||||
let entry = self.map.get(&input)?;
|
||||
if let Some(Success { required_depth, ref nested_goals, ref result }) = entry.success {
|
||||
if available_depth.cache_entry_is_applicable(required_depth)
|
||||
if let Some(Success { required_depth, ref nested_goals, ref result }) = entry.success
|
||||
&& available_depth.cache_entry_is_applicable(required_depth)
|
||||
&& candidate_is_applicable(nested_goals)
|
||||
{
|
||||
return Some(CacheData {
|
||||
@@ -91,13 +91,12 @@ impl<X: Cx> GlobalCache<X> {
|
||||
nested_goals,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let additional_depth = available_depth.0;
|
||||
if let Some(WithOverflow { nested_goals, result }) =
|
||||
entry.with_overflow.get(&additional_depth)
|
||||
&& candidate_is_applicable(nested_goals)
|
||||
{
|
||||
if candidate_is_applicable(nested_goals) {
|
||||
return Some(CacheData {
|
||||
result: cx.get_tracked(result),
|
||||
required_depth: additional_depth,
|
||||
@@ -105,7 +104,6 @@ impl<X: Cx> GlobalCache<X> {
|
||||
nested_goals,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user