Skip to content

Commit 60ba47e

Browse files
Rollup merge of #158355 - jdonszelmann:fixuop, r=lcnr
Fixup the refactoring errors in #156246 r? @lcnr
2 parents f9c9828 + 2625886 commit 60ba47e

5 files changed

Lines changed: 32 additions & 62 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ where
461461
Ok(i) => Ok(i),
462462
Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
463463
Err(NoSolutionOrRerunNonErased::RerunNonErased(_)) => {
464-
// check th t the opaque_accesses state mirrors the result we got.
464+
// Check that the opaque_accesses state mirrors the result we got.
465465
assert!(opaque_accesses.should_bail().is_err());
466466
Err(NoSolution)
467467
}
@@ -1505,7 +1505,7 @@ where
15051505
uv: ty::UnevaluatedConst<I>,
15061506
) -> Result<Option<I::Const>, RerunNonErased> {
15071507
if self.typing_mode().is_erased_not_coherence() {
1508-
self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)?;
1508+
match self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)? {}
15091509
}
15101510

15111511
Ok(self.delegate.evaluate_const(param_env, uv))
@@ -1579,7 +1579,7 @@ where
15791579
symbol: I::Symbol,
15801580
) -> Result<bool, RerunNonErased> {
15811581
if self.typing_mode().is_erased_not_coherence() {
1582-
self.opaque_accesses.rerun_always(RerunReason::MayUseUnstableFeature)?;
1582+
match self.opaque_accesses.rerun_always(RerunReason::MayUseUnstableFeature)? {}
15831583
}
15841584

15851585
Ok(may_use_unstable_feature(&**self.delegate, param_env, symbol))

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ where
9898

9999
outer.opaque_accesses.update(nested.opaque_accesses)?;
100100

101-
let r = match r.map_err_to_rerun()? {
102-
Ok(i) => Ok(i),
103-
Err(NoSolution) => Err(NoSolution),
104-
};
101+
// Unwrap is unreachable, we would have returned on the line above.
102+
let r = r.map_err_to_rerun().unwrap();
105103

106104
if !nested.inspect.is_noop() {
107105
let probe_kind = probe_kind(&r);

compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,10 @@ where
8181
None
8282
},
8383
|ecx| {
84-
ecx.probe(|&result| ProbeKind::RigidAlias { result })
85-
.enter(|this| {
86-
this.structurally_instantiate_normalizes_to_term(
87-
goal,
88-
goal.predicate.alias,
89-
);
90-
this.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
91-
})
92-
.map_err(Into::into)
84+
ecx.probe(|&result| ProbeKind::RigidAlias { result }).enter(|this| {
85+
this.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias);
86+
this.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
87+
})
9388
},
9489
)
9590
}
@@ -340,11 +335,9 @@ where
340335
GoalSource::Misc,
341336
goal.with(cx, PredicateKind::Ambiguous),
342337
);
343-
return ecx
344-
.evaluate_added_goals_and_make_canonical_response(
345-
Certainty::Yes,
346-
)
347-
.map_err(Into::into);
338+
return ecx.evaluate_added_goals_and_make_canonical_response(
339+
Certainty::Yes,
340+
);
348341
}
349342
// Outside of coherence, we treat the associated item as rigid instead.
350343
ty::TypingMode::Typeck { .. }
@@ -356,11 +349,9 @@ where
356349
goal,
357350
goal.predicate.alias,
358351
);
359-
return ecx
360-
.evaluate_added_goals_and_make_canonical_response(
361-
Certainty::Yes,
362-
)
363-
.map_err(Into::into);
352+
return ecx.evaluate_added_goals_and_make_canonical_response(
353+
Certainty::Yes,
354+
);
364355
}
365356
};
366357
}
@@ -390,10 +381,10 @@ where
390381
// This is not the case here and we only prefer adding an ambiguous
391382
// nested goal for consistency.
392383
ecx.add_goal(GoalSource::Misc, goal.with(cx, PredicateKind::Ambiguous));
393-
return then(ecx, Certainty::Yes).map_err(Into::into);
384+
return then(ecx, Certainty::Yes);
394385
} else {
395386
ecx.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias);
396-
return then(ecx, Certainty::Yes).map_err(Into::into);
387+
return then(ecx, Certainty::Yes);
397388
}
398389
} else {
399390
return error_response(ecx, cx.delay_bug("missing item"));
@@ -461,7 +452,7 @@ where
461452
};
462453

463454
ecx.instantiate_normalizes_to_term(goal, term);
464-
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes).map_err(Into::into)
455+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
465456
})
466457
}
467458

@@ -561,7 +552,6 @@ where
561552
pred,
562553
[(GoalSource::ImplWhereBound, goal.with(cx, output_is_sized_pred))],
563554
)
564-
.map_err(Into::into)
565555
}
566556

567557
fn consider_builtin_async_fn_trait_candidates(
@@ -748,8 +738,9 @@ where
748738
// and opaque types: If the `self_ty` is `Sized`, then the metadata is `()`.
749739
// FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't
750740
// exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`.
751-
let alias_bound_result =
752-
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
741+
let alias_bound_result = ecx
742+
.probe_builtin_trait_candidate(BuiltinImplSource::Misc)
743+
.enter(|ecx| {
753744
let sized_predicate = ty::TraitRef::new(
754745
cx,
755746
cx.require_trait_lang_item(SolverTraitLangItem::Sized),
@@ -758,12 +749,8 @@ where
758749
ecx.add_goal(GoalSource::Misc, goal.with(cx, sized_predicate));
759750
ecx.instantiate_normalizes_to_term(goal, Ty::new_unit(cx).into());
760751
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
761-
});
762-
763-
let alias_bound_result = match alias_bound_result.map_err_to_rerun()? {
764-
Ok(i) => Ok(i),
765-
Err(NoSolution) => Err(NoSolution),
766-
};
752+
})
753+
.map_err_to_rerun()?;
767754

768755
// In case the dummy alias-bound candidate does not apply, we instead treat this projection
769756
// as rigid.
@@ -873,7 +860,6 @@ where
873860
// but that's already proven by the generator being WF.
874861
[],
875862
)
876-
.map_err(Into::into)
877863
}
878864

879865
fn consider_builtin_fused_iterator_candidate(

compiler/rustc_next_trait_solver/src/solve/search_graph.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::marker::PhantomData;
44
use rustc_type_ir::data_structures::ensure_sufficient_stack;
55
use rustc_type_ir::search_graph::{self, PathKind};
66
use rustc_type_ir::solve::{
7-
AccessedOpaques, CanonicalInput, Certainty, NoSolution, NoSolutionOrRerunNonErased, QueryResult,
7+
AccessedOpaques, CanonicalInput, Certainty, NoSolution, QueryResult, RerunResultExt,
88
};
99
use rustc_type_ir::{Interner, MayBeErased, TypingMode};
1010

@@ -141,17 +141,8 @@ where
141141
) -> (QueryResult<I>, AccessedOpaques<I>) {
142142
ensure_sufficient_stack(|| {
143143
EvalCtxt::enter_canonical(cx, search_graph, input, inspect, |ecx, goal| {
144-
let result = ecx.compute_goal(goal);
145-
146-
// if we're in `RerunNonErased`, don't even bother with inspect,
147-
// and immediately return
148-
let result = match result {
149-
Ok(i) => Ok(i),
150-
Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
151-
Err(NoSolutionOrRerunNonErased::RerunNonErased(e)) => {
152-
return Err(e.into());
153-
}
154-
};
144+
// if we're in `RerunNonErased`, don't even bother with inspect, and immediately return
145+
let result = ecx.compute_goal(goal).map_err_to_rerun()?;
155146

156147
ecx.inspect.query_result(result);
157148
result.map_err(Into::into)

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ where
119119
.map(|pred| goal.with(cx, pred)),
120120
);
121121

122-
then(ecx, maximal_certainty).map_err(Into::into)
122+
then(ecx, maximal_certainty)
123123
})
124124
}
125125

@@ -399,7 +399,6 @@ where
399399
pred,
400400
[(GoalSource::ImplWhereBound, goal.with(cx, output_is_sized_pred))],
401401
)
402-
.map_err(Into::into)
403402
}
404403

405404
fn consider_builtin_async_fn_trait_candidates(
@@ -450,7 +449,6 @@ where
450449
.chain(nested_preds.into_iter().map(|pred| goal.with(cx, pred)))
451450
.map(|goal| (GoalSource::ImplWhereBound, goal)),
452451
)
453-
.map_err(Into::into)
454452
}
455453

456454
fn consider_builtin_async_fn_kind_helper_candidate(
@@ -696,7 +694,7 @@ where
696694
goal.predicate.trait_ref.args.type_at(1),
697695
assume,
698696
)?;
699-
ecx.evaluate_added_goals_and_make_canonical_response(certainty).map_err(Into::into)
697+
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
700698
},
701699
)
702700
}
@@ -1085,7 +1083,6 @@ where
10851083
ecx.try_evaluate_added_goals()
10861084
},
10871085
)
1088-
.map_err(Into::into)
10891086
})
10901087
.is_ok()
10911088
};
@@ -1124,11 +1121,9 @@ where
11241121
return Err(NoSolution.into());
11251122
};
11261123
if matching_projections.next().is_some() {
1127-
return ecx
1128-
.evaluate_added_goals_and_make_canonical_response(
1129-
Certainty::AMBIGUOUS,
1130-
)
1131-
.map_err(Into::into);
1124+
return ecx.evaluate_added_goals_and_make_canonical_response(
1125+
Certainty::AMBIGUOUS,
1126+
);
11321127
}
11331128
ecx.enter_forall_with_assumptions(
11341129
target_projection,
@@ -1156,7 +1151,7 @@ where
11561151
Goal::new(ecx.cx(), param_env, ty::OutlivesPredicate(a_region, b_region)),
11571152
);
11581153

1159-
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes).map_err(Into::into)
1154+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
11601155
})
11611156
}
11621157

0 commit comments

Comments
 (0)