Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 647ae50

Browse files
committed
take predicates by value instead of by reference
1 parent 7f940ef commit 647ae50

File tree

15 files changed

+58
-67
lines changed

15 files changed

+58
-67
lines changed

src/librustc_infer/infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10111011
&self,
10121012
cause: &ObligationCause<'tcx>,
10131013
param_env: ty::ParamEnv<'tcx>,
1014-
predicate: &ty::PolySubtypePredicate<'tcx>,
1014+
predicate: ty::PolySubtypePredicate<'tcx>,
10151015
) -> Option<InferResult<'tcx, ()>> {
10161016
// Subtle: it's ok to skip the binder here and resolve because
10171017
// `shallow_resolve` just ignores anything that is not a type
@@ -1034,7 +1034,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10341034

10351035
Some(self.commit_if_ok(|snapshot| {
10361036
let (ty::SubtypePredicate { a_is_expected, a, b }, placeholder_map) =
1037-
self.replace_bound_vars_with_placeholders(predicate);
1037+
self.replace_bound_vars_with_placeholders(&predicate);
10381038

10391039
let ok = self.at(cause, param_env).sub_exp(a_is_expected, a, b)?;
10401040

@@ -1047,11 +1047,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10471047
pub fn region_outlives_predicate(
10481048
&self,
10491049
cause: &traits::ObligationCause<'tcx>,
1050-
predicate: &ty::PolyRegionOutlivesPredicate<'tcx>,
1050+
predicate: ty::PolyRegionOutlivesPredicate<'tcx>,
10511051
) -> UnitResult<'tcx> {
10521052
self.commit_if_ok(|snapshot| {
10531053
let (ty::OutlivesPredicate(r_a, r_b), placeholder_map) =
1054-
self.replace_bound_vars_with_placeholders(predicate);
1054+
self.replace_bound_vars_with_placeholders(&predicate);
10551055
let origin = SubregionOrigin::from_obligation_cause(cause, || {
10561056
RelateRegionParamBound(cause.span)
10571057
});

src/librustc_infer/infer/outlives/verify.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
223223
// like `T` and `T::Item`. It may not work as well for things
224224
// like `<T as Foo<'a>>::Item`.
225225
let c_b = self.param_env.caller_bounds;
226-
let param_bounds = self.collect_outlives_from_predicate_list(&compare_ty, c_b.into_iter());
226+
let param_bounds =
227+
self.collect_outlives_from_predicate_list(&compare_ty, c_b.into_iter().copied());
227228

228229
// Next, collect regions we scraped from the well-formedness
229230
// constraints in the fn signature. To do that, we walk the list
@@ -334,10 +335,10 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
334335
fn collect_outlives_from_predicate_list(
335336
&self,
336337
compare_ty: impl Fn(Ty<'tcx>) -> bool,
337-
predicates: impl Iterator<Item = impl AsRef<ty::Predicate<'tcx>>>,
338+
predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
338339
) -> impl Iterator<Item = ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> {
339340
predicates
340-
.filter_map(|p| p.as_ref().to_opt_type_outlives())
341+
.filter_map(|p| p.to_opt_type_outlives())
341342
.filter_map(|p| p.no_bound_vars())
342343
.filter(move |p| compare_ty(p.0))
343344
}

src/librustc_infer/traits/util.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::Span;
88

99
pub fn anonymize_predicate<'tcx>(
1010
tcx: TyCtxt<'tcx>,
11-
pred: &ty::Predicate<'tcx>,
11+
pred: ty::Predicate<'tcx>,
1212
) -> ty::Predicate<'tcx> {
1313
match pred.kind() {
1414
&ty::PredicateKind::Trait(ref data, constness) => {
@@ -66,7 +66,7 @@ impl PredicateSet<'tcx> {
6666
Self { tcx, set: Default::default() }
6767
}
6868

69-
fn insert(&mut self, pred: &ty::Predicate<'tcx>) -> bool {
69+
fn insert(&mut self, pred: ty::Predicate<'tcx>) -> bool {
7070
// We have to be careful here because we want
7171
//
7272
// for<'a> Foo<&'a int>
@@ -81,10 +81,10 @@ impl PredicateSet<'tcx> {
8181
}
8282
}
8383

84-
impl<T: AsRef<ty::Predicate<'tcx>>> Extend<T> for PredicateSet<'tcx> {
85-
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
84+
impl Extend<ty::Predicate<'tcx>> for PredicateSet<'tcx> {
85+
fn extend<I: IntoIterator<Item = ty::Predicate<'tcx>>>(&mut self, iter: I) {
8686
for pred in iter {
87-
self.insert(pred.as_ref());
87+
self.insert(pred);
8888
}
8989
}
9090
}
@@ -132,7 +132,7 @@ pub fn elaborate_obligations<'tcx>(
132132
mut obligations: Vec<PredicateObligation<'tcx>>,
133133
) -> Elaborator<'tcx> {
134134
let mut visited = PredicateSet::new(tcx);
135-
obligations.retain(|obligation| visited.insert(&obligation.predicate));
135+
obligations.retain(|obligation| visited.insert(obligation.predicate));
136136
Elaborator { stack: obligations, visited }
137137
}
138138

@@ -172,7 +172,7 @@ impl Elaborator<'tcx> {
172172
// cases. One common case is when people define
173173
// `trait Sized: Sized { }` rather than `trait Sized { }`.
174174
let visited = &mut self.visited;
175-
let obligations = obligations.filter(|o| visited.insert(&o.predicate));
175+
let obligations = obligations.filter(|o| visited.insert(o.predicate));
176176

177177
self.stack.extend(obligations);
178178
}
@@ -260,7 +260,7 @@ impl Elaborator<'tcx> {
260260
}
261261
})
262262
.map(|predicate_kind| predicate_kind.to_predicate(tcx))
263-
.filter(|predicate| visited.insert(predicate))
263+
.filter(|&predicate| visited.insert(predicate))
264264
.map(|predicate| predicate_obligation(predicate, None)),
265265
);
266266
}

src/librustc_middle/ty/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,12 +1094,6 @@ pub struct CratePredicatesMap<'tcx> {
10941094
pub predicates: FxHashMap<DefId, &'tcx [(ty::Predicate<'tcx>, Span)]>,
10951095
}
10961096

1097-
impl<'tcx> AsRef<Predicate<'tcx>> for Predicate<'tcx> {
1098-
fn as_ref(&self) -> &Predicate<'tcx> {
1099-
self
1100-
}
1101-
}
1102-
11031097
impl<'tcx> Predicate<'tcx> {
11041098
/// Performs a substitution suitable for going from a
11051099
/// poly-trait-ref to supertraits that must hold if that
@@ -1214,17 +1208,17 @@ pub struct TraitPredicate<'tcx> {
12141208
pub type PolyTraitPredicate<'tcx> = ty::Binder<TraitPredicate<'tcx>>;
12151209

12161210
impl<'tcx> TraitPredicate<'tcx> {
1217-
pub fn def_id(&self) -> DefId {
1211+
pub fn def_id(self) -> DefId {
12181212
self.trait_ref.def_id
12191213
}
12201214

1221-
pub fn self_ty(&self) -> Ty<'tcx> {
1215+
pub fn self_ty(self) -> Ty<'tcx> {
12221216
self.trait_ref.self_ty()
12231217
}
12241218
}
12251219

12261220
impl<'tcx> PolyTraitPredicate<'tcx> {
1227-
pub fn def_id(&self) -> DefId {
1221+
pub fn def_id(self) -> DefId {
12281222
// Ok to skip binder since trait `DefId` does not care about regions.
12291223
self.skip_binder().def_id()
12301224
}

src/librustc_trait_selection/traits/auto_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,12 +768,12 @@ impl AutoTraitFinder<'tcx> {
768768
}
769769
}
770770
}
771-
ty::PredicateKind::RegionOutlives(ref binder) => {
771+
&ty::PredicateKind::RegionOutlives(binder) => {
772772
if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() {
773773
return false;
774774
}
775775
}
776-
ty::PredicateKind::TypeOutlives(ref binder) => {
776+
&ty::PredicateKind::TypeOutlives(binder) => {
777777
match (
778778
binder.no_bound_vars(),
779779
binder.map_bound_ref(|pred| pred.0).no_bound_vars(),

src/librustc_trait_selection/traits/error_reporting/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
146146
continue;
147147
}
148148

149-
if self.error_implies(&error2.predicate, &error.predicate)
149+
if self.error_implies(error2.predicate, error.predicate)
150150
&& !(error2.index >= error.index
151-
&& self.error_implies(&error.predicate, &error2.predicate))
151+
&& self.error_implies(error.predicate, error2.predicate))
152152
{
153153
info!("skipping {:?} (implied by {:?})", error, error2);
154154
is_suppressed[index] = true;
@@ -500,7 +500,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
500500
ty::PredicateKind::RegionOutlives(ref predicate) => {
501501
let predicate = self.resolve_vars_if_possible(predicate);
502502
let err = self
503-
.region_outlives_predicate(&obligation.cause, &predicate)
503+
.region_outlives_predicate(&obligation.cause, predicate)
504504
.err()
505505
.unwrap();
506506
struct_span_err!(
@@ -955,7 +955,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
955955
trait InferCtxtPrivExt<'tcx> {
956956
// returns if `cond` not occurring implies that `error` does not occur - i.e., that
957957
// `error` occurring implies that `cond` occurs.
958-
fn error_implies(&self, cond: &ty::Predicate<'tcx>, error: &ty::Predicate<'tcx>) -> bool;
958+
fn error_implies(&self, cond: ty::Predicate<'tcx>, error: ty::Predicate<'tcx>) -> bool;
959959

960960
fn report_fulfillment_error(
961961
&self,
@@ -1042,7 +1042,7 @@ trait InferCtxtPrivExt<'tcx> {
10421042
impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
10431043
// returns if `cond` not occurring implies that `error` does not occur - i.e., that
10441044
// `error` occurring implies that `cond` occurs.
1045-
fn error_implies(&self, cond: &ty::Predicate<'tcx>, error: &ty::Predicate<'tcx>) -> bool {
1045+
fn error_implies(&self, cond: ty::Predicate<'tcx>, error: ty::Predicate<'tcx>) -> bool {
10461046
if cond == error {
10471047
return true;
10481048
}
@@ -1055,7 +1055,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
10551055
}
10561056
};
10571057

1058-
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(*cond)) {
1058+
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) {
10591059
if let ty::PredicateKind::Trait(implication, _) = obligation.predicate.kind() {
10601060
let error = error.to_poly_trait_ref();
10611061
let implication = implication.to_poly_trait_ref();

src/librustc_trait_selection/traits/fulfill.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
378378
}
379379
}
380380

381-
ty::PredicateKind::RegionOutlives(ref binder) => {
381+
&ty::PredicateKind::RegionOutlives(binder) => {
382382
match infcx.region_outlives_predicate(&obligation.cause, binder) {
383383
Ok(()) => ProcessResult::Changed(vec![]),
384384
Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
@@ -481,7 +481,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
481481
}
482482
}
483483

484-
ty::PredicateKind::Subtype(subtype) => {
484+
&ty::PredicateKind::Subtype(subtype) => {
485485
match self.selcx.infcx().subtype_predicate(
486486
&obligation.cause,
487487
obligation.param_env,

src/librustc_trait_selection/traits/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,14 +1541,14 @@ fn assoc_ty_def(
15411541
crate trait ProjectionCacheKeyExt<'tcx>: Sized {
15421542
fn from_poly_projection_predicate(
15431543
selcx: &mut SelectionContext<'cx, 'tcx>,
1544-
predicate: &ty::PolyProjectionPredicate<'tcx>,
1544+
predicate: ty::PolyProjectionPredicate<'tcx>,
15451545
) -> Option<Self>;
15461546
}
15471547

15481548
impl<'tcx> ProjectionCacheKeyExt<'tcx> for ProjectionCacheKey<'tcx> {
15491549
fn from_poly_projection_predicate(
15501550
selcx: &mut SelectionContext<'cx, 'tcx>,
1551-
predicate: &ty::PolyProjectionPredicate<'tcx>,
1551+
predicate: ty::PolyProjectionPredicate<'tcx>,
15521552
) -> Option<Self> {
15531553
let infcx = selcx.infcx();
15541554
// We don't do cross-snapshot caching of obligations with escaping regions,

src/librustc_trait_selection/traits/select.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
415415
}
416416

417417
match obligation.predicate.kind() {
418-
ty::PredicateKind::Trait(t, _) => {
418+
&ty::PredicateKind::Trait(t, _) => {
419419
debug_assert!(!t.has_escaping_bound_vars());
420-
let obligation = obligation.with(*t);
420+
let obligation = obligation.with(t);
421421
self.evaluate_trait_predicate_recursively(previous_stack, obligation)
422422
}
423423

424-
ty::PredicateKind::Subtype(p) => {
424+
&ty::PredicateKind::Subtype(p) => {
425425
// Does this code ever run?
426426
match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
427427
Some(Ok(InferOk { mut obligations, .. })) => {
@@ -463,8 +463,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
463463
}
464464
}
465465

466-
ty::PredicateKind::Projection(data) => {
467-
let project_obligation = obligation.with(*data);
466+
&ty::PredicateKind::Projection(data) => {
467+
let project_obligation = obligation.with(data);
468468
match project::poly_project_and_unify_type(self, &project_obligation) {
469469
Ok(Some(mut subobligations)) => {
470470
self.add_depth(subobligations.iter_mut(), obligation.recursion_depth);
@@ -962,7 +962,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
962962
debug_assert!(!stack.obligation.predicate.has_escaping_bound_vars());
963963

964964
if let Some(c) =
965-
self.check_candidate_cache(stack.obligation.param_env, &cache_fresh_trait_pred)
965+
self.check_candidate_cache(stack.obligation.param_env, cache_fresh_trait_pred)
966966
{
967967
debug!("CACHE HIT: SELECT({:?})={:?}", cache_fresh_trait_pred, c);
968968
return c;
@@ -1247,7 +1247,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12471247
fn check_candidate_cache(
12481248
&mut self,
12491249
param_env: ty::ParamEnv<'tcx>,
1250-
cache_fresh_trait_pred: &ty::PolyTraitPredicate<'tcx>,
1250+
cache_fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
12511251
) -> Option<SelectionResult<'tcx, SelectionCandidate<'tcx>>> {
12521252
let tcx = self.tcx();
12531253
let trait_ref = &cache_fresh_trait_pred.skip_binder().trait_ref;

src/librustc_trait_selection/traits/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ impl<'tcx> TraitAliasExpander<'tcx> {
108108
}
109109

110110
// Don't recurse if this trait alias is already on the stack for the DFS search.
111-
let anon_pred = anonymize_predicate(tcx, &pred);
111+
let anon_pred = anonymize_predicate(tcx, pred);
112112
if item.path.iter().rev().skip(1).any(|(tr, _)| {
113-
anonymize_predicate(tcx, &tr.without_const().to_predicate(tcx)) == anon_pred
113+
anonymize_predicate(tcx, tr.without_const().to_predicate(tcx)) == anon_pred
114114
}) {
115115
return false;
116116
}

0 commit comments

Comments
 (0)