Skip to content

Commit c90b1fc

Browse files
Stop passing traitref/traitpredicate by ref
1 parent 5cbd6c7 commit c90b1fc

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
@@ -537,7 +537,7 @@ impl<T> Trait<T> for X {
537537
for pred in hir_generics.bounds_for_param(def_id) {
538538
if self.constrain_generic_bound_associated_type_structured_suggestion(
539539
diag,
540-
&trait_ref,
540+
trait_ref,
541541
pred.bounds,
542542
assoc,
543543
assoc_args,
@@ -706,7 +706,7 @@ fn foo(&self) -> Self::T { String::new() }
706706

707707
self.constrain_generic_bound_associated_type_structured_suggestion(
708708
diag,
709-
&trait_ref,
709+
trait_ref,
710710
opaque_hir_ty.bounds,
711711
assoc,
712712
assoc_args,
@@ -860,7 +860,7 @@ fn foo(&self) -> Self::T { String::new() }
860860
fn constrain_generic_bound_associated_type_structured_suggestion(
861861
&self,
862862
diag: &mut Diag<'_>,
863-
trait_ref: &ty::TraitRef<'tcx>,
863+
trait_ref: ty::TraitRef<'tcx>,
864864
bounds: hir::GenericBounds<'_>,
865865
assoc: ty::AssocItem,
866866
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 => {
@@ -4822,7 +4822,7 @@ impl<'a, 'hir> hir::intravisit::Visitor<'hir> for ReplaceImplTraitVisitor<'a> {
48224822
pub(super) fn get_explanation_based_on_obligation<'tcx>(
48234823
tcx: TyCtxt<'tcx>,
48244824
obligation: &PredicateObligation<'tcx>,
4825-
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
4825+
trait_predicate: ty::PolyTraitPredicate<'tcx>,
48264826
pre_message: String,
48274827
) -> String {
48284828
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

@@ -654,7 +654,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
654654

655655
let UnsatisfiedConst(unsatisfied_const) = self
656656
.maybe_add_note_for_unsatisfied_const(
657-
&leaf_trait_predicate,
657+
leaf_trait_predicate,
658658
&mut err,
659659
span,
660660
);
@@ -671,7 +671,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
671671
err.span_label(tcx.def_span(body), s);
672672
}
673673

674-
self.suggest_floating_point_literal(&obligation, &mut err, &leaf_trait_ref);
674+
self.suggest_floating_point_literal(&obligation, &mut err, leaf_trait_ref);
675675
self.suggest_dereferencing_index(&obligation, &mut err, leaf_trait_predicate);
676676
suggested |= self.suggest_dereferences(&obligation, &mut err, leaf_trait_predicate);
677677
suggested |= self.suggest_fn_call(&obligation, &mut err, leaf_trait_predicate);
@@ -706,7 +706,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
706706
span,
707707
leaf_trait_predicate,
708708
);
709-
self.note_version_mismatch(&mut err, &leaf_trait_ref);
709+
self.note_version_mismatch(&mut err, leaf_trait_ref);
710710
self.suggest_remove_await(&obligation, &mut err);
711711
self.suggest_derive(&obligation, &mut err, leaf_trait_predicate);
712712

@@ -754,7 +754,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
754754

755755
self.try_to_add_help_message(
756756
&obligation,
757-
&leaf_trait_predicate,
757+
leaf_trait_predicate,
758758
&mut err,
759759
span,
760760
is_fn_trait,
@@ -2226,11 +2226,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22262226
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
22272227
/// with the same path as `trait_ref`, a help message about
22282228
/// a probable version mismatch is added to `err`
2229-
fn note_version_mismatch(
2230-
&self,
2231-
err: &mut Diag<'_>,
2232-
trait_ref: &ty::PolyTraitRef<'tcx>,
2233-
) -> bool {
2229+
fn note_version_mismatch(&self, err: &mut Diag<'_>, trait_ref: ty::PolyTraitRef<'tcx>) -> bool {
22342230
let get_trait_impls = |trait_def_id| {
22352231
let mut trait_impls = vec![];
22362232
self.tcx.for_each_relevant_impl(
@@ -3034,7 +3030,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
30343030

30353031
fn get_standard_error_message(
30363032
&self,
3037-
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
3033+
trait_predicate: ty::PolyTraitPredicate<'tcx>,
30383034
message: Option<String>,
30393035
predicate_is_const: bool,
30403036
append_const_msg: Option<AppendConstMessage>,
@@ -3205,7 +3201,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32053201
fn try_to_add_help_message(
32063202
&self,
32073203
obligation: &PredicateObligation<'tcx>,
3208-
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
3204+
trait_predicate: ty::PolyTraitPredicate<'tcx>,
32093205
err: &mut Diag<'_>,
32103206
span: Span,
32113207
is_fn_trait: bool,
@@ -3237,7 +3233,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32373233
params,
32383234
);
32393235
} else if !trait_predicate.has_non_region_infer()
3240-
&& self.predicate_can_apply(obligation.param_env, *trait_predicate)
3236+
&& self.predicate_can_apply(obligation.param_env, trait_predicate)
32413237
{
32423238
// If a where-clause may be useful, remind the
32433239
// user that they can add it.
@@ -3248,7 +3244,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32483244
// which is somewhat confusing.
32493245
self.suggest_restricting_param_bound(
32503246
err,
3251-
*trait_predicate,
3247+
trait_predicate,
32523248
None,
32533249
obligation.cause.body_id,
32543250
);
@@ -3263,7 +3259,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32633259
);
32643260
} else if !suggested && !unsatisfied_const {
32653261
// Can't show anything else useful, try to find similar impls.
3266-
let impl_candidates = self.find_similar_impl_candidates(*trait_predicate);
3262+
let impl_candidates = self.find_similar_impl_candidates(trait_predicate);
32673263
if !self.report_similar_impl_candidates(
32683264
&impl_candidates,
32693265
trait_predicate.to_poly_trait_ref(),
@@ -3274,7 +3270,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32743270
) {
32753271
self.report_similar_impl_candidates_for_root_obligation(
32763272
obligation,
3277-
*trait_predicate,
3273+
trait_predicate,
32783274
body_def_id,
32793275
err,
32803276
);
@@ -3348,7 +3344,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
33483344

33493345
fn maybe_add_note_for_unsatisfied_const(
33503346
&self,
3351-
_trait_predicate: &ty::PolyTraitPredicate<'tcx>,
3347+
_trait_predicate: ty::PolyTraitPredicate<'tcx>,
33523348
_err: &mut Diag<'_>,
33533349
_span: Span,
33543350
) -> 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)