Skip to content

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
}

src/librustc_trait_selection/traits/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn predicate_obligations<'a, 'tcx>(
6666
infcx: &InferCtxt<'a, 'tcx>,
6767
param_env: ty::ParamEnv<'tcx>,
6868
body_id: hir::HirId,
69-
predicate: &ty::Predicate<'tcx>,
69+
predicate: ty::Predicate<'tcx>,
7070
span: Span,
7171
) -> Vec<traits::PredicateObligation<'tcx>> {
7272
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };

src/librustc_typeck/check/closure.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
179179
ty::Dynamic(ref object_type, ..) => {
180180
let sig = object_type.projection_bounds().find_map(|pb| {
181181
let pb = pb.with_self_ty(self.tcx, self.tcx.types.trait_object_dummy_self);
182-
self.deduce_sig_from_projection(None, &pb)
182+
self.deduce_sig_from_projection(None, pb)
183183
});
184184
let kind = object_type
185185
.principal_def_id()
@@ -206,8 +206,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
206206
obligation.predicate
207207
);
208208

209-
if let ty::PredicateKind::Projection(ref proj_predicate) =
210-
obligation.predicate.kind()
209+
if let &ty::PredicateKind::Projection(proj_predicate) = obligation.predicate.kind()
211210
{
212211
// Given a Projection predicate, we can potentially infer
213212
// the complete signature.
@@ -238,7 +237,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
238237
fn deduce_sig_from_projection(
239238
&self,
240239
cause_span: Option<Span>,
241-
projection: &ty::PolyProjectionPredicate<'tcx>,
240+
projection: ty::PolyProjectionPredicate<'tcx>,
242241
) -> Option<ExpectedSig<'tcx>> {
243242
let tcx = self.tcx;
244243

@@ -644,7 +643,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
644643
// where R is the return type we are expecting. This type `T`
645644
// will be our output.
646645
let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| {
647-
if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate.kind() {
646+
if let &ty::PredicateKind::Projection(proj_predicate) = obligation.predicate.kind() {
648647
self.deduce_future_output_from_projection(obligation.cause.span, proj_predicate)
649648
} else {
650649
None
@@ -665,7 +664,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
665664
fn deduce_future_output_from_projection(
666665
&self,
667666
cause_span: Span,
668-
predicate: &ty::PolyProjectionPredicate<'tcx>,
667+
predicate: ty::PolyProjectionPredicate<'tcx>,
669668
) -> Option<Ty<'tcx>> {
670669
debug!("deduce_future_output_from_projection(predicate={:?})", predicate);
671670

src/librustc_typeck/check/dropck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
205205
// just to look for all the predicates directly.
206206

207207
assert_eq!(dtor_predicates.parent, None);
208-
for (predicate, predicate_sp) in dtor_predicates.predicates {
208+
for &(predicate, predicate_sp) in dtor_predicates.predicates {
209209
// (We do not need to worry about deep analysis of type
210210
// expressions etc because the Drop impls are already forced
211211
// to take on a structure that is roughly an alpha-renaming of
@@ -228,7 +228,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
228228
// This implementation solves (Issue #59497) and (Issue #58311).
229229
// It is unclear to me at the moment whether the approach based on `relate`
230230
// could be extended easily also to the other `Predicate`.
231-
let predicate_matches_closure = |p: &'_ Predicate<'tcx>| {
231+
let predicate_matches_closure = |p: Predicate<'tcx>| {
232232
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
233233
match (predicate.kind(), p.kind()) {
234234
(ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => {
@@ -241,12 +241,12 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
241241
}
242242
};
243243

244-
if !assumptions_in_impl_context.iter().any(predicate_matches_closure) {
244+
if !assumptions_in_impl_context.iter().copied().any(predicate_matches_closure) {
245245
let item_span = tcx.hir().span(self_type_hir_id);
246246
let self_descr = tcx.def_kind(self_type_did).descr(self_type_did.to_def_id());
247247
struct_span_err!(
248248
tcx.sess,
249-
*predicate_sp,
249+
predicate_sp,
250250
E0367,
251251
"`Drop` impl requires `{}` but the {} it is implemented for does not",
252252
predicate,

0 commit comments

Comments
 (0)