Skip to content

Commit d2fa92b

Browse files
Stop passing traitref/traitpredicate by ref
1 parent 295d922 commit d2fa92b

File tree

17 files changed

+89
-56
lines changed

17 files changed

+89
-56
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
@@ -530,7 +530,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
530530
};
531531

532532
let err_msg = self.get_standard_error_message(
533-
&main_trait_predicate,
533+
main_trait_predicate,
534534
message,
535535
predicate_is_const,
536536
append_const_msg,
@@ -601,7 +601,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
601601
let explanation = get_explanation_based_on_obligation(
602602
self.tcx,
603603
&obligation,
604-
&main_trait_predicate,
604+
trait_predicate,
605605
pre_message,
606606
);
607607

@@ -652,7 +652,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
652652

653653
let UnsatisfiedConst(unsatisfied_const) = self
654654
.maybe_add_note_for_unsatisfied_const(
655-
&trait_predicate,
655+
trait_predicate,
656656
&mut err,
657657
span,
658658
);
@@ -669,7 +669,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
669669
err.span_label(tcx.def_span(body), s);
670670
}
671671

672-
self.suggest_floating_point_literal(&obligation, &mut err, &main_trait_ref);
672+
self.suggest_floating_point_literal(&obligation, &mut err, main_trait_ref);
673673
self.suggest_dereferencing_index(&obligation, &mut err, trait_predicate);
674674
suggested |= self.suggest_dereferences(&obligation, &mut err, trait_predicate);
675675
suggested |= self.suggest_fn_call(&obligation, &mut err, trait_predicate);
@@ -704,7 +704,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
704704
span,
705705
trait_predicate,
706706
);
707-
self.note_version_mismatch(&mut err, &main_trait_ref);
707+
self.note_version_mismatch(&mut err, main_trait_ref);
708708
self.suggest_remove_await(&obligation, &mut err);
709709
self.suggest_derive(&obligation, &mut err, trait_predicate);
710710

@@ -752,7 +752,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
752752

753753
self.try_to_add_help_message(
754754
&obligation,
755-
&main_trait_predicate,
755+
main_trait_predicate,
756756
&mut err,
757757
span,
758758
is_fn_trait,
@@ -2224,11 +2224,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22242224
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
22252225
/// with the same path as `trait_ref`, a help message about
22262226
/// a probable version mismatch is added to `err`
2227-
fn note_version_mismatch(
2228-
&self,
2229-
err: &mut Diag<'_>,
2230-
trait_ref: &ty::PolyTraitRef<'tcx>,
2231-
) -> bool {
2227+
fn note_version_mismatch(&self, err: &mut Diag<'_>, trait_ref: ty::PolyTraitRef<'tcx>) -> bool {
22322228
let get_trait_impls = |trait_def_id| {
22332229
let mut trait_impls = vec![];
22342230
self.tcx.for_each_relevant_impl(
@@ -3032,7 +3028,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
30323028

30333029
fn get_standard_error_message(
30343030
&self,
3035-
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
3031+
trait_predicate: ty::PolyTraitPredicate<'tcx>,
30363032
message: Option<String>,
30373033
predicate_is_const: bool,
30383034
append_const_msg: Option<AppendConstMessage>,
@@ -3203,7 +3199,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32033199
fn try_to_add_help_message(
32043200
&self,
32053201
obligation: &PredicateObligation<'tcx>,
3206-
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
3202+
trait_predicate: ty::PolyTraitPredicate<'tcx>,
32073203
err: &mut Diag<'_>,
32083204
span: Span,
32093205
is_fn_trait: bool,
@@ -3235,7 +3231,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32353231
params,
32363232
);
32373233
} else if !trait_predicate.has_non_region_infer()
3238-
&& self.predicate_can_apply(obligation.param_env, *trait_predicate)
3234+
&& self.predicate_can_apply(obligation.param_env, trait_predicate)
32393235
{
32403236
// If a where-clause may be useful, remind the
32413237
// user that they can add it.
@@ -3246,7 +3242,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32463242
// which is somewhat confusing.
32473243
self.suggest_restricting_param_bound(
32483244
err,
3249-
*trait_predicate,
3245+
trait_predicate,
32503246
None,
32513247
obligation.cause.body_id,
32523248
);
@@ -3261,7 +3257,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32613257
);
32623258
} else if !suggested && !unsatisfied_const {
32633259
// Can't show anything else useful, try to find similar impls.
3264-
let impl_candidates = self.find_similar_impl_candidates(*trait_predicate);
3260+
let impl_candidates = self.find_similar_impl_candidates(trait_predicate);
32653261
if !self.report_similar_impl_candidates(
32663262
&impl_candidates,
32673263
trait_predicate.to_poly_trait_ref(),
@@ -3272,7 +3268,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32723268
) {
32733269
self.report_similar_impl_candidates_for_root_obligation(
32743270
obligation,
3275-
*trait_predicate,
3271+
trait_predicate,
32763272
body_def_id,
32773273
err,
32783274
);
@@ -3346,7 +3342,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
33463342

33473343
fn maybe_add_note_for_unsatisfied_const(
33483344
&self,
3349-
_trait_predicate: &ty::PolyTraitPredicate<'tcx>,
3345+
_trait_predicate: ty::PolyTraitPredicate<'tcx>,
33503346
_err: &mut Diag<'_>,
33513347
_span: Span,
33523348
) -> 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/auto-traits/typeck-default-trait-impl-precedence.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `&'static u32: Defaulted` is not satisfied
22
--> $DIR/typeck-default-trait-impl-precedence.rs:19:20
33
|
44
LL | is_defaulted::<&'static u32>();
5-
| ^^^^^^^^^^^^ the trait `Defaulted` is not implemented for `&'static u32`, which is required by `&'static u32: Defaulted`
5+
| ^^^^^^^^^^^^ the trait `Signed` is not implemented for `u32`, which is required by `&'static u32: Defaulted`
66
|
77
note: required for `&'static u32` to implement `Defaulted`
88
--> $DIR/typeck-default-trait-impl-precedence.rs:10:19

tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.next.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `i32: Baz<Self>` is not satisfied
22
--> $DIR/assume-gat-normalization-for-nested-goals.rs:9:30
33
|
44
LL | type Bar<T>: Baz<Self> = i32;
5-
| ^^^ the trait `Eq<i32>` is not implemented for `i32`, which is required by `i32: Baz<Self>`
5+
| ^^^ the trait `Eq<i32>` is not implemented for `<Self as Foo>::Bar<()>`, which is required by `i32: Baz<Self>`
66
|
77
note: required for `i32` to implement `Baz<Self>`
88
--> $DIR/assume-gat-normalization-for-nested-goals.rs:16:23
@@ -14,10 +14,10 @@ note: required by a bound in `Foo::Bar`
1414
|
1515
LL | type Bar<T>: Baz<Self> = i32;
1616
| ^^^^^^^^^ required by this bound in `Foo::Bar`
17-
help: consider further restricting the associated type
17+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
1818
|
19-
LL | trait Foo where <Self as Foo>::Bar<()>: Eq<i32> {
20-
| +++++++++++++++++++++++++++++++++++++
19+
LL | trait Foo where i32: Baz<Self> {
20+
| ++++++++++++++++++++
2121

2222
error: aborting due to 1 previous error
2323

tests/ui/impl-trait/nested_impl_trait.stderr

+48-10
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,67 @@ LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
4242
|
4343
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
4444

45+
error[E0391]: cycle detected when computing type of `bad_in_ret_position::{opaque#0}`
46+
--> $DIR/nested_impl_trait.rs:6:46
47+
|
48+
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
49+
| ^^^^^^^^^^^^^^^^^^^^^
50+
|
51+
note: ...which requires computing type of opaque `bad_in_ret_position::{opaque#0}`...
52+
--> $DIR/nested_impl_trait.rs:6:46
53+
|
54+
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
55+
| ^^^^^^^^^^^^^^^^^^^^^
56+
note: ...which requires type-checking `bad_in_ret_position`...
57+
--> $DIR/nested_impl_trait.rs:6:1
58+
|
59+
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
60+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
61+
= note: ...which again requires computing type of `bad_in_ret_position::{opaque#0}`, completing the cycle
62+
note: cycle used when checking that `bad_in_ret_position::{opaque#0}` is well-formed
63+
--> $DIR/nested_impl_trait.rs:6:46
64+
|
65+
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
66+
| ^^^^^^^^^^^^^^^^^^^^^
67+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
68+
4569
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
4670
--> $DIR/nested_impl_trait.rs:6:46
4771
|
4872
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
4973
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
74+
75+
error[E0391]: cycle detected when computing type of `<impl at $DIR/nested_impl_trait.rs:18:1: 18:7>::bad::{opaque#0}`
76+
--> $DIR/nested_impl_trait.rs:19:34
77+
|
78+
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
79+
| ^^^^^^^^^^^^^^^^^^^^^
5080
|
51-
help: consider further restricting this bound
81+
note: ...which requires computing type of opaque `<impl at $DIR/nested_impl_trait.rs:18:1: 18:7>::bad::{opaque#0}`...
82+
--> $DIR/nested_impl_trait.rs:19:34
83+
|
84+
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
85+
| ^^^^^^^^^^^^^^^^^^^^^
86+
note: ...which requires type-checking `<impl at $DIR/nested_impl_trait.rs:18:1: 18:7>::bad`...
87+
--> $DIR/nested_impl_trait.rs:19:5
5288
|
53-
LL | fn bad_in_ret_position(x: impl Into<u32> + std::fmt::Debug) -> impl Into<impl Debug> { x }
54-
| +++++++++++++++++
89+
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
90+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
= note: ...which again requires computing type of `<impl at $DIR/nested_impl_trait.rs:18:1: 18:7>::bad::{opaque#0}`, completing the cycle
92+
note: cycle used when checking that `<impl at $DIR/nested_impl_trait.rs:18:1: 18:7>::bad::{opaque#0}` is well-formed
93+
--> $DIR/nested_impl_trait.rs:19:34
94+
|
95+
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
96+
| ^^^^^^^^^^^^^^^^^^^^^
97+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
5598

5699
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
57100
--> $DIR/nested_impl_trait.rs:19:34
58101
|
59102
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
60103
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
61-
|
62-
help: consider further restricting this bound
63-
|
64-
LL | fn bad(x: impl Into<u32> + std::fmt::Debug) -> impl Into<impl Debug> { x }
65-
| +++++++++++++++++
66104

67-
error: aborting due to 7 previous errors
105+
error: aborting due to 9 previous errors
68106

69-
Some errors have detailed explanations: E0277, E0562, E0666.
107+
Some errors have detailed explanations: E0277, E0391, E0562, E0666.
70108
For more information about an error, try `rustc --explain E0277`.

tests/ui/kindck/kindck-send-object.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: `&'static (dyn Dummy + 'static)` cannot be sent between threads sa
44
LL | assert_send::<&'static (dyn Dummy + 'static)>();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&'static (dyn Dummy + 'static)` cannot be sent between threads safely
66
|
7-
= help: the trait `Sync` is not implemented for `&'static (dyn Dummy + 'static)`, which is required by `&'static (dyn Dummy + 'static): Send`
7+
= help: the trait `Sync` is not implemented for `(dyn Dummy + 'static)`, which is required by `&'static (dyn Dummy + 'static): Send`
88
= note: required for `&'static (dyn Dummy + 'static)` to implement `Send`
99
note: required by a bound in `assert_send`
1010
--> $DIR/kindck-send-object.rs:5:18

0 commit comments

Comments
 (0)