Skip to content

Commit 70d978b

Browse files
committed
Auto merge of #125150 - compiler-errors:uplift-goal, r=lcnr
Uplift `Goal` to `rustc_type_ir` r? lcnr This also renames `ToPredicate` to `Uplift`, which is conceptually a helper trait for `Into`-like operations for things that need a `TyCtxt`. This name is based off of the same named trait from a-mir-formality.
2 parents 2d89cee + 7b3d6da commit 70d978b

File tree

54 files changed

+328
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+328
-298
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use rustc_middle::mir::{
2424
};
2525
use rustc_middle::ty::print::PrintTraitRefExt as _;
2626
use rustc_middle::ty::{
27-
self, suggest_constraining_type_params, PredicateKind, ToPredicate, Ty, TyCtxt,
28-
TypeSuperVisitable, TypeVisitor,
27+
self, suggest_constraining_type_params, PredicateKind, Ty, TyCtxt, TypeSuperVisitable,
28+
TypeVisitor, Upcast,
2929
};
3030
use rustc_middle::util::CallKind;
3131
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
@@ -1915,7 +1915,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19151915
self.infcx.err_ctxt().suggest_derive(
19161916
&obligation,
19171917
err,
1918-
trait_ref.to_predicate(self.infcx.tcx),
1918+
trait_ref.upcast(self.infcx.tcx),
19191919
);
19201920
}
19211921
}

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::{self as hir, BindingMode, ByRef, Node};
99
use rustc_infer::traits;
1010
use rustc_middle::bug;
1111
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
12-
use rustc_middle::ty::{self, InstanceDef, ToPredicate, Ty, TyCtxt};
12+
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt, Upcast};
1313
use rustc_middle::{
1414
hir::place::PlaceBase,
1515
mir::{self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location},
@@ -1255,7 +1255,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
12551255
self.infcx.err_ctxt().suggest_derive(
12561256
&obligation,
12571257
err,
1258-
trait_ref.to_predicate(self.infcx.tcx),
1258+
trait_ref.upcast(self.infcx.tcx),
12591259
);
12601260
}
12611261
Some(errors) => {

compiler/rustc_borrowck/src/type_check/canonical.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::ErrorGuaranteed;
44
use rustc_infer::infer::canonical::Canonical;
55
use rustc_middle::bug;
66
use rustc_middle::mir::ConstraintCategory;
7-
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
7+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast};
88
use rustc_span::def_id::DefId;
99
use rustc_span::Span;
1010
use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput};
@@ -115,7 +115,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
115115

116116
pub(super) fn prove_predicates(
117117
&mut self,
118-
predicates: impl IntoIterator<Item: ToPredicate<'tcx> + std::fmt::Debug>,
118+
predicates: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + std::fmt::Debug>,
119119
locations: Locations,
120120
category: ConstraintCategory<'tcx>,
121121
) {
@@ -127,12 +127,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
127127
#[instrument(skip(self), level = "debug")]
128128
pub(super) fn prove_predicate(
129129
&mut self,
130-
predicate: impl ToPredicate<'tcx> + std::fmt::Debug,
130+
predicate: impl Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + std::fmt::Debug,
131131
locations: Locations,
132132
category: ConstraintCategory<'tcx>,
133133
) {
134134
let param_env = self.param_env;
135-
let predicate = predicate.to_predicate(self.tcx());
135+
let predicate = predicate.upcast(self.tcx());
136136
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
137137
locations,
138138
category,

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,10 @@ impl<'bccx, 'tcx> ObligationEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx
546546
self.type_checker.param_env
547547
}
548548

549-
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
549+
fn register_predicates(
550+
&mut self,
551+
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
552+
) {
550553
self.register_obligations(
551554
obligations
552555
.into_iter()

compiler/rustc_hir_analysis/src/bounds.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! [`rustc_middle::ty`] form.
33
44
use rustc_hir::LangItem;
5-
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
5+
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
66
use rustc_span::Span;
77

88
/// Collects together a list of type bounds. These lists of bounds occur in many places
@@ -34,7 +34,7 @@ impl<'tcx> Bounds<'tcx> {
3434
span: Span,
3535
) {
3636
self.clauses
37-
.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx), span));
37+
.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).upcast(tcx), span));
3838
}
3939

4040
pub fn push_trait_bound(
@@ -49,7 +49,7 @@ impl<'tcx> Bounds<'tcx> {
4949
.map_bound(|trait_ref| {
5050
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
5151
})
52-
.to_predicate(tcx),
52+
.upcast(tcx),
5353
span,
5454
);
5555
// FIXME(-Znext-solver): We can likely remove this hack once the new trait solver lands.
@@ -67,7 +67,7 @@ impl<'tcx> Bounds<'tcx> {
6767
span: Span,
6868
) {
6969
self.clauses.push((
70-
projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx),
70+
projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).upcast(tcx),
7171
span,
7272
));
7373
}
@@ -76,7 +76,7 @@ impl<'tcx> Bounds<'tcx> {
7676
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
7777
let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]);
7878
// Preferable to put this obligation first, since we report better errors for sized ambiguity.
79-
self.clauses.insert(0, (trait_ref.to_predicate(tcx), span));
79+
self.clauses.insert(0, (trait_ref.upcast(tcx), span));
8080
}
8181

8282
pub fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_infer::traits::{util, FulfillmentError};
1414
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1515
use rustc_middle::ty::fold::BottomUpFolder;
1616
use rustc_middle::ty::util::ExplicitSelf;
17-
use rustc_middle::ty::ToPredicate;
17+
use rustc_middle::ty::Upcast;
1818
use rustc_middle::ty::{
1919
self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
2020
};
@@ -2211,7 +2211,7 @@ fn param_env_with_gat_bounds<'tcx>(
22112211
},
22122212
bound_vars,
22132213
)
2214-
.to_predicate(tcx),
2214+
.upcast(tcx),
22152215
),
22162216
};
22172217
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use rustc_middle::query::Providers;
2020
use rustc_middle::ty::print::with_no_trimmed_paths;
2121
use rustc_middle::ty::trait_def::TraitSpecializationKind;
2222
use rustc_middle::ty::{
23-
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
24-
TypeVisitable, TypeVisitableExt, TypeVisitor,
23+
self, AdtKind, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
24+
TypeVisitable, TypeVisitableExt, TypeVisitor, Upcast,
2525
};
2626
use rustc_middle::ty::{GenericArgKind, GenericArgs};
2727
use rustc_middle::{bug, span_bug};
@@ -685,7 +685,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
685685
// `Self: 'me`.)
686686
bounds.insert(
687687
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty_param, region_param))
688-
.to_predicate(tcx),
688+
.upcast(tcx),
689689
);
690690
}
691691
}
@@ -730,7 +730,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
730730
region_a_param,
731731
region_b_param,
732732
))
733-
.to_predicate(tcx),
733+
.upcast(tcx),
734734
);
735735
}
736736
}

compiler/rustc_hir_analysis/src/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_infer::traits::ObligationCause;
2929
use rustc_middle::hir::nested_filter;
3030
use rustc_middle::query::Providers;
3131
use rustc_middle::ty::util::{Discr, IntTypeExt};
32-
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, ToPredicate, Ty, TyCtxt};
32+
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, Upcast};
3333
use rustc_middle::{bug, span_bug};
3434
use rustc_span::symbol::{kw, sym, Ident, Symbol};
3535
use rustc_span::{Span, DUMMY_SP};
@@ -1665,7 +1665,7 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate
16651665
def_id, inferred_outlives,
16661666
);
16671667
let inferred_outlives_iter =
1668-
inferred_outlives.iter().map(|(clause, span)| ((*clause).to_predicate(tcx), *span));
1668+
inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
16691669
if result.predicates.is_empty() {
16701670
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
16711671
} else {

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+18-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def::DefKind;
99
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_hir::intravisit::{self, Visitor};
1111
use rustc_middle::ty::{self, Ty, TyCtxt};
12-
use rustc_middle::ty::{GenericPredicates, ImplTraitInTraitData, ToPredicate};
12+
use rustc_middle::ty::{GenericPredicates, ImplTraitInTraitData, Upcast};
1313
use rustc_middle::{bug, span_bug};
1414
use rustc_span::symbol::Ident;
1515
use rustc_span::{Span, DUMMY_SP};
@@ -40,11 +40,13 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
4040
// `tcx.def_span(def_id);`
4141
let span = DUMMY_SP;
4242

43-
result.predicates =
44-
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
45-
ty::TraitRef::identity(tcx, def_id).to_predicate(tcx),
46-
span,
47-
))));
43+
result.predicates = tcx.arena.alloc_from_iter(
44+
result
45+
.predicates
46+
.iter()
47+
.copied()
48+
.chain(std::iter::once((ty::TraitRef::identity(tcx, def_id).upcast(tcx), span))),
49+
);
4850
}
4951
debug!("predicates_of(def_id={:?}) = {:?}", def_id, result);
5052
result
@@ -165,7 +167,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
165167
// (see below). Recall that a default impl is not itself an impl, but rather a
166168
// set of defaults that can be incorporated into another impl.
167169
if let Some(trait_ref) = is_default_impl_trait {
168-
predicates.insert((trait_ref.to_predicate(tcx), tcx.def_span(def_id)));
170+
predicates.insert((trait_ref.upcast(tcx), tcx.def_span(def_id)));
169171
}
170172

171173
// Collect the predicates that were written inline by the user on each
@@ -196,10 +198,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
196198
.no_bound_vars()
197199
.expect("const parameters cannot be generic");
198200
let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty);
199-
predicates.insert((
200-
ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx),
201-
param.span,
202-
));
201+
predicates
202+
.insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));
203203
}
204204
}
205205
}
@@ -228,7 +228,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
228228
ty::ClauseKind::WellFormed(ty.into()),
229229
bound_vars,
230230
);
231-
predicates.insert((predicate.to_predicate(tcx), span));
231+
predicates.insert((predicate.upcast(tcx), span));
232232
}
233233
}
234234

@@ -257,8 +257,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
257257
)
258258
}
259259
};
260-
let pred = ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
261-
.to_predicate(tcx);
260+
let pred =
261+
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2)).upcast(tcx);
262262
(pred, span)
263263
}))
264264
}
@@ -328,12 +328,12 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
328328
let span = tcx.def_span(param.def_id);
329329
predicates.push((
330330
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(orig_lifetime, dup_lifetime))
331-
.to_predicate(tcx),
331+
.upcast(tcx),
332332
span,
333333
));
334334
predicates.push((
335335
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(dup_lifetime, orig_lifetime))
336-
.to_predicate(tcx),
336+
.upcast(tcx),
337337
span,
338338
));
339339
}
@@ -354,8 +354,7 @@ fn const_evaluatable_predicates_of(
354354
let ct = ty::Const::from_anon_const(self.tcx, c.def_id);
355355
if let ty::ConstKind::Unevaluated(_) = ct.kind() {
356356
let span = self.tcx.def_span(c.def_id);
357-
self.preds
358-
.insert((ty::ClauseKind::ConstEvaluatable(ct).to_predicate(self.tcx), span));
357+
self.preds.insert((ty::ClauseKind::ConstEvaluatable(ct).upcast(self.tcx), span));
359358
}
360359
}
361360

@@ -694,7 +693,7 @@ pub(super) fn type_param_predicates(
694693
&& param_id == item_hir_id
695694
{
696695
let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id.to_def_id());
697-
extend = Some((identity_trait_ref.to_predicate(tcx), item.span));
696+
extend = Some((identity_trait_ref.upcast(tcx), item.span));
698697
}
699698

700699
let icx = ItemCtxt::new(tcx, item_def_id);

compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_lint_defs::builtin::UNUSED_ASSOCIATED_TYPE_BOUNDS;
99
use rustc_middle::span_bug;
1010
use rustc_middle::ty::fold::BottomUpFolder;
1111
use rustc_middle::ty::{self, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable};
12-
use rustc_middle::ty::{DynKind, ToPredicate};
12+
use rustc_middle::ty::{DynKind, Upcast};
1313
use rustc_span::{ErrorGuaranteed, Span};
1414
use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
1515
use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations};
@@ -119,7 +119,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
119119
.filter(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id()));
120120

121121
for (base_trait_ref, span) in regular_traits_refs_spans {
122-
let base_pred: ty::Predicate<'tcx> = base_trait_ref.to_predicate(tcx);
122+
let base_pred: ty::Predicate<'tcx> = base_trait_ref.upcast(tcx);
123123
for pred in traits::elaborate(tcx, [base_pred]).filter_only_self() {
124124
debug!("observing object predicate `{pred:?}`");
125125

compiler/rustc_hir_analysis/src/outlives/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_hir::def::DefKind;
22
use rustc_hir::def_id::LocalDefId;
33
use rustc_middle::query::Providers;
44
use rustc_middle::ty::GenericArgKind;
5-
use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt};
5+
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt, Upcast};
66
use rustc_span::Span;
77

88
mod explicit;
@@ -75,14 +75,14 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
7575
match kind1.unpack() {
7676
GenericArgKind::Type(ty1) => Some((
7777
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2))
78-
.to_predicate(tcx),
78+
.upcast(tcx),
7979
span,
8080
)),
8181
GenericArgKind::Lifetime(region1) => Some((
8282
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(
8383
region1, *region2,
8484
))
85-
.to_predicate(tcx),
85+
.upcast(tcx),
8686
span,
8787
)),
8888
GenericArgKind::Const(_) => {

compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A utility module to inspect currently ambiguous obligations in the current context.
22
use crate::FnCtxt;
3-
use rustc_infer::traits::solve::Goal;
43
use rustc_infer::traits::{self, ObligationCause};
4+
use rustc_middle::traits::solve::Goal;
55
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
66
use rustc_span::Span;
77
use rustc_trait_selection::solve::inspect::ProofTreeInferCtxtExt;

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use rustc_middle::middle::stability::EvalResult;
2828
use rustc_middle::span_bug;
2929
use rustc_middle::ty::print::with_no_trimmed_paths;
3030
use rustc_middle::ty::{
31-
self, suggest_constraining_type_params, Article, Binder, IsSuggestable, ToPredicate, Ty,
32-
TypeVisitableExt,
31+
self, suggest_constraining_type_params, Article, Binder, IsSuggestable, Ty, TypeVisitableExt,
32+
Upcast,
3333
};
3434
use rustc_session::errors::ExprParenthesesNeeded;
3535
use rustc_span::source_map::Spanned;
@@ -1716,7 +1716,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17161716
}
17171717
}
17181718
}
1719-
self.suggest_derive(diag, &[(trait_ref.to_predicate(self.tcx), None, None)]);
1719+
self.suggest_derive(diag, &[(trait_ref.upcast(self.tcx), None, None)]);
17201720
}
17211721
}
17221722
}

compiler/rustc_hir_typeck/src/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::query::Providers;
2121
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
2222
use rustc_middle::ty::AssocItem;
2323
use rustc_middle::ty::GenericParamDefKind;
24-
use rustc_middle::ty::ToPredicate;
24+
use rustc_middle::ty::Upcast;
2525
use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt};
2626
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
2727
use rustc_middle::{bug, span_bug};
@@ -1496,7 +1496,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14961496
}
14971497
}
14981498

1499-
trait_predicate = Some(ty::Binder::dummy(trait_ref).to_predicate(self.tcx));
1499+
trait_predicate = Some(trait_ref.upcast(self.tcx));
15001500
}
15011501
ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
15021502
let trait_ref = self.instantiate_binder_with_fresh_vars(

0 commit comments

Comments
 (0)