@@ -167,8 +167,6 @@ fn compare_method_predicate_entailment<'tcx>(
167
167
trait_m : ty:: AssocItem ,
168
168
impl_trait_ref : ty:: TraitRef < ' tcx > ,
169
169
) -> Result < ( ) , ErrorGuaranteed > {
170
- let trait_to_impl_args = impl_trait_ref. args ;
171
-
172
170
// This node-id should be used for the `body_id` field on each
173
171
// `ObligationCause` (and the `FnCtxt`).
174
172
//
@@ -183,13 +181,13 @@ fn compare_method_predicate_entailment<'tcx>(
183
181
kind : impl_m. kind ,
184
182
} ) ;
185
183
186
- // Create mapping from impl to placeholder.
187
- let impl_to_placeholder_args = GenericArgs :: identity_for_item ( tcx, impl_m. def_id ) ;
188
-
189
184
// Create mapping from trait to placeholder.
190
- let trait_to_placeholder_args =
191
- impl_to_placeholder_args. rebase_onto ( tcx, impl_m. container_id ( tcx) , trait_to_impl_args) ;
192
- debug ! ( "compare_impl_method: trait_to_placeholder_args={:?}" , trait_to_placeholder_args) ;
185
+ let trait_to_impl_args = GenericArgs :: identity_for_item ( tcx, impl_m. def_id ) . rebase_onto (
186
+ tcx,
187
+ impl_m. container_id ( tcx) ,
188
+ impl_trait_ref. args ,
189
+ ) ;
190
+ debug ! ( "compare_impl_method: trait_to_placeholder_args={:?}" , trait_to_impl_args) ;
193
191
194
192
let impl_m_predicates = tcx. predicates_of ( impl_m. def_id ) ;
195
193
let trait_m_predicates = tcx. predicates_of ( trait_m. def_id ) ;
@@ -204,9 +202,7 @@ fn compare_method_predicate_entailment<'tcx>(
204
202
let impl_predicates = tcx. predicates_of ( impl_m_predicates. parent . unwrap ( ) ) ;
205
203
let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) . predicates ;
206
204
hybrid_preds. extend (
207
- trait_m_predicates
208
- . instantiate_own ( tcx, trait_to_placeholder_args)
209
- . map ( |( predicate, _) | predicate) ,
205
+ trait_m_predicates. instantiate_own ( tcx, trait_to_impl_args) . map ( |( predicate, _) | predicate) ,
210
206
) ;
211
207
212
208
// Construct trait parameter environment and then shift it into the placeholder viewpoint.
@@ -225,7 +221,7 @@ fn compare_method_predicate_entailment<'tcx>(
225
221
// definition in the context of the hybrid param-env. This makes
226
222
// sure that the impl's method's where clauses are not more
227
223
// restrictive than the trait's method (and the impl itself).
228
- let impl_m_own_bounds = impl_m_predicates. instantiate_own ( tcx , impl_to_placeholder_args ) ;
224
+ let impl_m_own_bounds = impl_m_predicates. instantiate_own_identity ( ) ;
229
225
for ( predicate, span) in impl_m_own_bounds {
230
226
let normalize_cause = traits:: ObligationCause :: misc ( span, impl_m_def_id) ;
231
227
let predicate = ocx. normalize ( & normalize_cause, param_env, predicate) ;
@@ -252,7 +248,6 @@ fn compare_method_predicate_entailment<'tcx>(
252
248
// any associated types appearing in the fn arguments or return
253
249
// type.
254
250
255
- // Compute placeholder form of impl and trait method tys.
256
251
let mut wf_tys = FxIndexSet :: default ( ) ;
257
252
258
253
let unnormalized_impl_sig = infcx. instantiate_binder_with_fresh_vars (
@@ -265,7 +260,7 @@ fn compare_method_predicate_entailment<'tcx>(
265
260
let impl_sig = ocx. normalize ( & norm_cause, param_env, unnormalized_impl_sig) ;
266
261
debug ! ( "compare_impl_method: impl_fty={:?}" , impl_sig) ;
267
262
268
- let trait_sig = tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_to_placeholder_args ) ;
263
+ let trait_sig = tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_to_impl_args ) ;
269
264
let trait_sig = tcx. liberate_late_bound_regions ( impl_m. def_id , trait_sig) ;
270
265
271
266
// Next, add all inputs and output as well-formed tys. Importantly,
@@ -451,8 +446,6 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
451
446
// just so we don't ICE during instantiation later.
452
447
check_method_is_structurally_compatible ( tcx, impl_m, trait_m, impl_trait_ref, true ) ?;
453
448
454
- let trait_to_impl_args = impl_trait_ref. args ;
455
-
456
449
let impl_m_hir_id = tcx. local_def_id_to_hir_id ( impl_m_def_id) ;
457
450
let return_span = tcx. hir ( ) . fn_decl_by_hir_id ( impl_m_hir_id) . unwrap ( ) . output . span ( ) ;
458
451
let cause =
@@ -462,18 +455,18 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
462
455
kind : impl_m. kind ,
463
456
} ) ;
464
457
465
- // Create mapping from impl to placeholder .
466
- let impl_to_placeholder_args = GenericArgs :: identity_for_item ( tcx, impl_m. def_id ) ;
467
-
468
- // Create mapping from trait to placeholder.
469
- let trait_to_placeholder_args =
470
- impl_to_placeholder_args . rebase_onto ( tcx , impl_m . container_id ( tcx ) , trait_to_impl_args ) ;
458
+ // Create mapping from trait to impl (i.e. impl trait header + impl method identity args) .
459
+ let trait_to_impl_args = GenericArgs :: identity_for_item ( tcx, impl_m. def_id ) . rebase_onto (
460
+ tcx ,
461
+ impl_m . container_id ( tcx ) ,
462
+ impl_trait_ref . args ,
463
+ ) ;
471
464
472
465
let hybrid_preds = tcx
473
466
. predicates_of ( impl_m. container_id ( tcx) )
474
467
. instantiate_identity ( tcx)
475
468
. into_iter ( )
476
- . chain ( tcx. predicates_of ( trait_m. def_id ) . instantiate_own ( tcx, trait_to_placeholder_args ) )
469
+ . chain ( tcx. predicates_of ( trait_m. def_id ) . instantiate_own ( tcx, trait_to_impl_args ) )
477
470
. map ( |( clause, _) | clause) ;
478
471
let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses_from_iter ( hybrid_preds) , Reveal :: UserFacing ) ;
479
472
let param_env = traits:: normalize_param_env_or_error (
@@ -507,7 +500,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
507
500
. instantiate_binder_with_fresh_vars (
508
501
return_span,
509
502
infer:: HigherRankedType ,
510
- tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_to_placeholder_args ) ,
503
+ tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_to_impl_args ) ,
511
504
)
512
505
. fold_with ( & mut collector) ;
513
506
@@ -1732,13 +1725,14 @@ fn compare_const_predicate_entailment<'tcx>(
1732
1725
// because we shouldn't really have to deal with lifetimes or
1733
1726
// predicates. In fact some of this should probably be put into
1734
1727
// shared functions because of DRY violations...
1735
- let impl_args = GenericArgs :: identity_for_item ( tcx, impl_ct. def_id ) ;
1736
- let trait_to_impl_args =
1737
- impl_args. rebase_onto ( tcx, impl_ct. container_id ( tcx) , impl_trait_ref. args ) ;
1728
+ let trait_to_impl_args = GenericArgs :: identity_for_item ( tcx, impl_ct. def_id ) . rebase_onto (
1729
+ tcx,
1730
+ impl_ct. container_id ( tcx) ,
1731
+ impl_trait_ref. args ,
1732
+ ) ;
1738
1733
1739
1734
// Create a parameter environment that represents the implementation's
1740
1735
// method.
1741
- // Compute placeholder form of impl and trait const tys.
1742
1736
let impl_ty = tcx. type_of ( impl_ct_def_id) . instantiate_identity ( ) ;
1743
1737
1744
1738
let trait_ty = tcx. type_of ( trait_ct. def_id ) . instantiate ( tcx, trait_to_impl_args) ;
@@ -1772,7 +1766,7 @@ fn compare_const_predicate_entailment<'tcx>(
1772
1766
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
1773
1767
let ocx = ObligationCtxt :: new_with_diagnostics ( & infcx) ;
1774
1768
1775
- let impl_ct_own_bounds = impl_ct_predicates. instantiate_own ( tcx , impl_args ) ;
1769
+ let impl_ct_own_bounds = impl_ct_predicates. instantiate_own_identity ( ) ;
1776
1770
for ( predicate, span) in impl_ct_own_bounds {
1777
1771
let cause = ObligationCause :: misc ( span, impl_ct_def_id) ;
1778
1772
let predicate = ocx. normalize ( & cause, param_env, predicate) ;
@@ -1866,14 +1860,16 @@ fn compare_type_predicate_entailment<'tcx>(
1866
1860
trait_ty : ty:: AssocItem ,
1867
1861
impl_trait_ref : ty:: TraitRef < ' tcx > ,
1868
1862
) -> Result < ( ) , ErrorGuaranteed > {
1869
- let impl_args = GenericArgs :: identity_for_item ( tcx, impl_ty. def_id ) ;
1870
- let trait_to_impl_args =
1871
- impl_args. rebase_onto ( tcx, impl_ty. container_id ( tcx) , impl_trait_ref. args ) ;
1863
+ let trait_to_impl_args = GenericArgs :: identity_for_item ( tcx, impl_ty. def_id ) . rebase_onto (
1864
+ tcx,
1865
+ impl_ty. container_id ( tcx) ,
1866
+ impl_trait_ref. args ,
1867
+ ) ;
1872
1868
1873
1869
let impl_ty_predicates = tcx. predicates_of ( impl_ty. def_id ) ;
1874
1870
let trait_ty_predicates = tcx. predicates_of ( trait_ty. def_id ) ;
1875
1871
1876
- let impl_ty_own_bounds = impl_ty_predicates. instantiate_own ( tcx , impl_args ) ;
1872
+ let impl_ty_own_bounds = impl_ty_predicates. instantiate_own_identity ( ) ;
1877
1873
if impl_ty_own_bounds. len ( ) == 0 {
1878
1874
// Nothing to check.
1879
1875
return Ok ( ( ) ) ;
0 commit comments