Skip to content

Commit 2c0348a

Browse files
Stop passing traitref/traitpredicate by ref
1 parent f8d12d9 commit 2c0348a

File tree

11 files changed

+33
-38
lines changed

11 files changed

+33
-38
lines changed

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<T> Trait<T> for X {
546546
for pred in hir_generics.bounds_for_param(def_id) {
547547
if self.constrain_generic_bound_associated_type_structured_suggestion(
548548
diag,
549-
&trait_ref,
549+
trait_ref,
550550
pred.bounds,
551551
assoc,
552552
assoc_args,
@@ -715,7 +715,7 @@ fn foo(&self) -> Self::T { String::new() }
715715

716716
self.constrain_generic_bound_associated_type_structured_suggestion(
717717
diag,
718-
&trait_ref,
718+
trait_ref,
719719
opaque_hir_ty.bounds,
720720
assoc,
721721
assoc_args,
@@ -869,7 +869,7 @@ fn foo(&self) -> Self::T { String::new() }
869869
fn constrain_generic_bound_associated_type_structured_suggestion(
870870
&self,
871871
diag: &mut Diag<'_>,
872-
trait_ref: &ty::TraitRef<'tcx>,
872+
trait_ref: ty::TraitRef<'tcx>,
873873
bounds: hir::GenericBounds<'_>,
874874
assoc: ty::AssocItem,
875875
assoc_args: &[ty::GenericArg<'tcx>],

compiler/rustc_infer/src/traits/util.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
285285
let obligations =
286286
predicates.predicates.iter().enumerate().map(|(index, &(clause, span))| {
287287
elaboratable.child_with_derived_cause(
288-
clause
289-
.instantiate_supertrait(tcx, &bound_clause.rebind(data.trait_ref)),
288+
clause.instantiate_supertrait(tcx, bound_clause.rebind(data.trait_ref)),
290289
span,
291290
bound_clause.rebind(data),
292291
index,

compiler/rustc_middle/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'tcx> Elaborator<'tcx> {
3737
let super_predicates =
3838
self.tcx.super_predicates_of(trait_ref.def_id()).predicates.iter().filter_map(
3939
|&(pred, _)| {
40-
let clause = pred.instantiate_supertrait(self.tcx, &trait_ref);
40+
let clause = pred.instantiate_supertrait(self.tcx, trait_ref);
4141
self.visited.insert(clause).then_some(clause)
4242
},
4343
);

compiler/rustc_middle/src/ty/predicate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'tcx> Clause<'tcx> {
313313
pub fn instantiate_supertrait(
314314
self,
315315
tcx: TyCtxt<'tcx>,
316-
trait_ref: &ty::PolyTraitRef<'tcx>,
316+
trait_ref: ty::PolyTraitRef<'tcx>,
317317
) -> Clause<'tcx> {
318318
// The interaction between HRTB and supertraits is not entirely
319319
// obvious. Let me walk you (and myself) through an example.

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3597,7 +3597,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
35973597
&self,
35983598
obligation: &PredicateObligation<'tcx>,
35993599
err: &mut Diag<'_>,
3600-
trait_ref: &ty::PolyTraitRef<'tcx>,
3600+
trait_ref: ty::PolyTraitRef<'tcx>,
36013601
) {
36023602
let rhs_span = match obligation.cause.code() {
36033603
ObligationCauseCode::BinOp { rhs_span: Some(span), rhs_is_lit, .. } if *rhs_is_lit => {
@@ -4863,7 +4863,7 @@ impl<'a, 'hir> hir::intravisit::Visitor<'hir> for ReplaceImplTraitVisitor<'a> {
48634863
pub(super) fn get_explanation_based_on_obligation<'tcx>(
48644864
tcx: TyCtxt<'tcx>,
48654865
obligation: &PredicateObligation<'tcx>,
4866-
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
4866+
trait_predicate: ty::PolyTraitPredicate<'tcx>,
48674867
pre_message: String,
48684868
) -> String {
48694869
if let ObligationCauseCode::MainFunctionType = obligation.cause.code() {

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
532532
};
533533

534534
let err_msg = self.get_standard_error_message(
535-
&main_trait_predicate,
535+
main_trait_predicate,
536536
message,
537537
predicate_is_const,
538538
append_const_msg,
@@ -603,7 +603,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
603603
let explanation = get_explanation_based_on_obligation(
604604
self.tcx,
605605
&obligation,
606-
&leaf_trait_predicate,
606+
leaf_trait_predicate,
607607
pre_message,
608608
);
609609

@@ -658,7 +658,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
658658

659659
let UnsatisfiedConst(unsatisfied_const) = self
660660
.maybe_add_note_for_unsatisfied_const(
661-
&leaf_trait_predicate,
661+
leaf_trait_predicate,
662662
&mut err,
663663
span,
664664
);
@@ -675,7 +675,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
675675
err.span_label(tcx.def_span(body), s);
676676
}
677677

678-
self.suggest_floating_point_literal(&obligation, &mut err, &leaf_trait_ref);
678+
self.suggest_floating_point_literal(&obligation, &mut err, leaf_trait_ref);
679679
self.suggest_dereferencing_index(&obligation, &mut err, leaf_trait_predicate);
680680
suggested |= self.suggest_dereferences(&obligation, &mut err, leaf_trait_predicate);
681681
suggested |= self.suggest_fn_call(&obligation, &mut err, leaf_trait_predicate);
@@ -710,7 +710,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
710710
span,
711711
leaf_trait_predicate,
712712
);
713-
self.note_version_mismatch(&mut err, &leaf_trait_ref);
713+
self.note_version_mismatch(&mut err, leaf_trait_ref);
714714
self.suggest_remove_await(&obligation, &mut err);
715715
self.suggest_derive(&obligation, &mut err, leaf_trait_predicate);
716716

@@ -758,7 +758,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
758758

759759
self.try_to_add_help_message(
760760
&obligation,
761-
&leaf_trait_predicate,
761+
leaf_trait_predicate,
762762
&mut err,
763763
span,
764764
is_fn_trait,
@@ -2234,11 +2234,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22342234
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
22352235
/// with the same path as `trait_ref`, a help message about
22362236
/// a probable version mismatch is added to `err`
2237-
fn note_version_mismatch(
2238-
&self,
2239-
err: &mut Diag<'_>,
2240-
trait_ref: &ty::PolyTraitRef<'tcx>,
2241-
) -> bool {
2237+
fn note_version_mismatch(&self, err: &mut Diag<'_>, trait_ref: ty::PolyTraitRef<'tcx>) -> bool {
22422238
let get_trait_impls = |trait_def_id| {
22432239
let mut trait_impls = vec![];
22442240
self.tcx.for_each_relevant_impl(
@@ -3042,7 +3038,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
30423038

30433039
fn get_standard_error_message(
30443040
&self,
3045-
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
3041+
trait_predicate: ty::PolyTraitPredicate<'tcx>,
30463042
message: Option<String>,
30473043
predicate_is_const: bool,
30483044
append_const_msg: Option<AppendConstMessage>,
@@ -3213,7 +3209,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32133209
fn try_to_add_help_message(
32143210
&self,
32153211
obligation: &PredicateObligation<'tcx>,
3216-
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
3212+
trait_predicate: ty::PolyTraitPredicate<'tcx>,
32173213
err: &mut Diag<'_>,
32183214
span: Span,
32193215
is_fn_trait: bool,
@@ -3245,7 +3241,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32453241
params,
32463242
);
32473243
} else if !trait_predicate.has_non_region_infer()
3248-
&& self.predicate_can_apply(obligation.param_env, *trait_predicate)
3244+
&& self.predicate_can_apply(obligation.param_env, trait_predicate)
32493245
{
32503246
// If a where-clause may be useful, remind the
32513247
// user that they can add it.
@@ -3256,7 +3252,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32563252
// which is somewhat confusing.
32573253
self.suggest_restricting_param_bound(
32583254
err,
3259-
*trait_predicate,
3255+
trait_predicate,
32603256
None,
32613257
obligation.cause.body_id,
32623258
);
@@ -3271,7 +3267,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32713267
);
32723268
} else if !suggested && !unsatisfied_const {
32733269
// Can't show anything else useful, try to find similar impls.
3274-
let impl_candidates = self.find_similar_impl_candidates(*trait_predicate);
3270+
let impl_candidates = self.find_similar_impl_candidates(trait_predicate);
32753271
if !self.report_similar_impl_candidates(
32763272
&impl_candidates,
32773273
trait_predicate.to_poly_trait_ref(),
@@ -3282,7 +3278,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32823278
) {
32833279
self.report_similar_impl_candidates_for_root_obligation(
32843280
obligation,
3285-
*trait_predicate,
3281+
trait_predicate,
32863282
body_def_id,
32873283
err,
32883284
);
@@ -3356,7 +3352,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
33563352

33573353
fn maybe_add_note_for_unsatisfied_const(
33583354
&self,
3359-
_trait_predicate: &ty::PolyTraitPredicate<'tcx>,
3355+
_trait_predicate: ty::PolyTraitPredicate<'tcx>,
33603356
_err: &mut Diag<'_>,
33613357
_span: Span,
33623358
) -> UnsatisfiedConst {

compiler/rustc_trait_selection/src/traits/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn predicates_reference_self(
194194
predicates
195195
.predicates
196196
.iter()
197-
.map(|&(predicate, sp)| (predicate.instantiate_supertrait(tcx, &trait_ref), sp))
197+
.map(|&(predicate, sp)| (predicate.instantiate_supertrait(tcx, trait_ref), sp))
198198
.filter_map(|predicate| predicate_references_self(tcx, predicate))
199199
.collect()
200200
}

compiler/rustc_trait_selection/src/traits/select/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
18661866
// the param_env so that it can be given the lowest priority. See
18671867
// #50825 for the motivation for this.
18681868
let is_global =
1869-
|cand: &ty::PolyTraitPredicate<'tcx>| cand.is_global() && !cand.has_bound_vars();
1869+
|cand: ty::PolyTraitPredicate<'tcx>| cand.is_global() && !cand.has_bound_vars();
18701870

18711871
// (*) Prefer `BuiltinCandidate { has_nested: false }`, `PointeeCandidate`,
18721872
// `DiscriminantKindCandidate`, `ConstDestructCandidate`
@@ -1909,7 +1909,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
19091909
}
19101910

19111911
(
1912-
ParamCandidate(ref other_cand),
1912+
ParamCandidate(other_cand),
19131913
ImplCandidate(..)
19141914
| AutoImplCandidate
19151915
| ClosureCandidate { .. }
@@ -1934,12 +1934,12 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
19341934
//
19351935
// Global bounds from the where clause should be ignored
19361936
// here (see issue #50825).
1937-
DropVictim::drop_if(!is_global(other_cand))
1937+
DropVictim::drop_if(!is_global(*other_cand))
19381938
}
1939-
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(ref victim_cand)) => {
1939+
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(victim_cand)) => {
19401940
// Prefer these to a global where-clause bound
19411941
// (see issue #50825).
1942-
if is_global(victim_cand) { DropVictim::Yes } else { DropVictim::No }
1942+
if is_global(*victim_cand) { DropVictim::Yes } else { DropVictim::No }
19431943
}
19441944
(
19451945
ImplCandidate(_)
@@ -1957,12 +1957,12 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
19571957
| TraitUpcastingUnsizeCandidate(_)
19581958
| BuiltinCandidate { has_nested: true }
19591959
| TraitAliasCandidate,
1960-
ParamCandidate(ref victim_cand),
1960+
ParamCandidate(victim_cand),
19611961
) => {
19621962
// Prefer these to a global where-clause bound
19631963
// (see issue #50825).
19641964
DropVictim::drop_if(
1965-
is_global(victim_cand) && other.evaluation.must_apply_modulo_regions(),
1965+
is_global(*victim_cand) && other.evaluation.must_apply_modulo_regions(),
19661966
)
19671967
}
19681968

compiler/rustc_trait_selection/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'tcx> TraitAliasExpander<'tcx> {
132132
debug!(?predicates);
133133

134134
let items = predicates.predicates.iter().rev().filter_map(|(pred, span)| {
135-
pred.instantiate_supertrait(tcx, &trait_ref)
135+
pred.instantiate_supertrait(tcx, trait_ref)
136136
.as_trait_clause()
137137
.map(|trait_ref| item.clone_and_push(trait_ref.map_bound(|t| t.trait_ref), *span))
138138
});

compiler/rustc_trait_selection/src/traits/vtable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn prepare_vtable_segments_inner<'tcx, T>(
125125
.predicates
126126
.into_iter()
127127
.filter_map(move |(pred, _)| {
128-
pred.instantiate_supertrait(tcx, &inner_most_trait_ref).as_trait_clause()
128+
pred.instantiate_supertrait(tcx, inner_most_trait_ref).as_trait_clause()
129129
});
130130

131131
// Find an unvisited supertrait

tests/ui/typeck/suggest-similar-impls-for-root-obligation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ impl<'s, T: Foo<'s>> From<T> for Bar {
1313
fn main() {
1414
let _: Bar = ((),).into();
1515
//~^ ERROR he trait bound `((),): Into<Bar>` is not satisfied
16-
}
16+
}

0 commit comments

Comments
 (0)