Skip to content

Commit 3912168

Browse files
committed
Swap Vec<PredicateObligation> to type alias
1 parent a49aefc commit 3912168

File tree

27 files changed

+175
-157
lines changed

27 files changed

+175
-157
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_infer::infer::region_constraints::RegionConstraintData;
1818
use rustc_infer::infer::{
1919
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
2020
};
21+
use rustc_infer::traits::PredicateObligations;
2122
use rustc_middle::mir::tcx::PlaceTy;
2223
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
2324
use rustc_middle::mir::*;
@@ -40,7 +41,6 @@ use rustc_span::source_map::Spanned;
4041
use rustc_span::symbol::sym;
4142
use rustc_span::{DUMMY_SP, Span};
4243
use rustc_target::abi::{FIRST_VARIANT, FieldIdx};
43-
use rustc_trait_selection::traits::PredicateObligation;
4444
use rustc_trait_selection::traits::query::type_op::custom::{
4545
CustomTypeOp, scrape_region_constraints,
4646
};
@@ -2940,7 +2940,7 @@ impl NormalizeLocation for Location {
29402940
pub(super) struct InstantiateOpaqueType<'tcx> {
29412941
pub base_universe: Option<ty::UniverseIndex>,
29422942
pub region_constraints: Option<RegionConstraintData<'tcx>>,
2943-
pub obligations: Vec<PredicateObligation<'tcx>>,
2943+
pub obligations: PredicateObligations<'tcx>,
29442944
}
29452945

29462946
impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_infer::infer::InferCtxt;
2+
use rustc_infer::traits::PredicateObligations;
23
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
34
use rustc_session::Limit;
45
use rustc_span::Span;
@@ -23,7 +24,7 @@ struct AutoderefSnapshot<'tcx> {
2324
reached_recursion_limit: bool,
2425
steps: Vec<(Ty<'tcx>, AutoderefKind)>,
2526
cur_ty: Ty<'tcx>,
26-
obligations: Vec<traits::PredicateObligation<'tcx>>,
27+
obligations: PredicateObligations<'tcx>,
2728
}
2829

2930
pub struct Autoderef<'a, 'tcx> {
@@ -165,7 +166,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
165166
pub fn structurally_normalize(
166167
&self,
167168
ty: Ty<'tcx>,
168-
) -> Option<(Ty<'tcx>, Vec<traits::PredicateObligation<'tcx>>)> {
169+
) -> Option<(Ty<'tcx>, PredicateObligations<'tcx>)> {
169170
let ocx = ObligationCtxt::new(self.infcx);
170171
let Ok(normalized_ty) = ocx.structurally_normalize(
171172
&traits::ObligationCause::misc(self.span, self.body_id),
@@ -204,11 +205,11 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
204205
self.state.steps.len()
205206
}
206207

207-
pub fn into_obligations(self) -> Vec<traits::PredicateObligation<'tcx>> {
208+
pub fn into_obligations(self) -> PredicateObligations<'tcx> {
208209
self.state.obligations
209210
}
210211

211-
pub fn current_obligations(&self) -> Vec<traits::PredicateObligation<'tcx>> {
212+
pub fn current_obligations(&self) -> PredicateObligations<'tcx> {
212213
self.state.obligations.clone()
213214
}
214215

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use rustc_infer::infer::relate::RelateResult;
4646
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
4747
use rustc_infer::traits::{
4848
IfExpressionCause, MatchExpressionArmCause, Obligation, PredicateObligation,
49+
PredicateObligations,
4950
};
5051
use rustc_middle::lint::in_external_macro;
5152
use rustc_middle::span_bug;
@@ -120,7 +121,7 @@ fn simple<'tcx>(kind: Adjust<'tcx>) -> impl FnOnce(Ty<'tcx>) -> Vec<Adjustment<'
120121
fn success<'tcx>(
121122
adj: Vec<Adjustment<'tcx>>,
122123
target: Ty<'tcx>,
123-
obligations: Vec<traits::PredicateObligation<'tcx>>,
124+
obligations: PredicateObligations<'tcx>,
124125
) -> CoerceResult<'tcx> {
125126
Ok(InferOk { value: (adj, target), obligations })
126127
}

compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A utility module to inspect currently ambiguous obligations in the current context.
22
3-
use rustc_infer::traits::{self, ObligationCause};
3+
use rustc_infer::traits::{self, ObligationCause, PredicateObligations};
44
use rustc_middle::traits::solve::Goal;
55
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
66
use rustc_span::Span;
@@ -15,10 +15,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1515
/// Returns a list of all obligations whose self type has been unified
1616
/// with the unconstrained type `self_ty`.
1717
#[instrument(skip(self), level = "debug")]
18-
pub(crate) fn obligations_for_self_ty(
19-
&self,
20-
self_ty: ty::TyVid,
21-
) -> Vec<traits::PredicateObligation<'tcx>> {
18+
pub(crate) fn obligations_for_self_ty(&self, self_ty: ty::TyVid) -> PredicateObligations<'tcx> {
2219
if self.next_trait_solver() {
2320
self.obligations_for_self_ty_next(self_ty)
2421
} else {
@@ -75,7 +72,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7572
pub(crate) fn obligations_for_self_ty_next(
7673
&self,
7774
self_ty: ty::TyVid,
78-
) -> Vec<traits::PredicateObligation<'tcx>> {
75+
) -> PredicateObligations<'tcx> {
7976
let obligations = self.fulfillment_cx.borrow().pending_obligations();
8077
debug!(?obligations);
8178
let mut obligations_for_self_ty = vec![];
@@ -103,7 +100,7 @@ struct NestedObligationsForSelfTy<'a, 'tcx> {
103100
fcx: &'a FnCtxt<'a, 'tcx>,
104101
self_ty: ty::TyVid,
105102
root_cause: &'a ObligationCause<'tcx>,
106-
obligations_for_self_ty: &'a mut Vec<traits::PredicateObligation<'tcx>>,
103+
obligations_for_self_ty: &'a mut PredicateObligations<'tcx>,
107104
}
108105

109106
impl<'a, 'tcx> ProofTreeVisitor<'tcx> for NestedObligationsForSelfTy<'a, 'tcx> {

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use crate::infer::region_constraints::{Constraint, RegionConstraintData};
2828
use crate::infer::{DefineOpaqueTypes, InferCtxt, InferOk, InferResult};
2929
use crate::traits::query::NoSolution;
3030
use crate::traits::{
31-
Obligation, ObligationCause, PredicateObligation, ScrubbedTraitError, TraitEngine,
31+
Obligation, ObligationCause, PredicateObligation, PredicateObligations, ScrubbedTraitError,
32+
TraitEngine,
3233
};
3334

3435
impl<'tcx> InferCtxt<'tcx> {
@@ -493,7 +494,7 @@ impl<'tcx> InferCtxt<'tcx> {
493494
),
494495
};
495496

496-
let mut obligations = vec![];
497+
let mut obligations = PredicateObligations::new();
497498

498499
// Carry all newly resolved opaque types to the caller's scope
499500
for &(a, b) in &query_response.value.opaque_types {
@@ -598,7 +599,7 @@ impl<'tcx> InferCtxt<'tcx> {
598599
variables1: &OriginalQueryValues<'tcx>,
599600
variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,
600601
) -> InferResult<'tcx, ()> {
601-
let mut obligations = vec![];
602+
let mut obligations = PredicateObligations::new();
602603
for (index, value1) in variables1.var_values.iter().enumerate() {
603604
let value2 = variables2(BoundVar::new(index));
604605

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ use tracing::{debug, instrument};
5151
use type_variable::TypeVariableOrigin;
5252

5353
use crate::infer::region_constraints::UndoLog;
54-
use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligation, TraitEngine};
54+
use crate::traits::{
55+
self, ObligationCause, ObligationInspector, PredicateObligations, TraitEngine,
56+
};
5557

5658
pub mod at;
5759
pub mod canonical;
@@ -69,7 +71,7 @@ pub(crate) mod snapshot;
6971
mod type_variable;
7072

7173
/// `InferOk<'tcx, ()>` is used a lot. It may seem like a useless wrapper
72-
/// around `Vec<PredicateObligation<'tcx>>`, but it has one important property:
74+
/// around `PredicateObligations<'tcx>`, but it has one important property:
7375
/// because `InferOk` is marked with `#[must_use]`, if you have a method
7476
/// `InferCtxt::f` that returns `InferResult<'tcx, ()>` and you call it with
7577
/// `infcx.f()?;` you'll get a warning about the obligations being discarded
@@ -79,7 +81,7 @@ mod type_variable;
7981
#[derive(Debug)]
8082
pub struct InferOk<'tcx, T> {
8183
pub value: T,
82-
pub obligations: Vec<PredicateObligation<'tcx>>,
84+
pub obligations: PredicateObligations<'tcx>,
8385
}
8486
pub type InferResult<'tcx, T> = Result<InferOk<'tcx, T>, TypeError<'tcx>>;
8587

@@ -660,7 +662,7 @@ impl<'tcx, T> InferOk<'tcx, T> {
660662
}
661663

662664
impl<'tcx> InferOk<'tcx, ()> {
663-
pub fn into_obligations(self) -> Vec<PredicateObligation<'tcx>> {
665+
pub fn into_obligations(self) -> PredicateObligations<'tcx> {
664666
self.obligations
665667
}
666668
}

compiler/rustc_infer/src/infer/opaque_types/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tracing::{debug, instrument};
1616
use super::DefineOpaqueTypes;
1717
use crate::errors::OpaqueHiddenTypeDiag;
1818
use crate::infer::{InferCtxt, InferOk};
19-
use crate::traits::{self, Obligation};
19+
use crate::traits::{self, Obligation, PredicateObligations};
2020

2121
mod table;
2222

@@ -46,14 +46,14 @@ impl<'tcx> InferCtxt<'tcx> {
4646
) -> InferOk<'tcx, T> {
4747
// We handle opaque types differently in the new solver.
4848
if self.next_trait_solver() {
49-
return InferOk { value, obligations: vec![] };
49+
return InferOk { value, obligations: PredicateObligations::new() };
5050
}
5151

5252
if !value.has_opaque_types() {
53-
return InferOk { value, obligations: vec![] };
53+
return InferOk { value, obligations: PredicateObligations::new() };
5454
}
5555

56-
let mut obligations = vec![];
56+
let mut obligations = PredicateObligations::new();
5757
let value = value.fold_with(&mut BottomUpFolder {
5858
tcx: self.tcx,
5959
lt_op: |lt| lt,

compiler/rustc_infer/src/infer/projection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_middle::traits::ObligationCause;
22
use rustc_middle::ty::{self, Ty};
33

44
use super::InferCtxt;
5-
use crate::traits::{Obligation, PredicateObligation};
5+
use crate::traits::{Obligation, PredicateObligations};
66

77
impl<'tcx> InferCtxt<'tcx> {
88
/// Instead of normalizing an associated type projection,
@@ -17,7 +17,7 @@ impl<'tcx> InferCtxt<'tcx> {
1717
projection_ty: ty::AliasTy<'tcx>,
1818
cause: ObligationCause<'tcx>,
1919
recursion_depth: usize,
20-
obligations: &mut Vec<PredicateObligation<'tcx>>,
20+
obligations: &mut PredicateObligations<'tcx>,
2121
) -> Ty<'tcx> {
2222
debug_assert!(!self.next_trait_solver());
2323
let ty_var = self.next_ty_var(self.tcx.def_span(projection_ty.def_id));

compiler/rustc_infer/src/infer/relate/lattice.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use tracing::{debug, instrument};
2626
use super::StructurallyRelateAliases;
2727
use super::combine::PredicateEmittingRelation;
2828
use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin, TypeTrace};
29-
use crate::traits::{Obligation, PredicateObligation};
29+
use crate::traits::{Obligation, PredicateObligations};
3030

3131
#[derive(Clone, Copy)]
3232
pub(crate) enum LatticeOpKind {
@@ -51,7 +51,7 @@ pub(crate) struct LatticeOp<'infcx, 'tcx> {
5151
param_env: ty::ParamEnv<'tcx>,
5252
// Mutable fields
5353
kind: LatticeOpKind,
54-
obligations: Vec<PredicateObligation<'tcx>>,
54+
obligations: PredicateObligations<'tcx>,
5555
}
5656

5757
impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
@@ -61,10 +61,10 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
6161
param_env: ty::ParamEnv<'tcx>,
6262
kind: LatticeOpKind,
6363
) -> LatticeOp<'infcx, 'tcx> {
64-
LatticeOp { infcx, trace, param_env, kind, obligations: vec![] }
64+
LatticeOp { infcx, trace, param_env, kind, obligations: PredicateObligations::new() }
6565
}
6666

67-
pub(crate) fn into_obligations(self) -> Vec<PredicateObligation<'tcx>> {
67+
pub(crate) fn into_obligations(self) -> PredicateObligations<'tcx> {
6868
self.obligations
6969
}
7070
}

compiler/rustc_infer/src/infer/relate/type_relating.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tracing::{debug, instrument};
1010
use crate::infer::BoundRegionConversionTime::HigherRankedType;
1111
use crate::infer::relate::{PredicateEmittingRelation, StructurallyRelateAliases};
1212
use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin, TypeTrace};
13-
use crate::traits::{Obligation, PredicateObligation};
13+
use crate::traits::{Obligation, PredicateObligations};
1414

1515
/// Enforce that `a` is equal to or a subtype of `b`.
1616
pub(crate) struct TypeRelating<'infcx, 'tcx> {
@@ -24,7 +24,7 @@ pub(crate) struct TypeRelating<'infcx, 'tcx> {
2424

2525
// Mutable fields.
2626
ambient_variance: ty::Variance,
27-
obligations: Vec<PredicateObligation<'tcx>>,
27+
obligations: PredicateObligations<'tcx>,
2828
/// The cache only tracks the `ambient_variance` as it's the
2929
/// only field which is mutable and which meaningfully changes
3030
/// the result when relating types.
@@ -66,12 +66,12 @@ impl<'infcx, 'tcx> TypeRelating<'infcx, 'tcx> {
6666
define_opaque_types,
6767
structurally_relate_aliases,
6868
ambient_variance,
69-
obligations: vec![],
69+
obligations: PredicateObligations::new(),
7070
cache: Default::default(),
7171
}
7272
}
7373

74-
pub(crate) fn into_obligations(self) -> Vec<PredicateObligation<'tcx>> {
74+
pub(crate) fn into_obligations(self) -> PredicateObligations<'tcx> {
7575
self.obligations
7676
}
7777
}

compiler/rustc_infer/src/traits/engine.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::Debug;
33
use rustc_hir::def_id::DefId;
44
use rustc_middle::ty::{self, Ty, Upcast};
55

6-
use super::{ObligationCause, PredicateObligation};
6+
use super::{ObligationCause, PredicateObligation, PredicateObligations};
77
use crate::infer::InferCtxt;
88
use crate::traits::Obligation;
99

@@ -20,7 +20,7 @@ pub enum ScrubbedTraitError<'tcx> {
2020
/// An ambiguity. This goal may hold if further inference is done.
2121
Ambiguity,
2222
/// An old-solver-style cycle error, which will fatal.
23-
Cycle(Vec<PredicateObligation<'tcx>>),
23+
Cycle(PredicateObligations<'tcx>),
2424
}
2525

2626
impl<'tcx> ScrubbedTraitError<'tcx> {
@@ -62,7 +62,7 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx {
6262
fn register_predicate_obligations(
6363
&mut self,
6464
infcx: &InferCtxt<'tcx>,
65-
obligations: Vec<PredicateObligation<'tcx>>,
65+
obligations: PredicateObligations<'tcx>,
6666
) {
6767
for obligation in obligations {
6868
self.register_predicate_obligation(infcx, obligation);
@@ -84,15 +84,15 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx {
8484
self.collect_remaining_errors(infcx)
8585
}
8686

87-
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
87+
fn pending_obligations(&self) -> PredicateObligations<'tcx>;
8888

8989
/// Among all pending obligations, collect those are stalled on a inference variable which has
9090
/// changed since the last call to `select_where_possible`. Those obligations are marked as
9191
/// successful and returned.
9292
fn drain_unstalled_obligations(
9393
&mut self,
9494
infcx: &InferCtxt<'tcx>,
95-
) -> Vec<PredicateObligation<'tcx>>;
95+
) -> PredicateObligations<'tcx>;
9696
}
9797

9898
pub trait FromSolverError<'tcx, E>: Debug + 'tcx {

compiler/rustc_infer/src/traits/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
8484
pub type TraitObligation<'tcx> = Obligation<'tcx, ty::TraitPredicate<'tcx>>;
8585
pub type PolyTraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
8686

87+
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;
88+
8789
impl<'tcx> PredicateObligation<'tcx> {
8890
/// Flips the polarity of the inner predicate.
8991
///

compiler/rustc_infer/src/traits/project.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::traits::EvaluationResult;
66
use rustc_middle::ty;
77
use tracing::{debug, info};
88

9-
use super::PredicateObligation;
9+
use super::PredicateObligations;
1010
use crate::infer::snapshot::undo_log::InferCtxtUndoLogs;
1111

1212
pub(crate) type UndoLog<'tcx> =
@@ -20,7 +20,7 @@ pub struct MismatchedProjectionTypes<'tcx> {
2020
#[derive(Clone)]
2121
pub struct Normalized<'tcx, T> {
2222
pub value: T,
23-
pub obligations: Vec<PredicateObligation<'tcx>>,
23+
pub obligations: PredicateObligations<'tcx>,
2424
}
2525

2626
pub type NormalizedTerm<'tcx> = Normalized<'tcx, ty::Term<'tcx>>;
@@ -191,7 +191,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
191191
info!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty);
192192
let mut ty = ty.clone();
193193
if result.must_apply_considering_regions() {
194-
ty.obligations = vec![];
194+
ty.obligations = PredicateObligations::new();
195195
}
196196
map.insert(key, ProjectionCacheEntry::NormalizedTerm {
197197
ty,

0 commit comments

Comments
 (0)