Skip to content

Commit f8ed97e

Browse files
committed
Auto merge of rust-lang#110031 - compiler-errors:generic-elaboration, r=b-naber
Make elaboration generic over input Combines all the `elaborate_*` family of functions into just one, which is an iterator over the same type that you pass in (e.g. elaborating `Predicate` gives `Predicate`s, elaborating `Obligation`s gives `Obligation`s, etc.)
2 parents d1be642 + 2cd0729 commit f8ed97e

File tree

22 files changed

+164
-165
lines changed

22 files changed

+164
-165
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
3333
use rustc_middle::middle::stability::AllowUnstable;
3434
use rustc_middle::ty::fold::FnMutDelegate;
3535
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
36-
use rustc_middle::ty::DynKind;
3736
use rustc_middle::ty::GenericParamDefKind;
3837
use rustc_middle::ty::{self, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
38+
use rustc_middle::ty::{DynKind, ToPredicate};
3939
use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECTS};
4040
use rustc_span::edit_distance::find_best_match_for_name;
4141
use rustc_span::edition::Edition;
@@ -1526,8 +1526,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
15261526

15271527
for (base_trait_ref, span, constness) in regular_traits_refs_spans {
15281528
assert_eq!(constness, ty::BoundConstness::NotConst);
1529-
1530-
for pred in traits::elaborate_trait_ref(tcx, base_trait_ref) {
1529+
let base_pred: ty::Predicate<'tcx> = base_trait_ref.to_predicate(tcx);
1530+
for pred in traits::elaborate(tcx, [base_pred]) {
15311531
debug!("conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", pred);
15321532

15331533
let bound_predicate = pred.kind();

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ pub(super) fn check_type_bounds<'tcx>(
20342034
ObligationCause::new(impl_ty_span, impl_ty_def_id, code)
20352035
};
20362036

2037-
let obligations = tcx
2037+
let obligations: Vec<_> = tcx
20382038
.bound_explicit_item_bounds(trait_ty.def_id)
20392039
.subst_iter_copied(tcx, rebased_substs)
20402040
.map(|(concrete_ty_bound, span)| {
@@ -2044,7 +2044,7 @@ pub(super) fn check_type_bounds<'tcx>(
20442044
.collect();
20452045
debug!("check_type_bounds: item_bounds={:?}", obligations);
20462046

2047-
for mut obligation in util::elaborate_obligations(tcx, obligations) {
2047+
for mut obligation in util::elaborate(tcx, obligations) {
20482048
let normalized_predicate =
20492049
ocx.normalize(&normalize_cause, normalize_param_env, obligation.predicate);
20502050
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
19081908

19091909
let predicates_with_span = tcx.predicates_of(self.body_def_id).predicates.iter().copied();
19101910
// Check elaborated bounds.
1911-
let implied_obligations = traits::elaborate_predicates_with_span(tcx, predicates_with_span);
1911+
let implied_obligations = traits::elaborate(tcx, predicates_with_span);
19121912

19131913
for (pred, obligation_span) in implied_obligations {
19141914
// We lower empty bounds like `Vec<dyn Copy>:` as

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub(super) fn item_bounds(
130130
tcx: TyCtxt<'_>,
131131
def_id: DefId,
132132
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
133-
let bounds = tcx.mk_predicates_from_iter(util::elaborate_predicates(
133+
let bounds = tcx.mk_predicates_from_iter(util::elaborate(
134134
tcx,
135135
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
136136
));

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,14 @@ fn check_predicates<'tcx>(
318318
span: Span,
319319
) {
320320
let instantiated = tcx.predicates_of(impl1_def_id).instantiate(tcx, impl1_substs);
321-
let impl1_predicates: Vec<_> =
322-
traits::elaborate_predicates_with_span(tcx, instantiated.into_iter()).collect();
321+
let impl1_predicates: Vec<_> = traits::elaborate(tcx, instantiated.into_iter()).collect();
323322

324323
let mut impl2_predicates = if impl2_node.is_from_trait() {
325324
// Always applicable traits have to be always applicable without any
326325
// assumptions.
327326
Vec::new()
328327
} else {
329-
traits::elaborate_predicates(
328+
traits::elaborate(
330329
tcx,
331330
tcx.predicates_of(impl2_node.def_id())
332331
.instantiate(tcx, impl2_substs)
@@ -371,11 +370,10 @@ fn check_predicates<'tcx>(
371370
.unwrap();
372371

373372
assert!(!obligations.needs_infer());
374-
impl2_predicates.extend(
375-
traits::elaborate_obligations(tcx, obligations).map(|obligation| obligation.predicate),
376-
)
373+
impl2_predicates
374+
.extend(traits::elaborate(tcx, obligations).map(|obligation| obligation.predicate))
377375
}
378-
impl2_predicates.extend(traits::elaborate_predicates(tcx, always_applicable_traits));
376+
impl2_predicates.extend(traits::elaborate(tcx, always_applicable_traits));
379377

380378
for (predicate, span) in impl1_predicates {
381379
if !impl2_predicates.iter().any(|pred2| trait_predicates_eq(tcx, predicate, *pred2, span)) {

compiler/rustc_hir_typeck/src/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
204204
let mut expected_sig = None;
205205
let mut expected_kind = None;
206206

207-
for (pred, span) in traits::elaborate_predicates_with_span(
207+
for (pred, span) in traits::elaborate(
208208
self.tcx,
209209
// Reverse the obligations here, since `elaborate_*` uses a stack,
210210
// and we want to keep inference generally in the same order of

compiler/rustc_hir_typeck/src/method/confirm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
574574
) -> Option<Span> {
575575
let sized_def_id = self.tcx.lang_items().sized_trait()?;
576576

577-
traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied())
577+
traits::elaborate(self.tcx, predicates.predicates.iter().copied())
578578
// We don't care about regions here.
579579
.filter_map(|pred| match pred.kind().skip_binder() {
580580
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred))

compiler/rustc_hir_typeck/src/method/probe.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1555,8 +1555,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15551555
if !self.predicate_may_hold(&o) {
15561556
result = ProbeResult::NoMatch;
15571557
let parent_o = o.clone();
1558-
let implied_obligations =
1559-
traits::elaborate_obligations(self.tcx, vec![o]);
1558+
let implied_obligations = traits::elaborate(self.tcx, vec![o]);
15601559
for o in implied_obligations {
15611560
let parent = if o == parent_o {
15621561
None

0 commit comments

Comments
 (0)