@@ -43,14 +43,13 @@ mod refine;
43
43
/// - `impl_m`: type of the method we are checking
44
44
/// - `trait_m`: the method in the trait
45
45
/// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation
46
+ #[ instrument( level = "debug" , skip( tcx) ) ]
46
47
pub ( super ) fn compare_impl_method < ' tcx > (
47
48
tcx : TyCtxt < ' tcx > ,
48
49
impl_m : ty:: AssocItem ,
49
50
trait_m : ty:: AssocItem ,
50
51
impl_trait_ref : ty:: TraitRef < ' tcx > ,
51
52
) {
52
- debug ! ( "compare_impl_method(impl_trait_ref={:?})" , impl_trait_ref) ;
53
-
54
53
let _: Result < _ , ErrorGuaranteed > = try {
55
54
check_method_is_structurally_compatible ( tcx, impl_m, trait_m, impl_trait_ref, false ) ?;
56
55
compare_method_predicate_entailment ( tcx, impl_m, trait_m, impl_trait_ref) ?;
@@ -167,8 +166,6 @@ fn compare_method_predicate_entailment<'tcx>(
167
166
trait_m : ty:: AssocItem ,
168
167
impl_trait_ref : ty:: TraitRef < ' tcx > ,
169
168
) -> Result < ( ) , ErrorGuaranteed > {
170
- let trait_to_impl_args = impl_trait_ref. args ;
171
-
172
169
// This node-id should be used for the `body_id` field on each
173
170
// `ObligationCause` (and the `FnCtxt`).
174
171
//
@@ -183,13 +180,13 @@ fn compare_method_predicate_entailment<'tcx>(
183
180
kind : impl_m. kind ,
184
181
} ) ;
185
182
186
- // Create mapping from impl to placeholder .
187
- let impl_to_placeholder_args = GenericArgs :: identity_for_item ( tcx, impl_m. def_id ) ;
188
-
189
- // 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 ) ;
183
+ // Create mapping from trait method to impl method .
184
+ let trait_to_impl_args = GenericArgs :: identity_for_item ( tcx, impl_m. def_id ) . rebase_onto (
185
+ tcx ,
186
+ impl_m . container_id ( tcx ) ,
187
+ impl_trait_ref . args ,
188
+ ) ;
189
+ debug ! ( ?trait_to_impl_args ) ;
193
190
194
191
let impl_m_predicates = tcx. predicates_of ( impl_m. def_id ) ;
195
192
let trait_m_predicates = tcx. predicates_of ( trait_m. def_id ) ;
@@ -204,28 +201,22 @@ fn compare_method_predicate_entailment<'tcx>(
204
201
let impl_predicates = tcx. predicates_of ( impl_m_predicates. parent . unwrap ( ) ) ;
205
202
let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) . predicates ;
206
203
hybrid_preds. extend (
207
- trait_m_predicates
208
- . instantiate_own ( tcx, trait_to_placeholder_args)
209
- . map ( |( predicate, _) | predicate) ,
204
+ trait_m_predicates. instantiate_own ( tcx, trait_to_impl_args) . map ( |( predicate, _) | predicate) ,
210
205
) ;
211
206
212
- // Construct trait parameter environment and then shift it into the placeholder viewpoint.
213
- // The key step here is to update the caller_bounds's predicates to be
214
- // the new hybrid bounds we computed.
215
207
let normalize_cause = traits:: ObligationCause :: misc ( impl_m_span, impl_m_def_id) ;
216
208
let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses ( & hybrid_preds) , Reveal :: UserFacing ) ;
217
209
let param_env = traits:: normalize_param_env_or_error ( tcx, param_env, normalize_cause) ;
210
+ debug ! ( caller_bounds=?param_env. caller_bounds( ) ) ;
218
211
219
212
let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
220
213
let ocx = ObligationCtxt :: new_with_diagnostics ( infcx) ;
221
214
222
- debug ! ( "compare_impl_method: caller_bounds={:?}" , param_env. caller_bounds( ) ) ;
223
-
224
215
// Create obligations for each predicate declared by the impl
225
216
// definition in the context of the hybrid param-env. This makes
226
217
// sure that the impl's method's where clauses are not more
227
218
// 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 ) ;
219
+ let impl_m_own_bounds = impl_m_predicates. instantiate_own_identity ( ) ;
229
220
for ( predicate, span) in impl_m_own_bounds {
230
221
let normalize_cause = traits:: ObligationCause :: misc ( span, impl_m_def_id) ;
231
222
let predicate = ocx. normalize ( & normalize_cause, param_env, predicate) ;
@@ -252,7 +243,6 @@ fn compare_method_predicate_entailment<'tcx>(
252
243
// any associated types appearing in the fn arguments or return
253
244
// type.
254
245
255
- // Compute placeholder form of impl and trait method tys.
256
246
let mut wf_tys = FxIndexSet :: default ( ) ;
257
247
258
248
let unnormalized_impl_sig = infcx. instantiate_binder_with_fresh_vars (
@@ -263,9 +253,9 @@ fn compare_method_predicate_entailment<'tcx>(
263
253
264
254
let norm_cause = ObligationCause :: misc ( impl_m_span, impl_m_def_id) ;
265
255
let impl_sig = ocx. normalize ( & norm_cause, param_env, unnormalized_impl_sig) ;
266
- debug ! ( "compare_impl_method: impl_fty={:?}" , impl_sig) ;
256
+ debug ! ( ? impl_sig) ;
267
257
268
- let trait_sig = tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_to_placeholder_args ) ;
258
+ let trait_sig = tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_to_impl_args ) ;
269
259
let trait_sig = tcx. liberate_late_bound_regions ( impl_m. def_id , trait_sig) ;
270
260
271
261
// Next, add all inputs and output as well-formed tys. Importantly,
@@ -276,9 +266,7 @@ fn compare_method_predicate_entailment<'tcx>(
276
266
// We also have to add the normalized trait signature
277
267
// as we don't normalize during implied bounds computation.
278
268
wf_tys. extend ( trait_sig. inputs_and_output . iter ( ) ) ;
279
- let trait_fty = Ty :: new_fn_ptr ( tcx, ty:: Binder :: dummy ( trait_sig) ) ;
280
-
281
- debug ! ( "compare_impl_method: trait_fty={:?}" , trait_fty) ;
269
+ debug ! ( ?trait_sig) ;
282
270
283
271
// FIXME: We'd want to keep more accurate spans than "the method signature" when
284
272
// processing the comparison between the trait and impl fn, but we sadly lose them
@@ -451,8 +439,6 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
451
439
// just so we don't ICE during instantiation later.
452
440
check_method_is_structurally_compatible ( tcx, impl_m, trait_m, impl_trait_ref, true ) ?;
453
441
454
- let trait_to_impl_args = impl_trait_ref. args ;
455
-
456
442
let impl_m_hir_id = tcx. local_def_id_to_hir_id ( impl_m_def_id) ;
457
443
let return_span = tcx. hir ( ) . fn_decl_by_hir_id ( impl_m_hir_id) . unwrap ( ) . output . span ( ) ;
458
444
let cause =
@@ -462,18 +448,18 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
462
448
kind : impl_m. kind ,
463
449
} ) ;
464
450
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 ) ;
451
+ // Create mapping from trait to impl (i.e. impl trait header + impl method identity args) .
452
+ let trait_to_impl_args = GenericArgs :: identity_for_item ( tcx, impl_m. def_id ) . rebase_onto (
453
+ tcx ,
454
+ impl_m . container_id ( tcx ) ,
455
+ impl_trait_ref . args ,
456
+ ) ;
471
457
472
458
let hybrid_preds = tcx
473
459
. predicates_of ( impl_m. container_id ( tcx) )
474
460
. instantiate_identity ( tcx)
475
461
. into_iter ( )
476
- . chain ( tcx. predicates_of ( trait_m. def_id ) . instantiate_own ( tcx, trait_to_placeholder_args ) )
462
+ . chain ( tcx. predicates_of ( trait_m. def_id ) . instantiate_own ( tcx, trait_to_impl_args ) )
477
463
. map ( |( clause, _) | clause) ;
478
464
let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses_from_iter ( hybrid_preds) , Reveal :: UserFacing ) ;
479
465
let param_env = traits:: normalize_param_env_or_error (
@@ -507,7 +493,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
507
493
. instantiate_binder_with_fresh_vars (
508
494
return_span,
509
495
infer:: HigherRankedType ,
510
- tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_to_placeholder_args ) ,
496
+ tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_to_impl_args ) ,
511
497
)
512
498
. fold_with ( & mut collector) ;
513
499
@@ -701,7 +687,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
701
687
// Also, we only need to account for a difference in trait and impl args,
702
688
// since we previously enforce that the trait method and impl method have the
703
689
// same generics.
704
- let num_trait_args = trait_to_impl_args . len ( ) ;
690
+ let num_trait_args = impl_trait_ref . args . len ( ) ;
705
691
let num_impl_args = tcx. generics_of ( impl_m. container_id ( tcx) ) . own_params . len ( ) ;
706
692
let ty = match ty. try_fold_with ( & mut RemapHiddenTyRegions {
707
693
tcx,
@@ -1037,12 +1023,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
1037
1023
let trait_generics = tcx. generics_of ( trait_m. def_id ) ;
1038
1024
let trait_params = trait_generics. own_counts ( ) . lifetimes ;
1039
1025
1040
- debug ! (
1041
- "check_region_bounds_on_impl_item: \
1042
- trait_generics={:?} \
1043
- impl_generics={:?}",
1044
- trait_generics, impl_generics
1045
- ) ;
1026
+ debug ! ( ?trait_generics, ?impl_generics) ;
1046
1027
1047
1028
// Must have same number of early-bound lifetime parameters.
1048
1029
// Unfortunately, if the user screws up the bounds, then this
@@ -1706,8 +1687,7 @@ pub(super) fn compare_impl_const_raw(
1706
1687
let trait_const_item = tcx. associated_item ( trait_const_item_def) ;
1707
1688
let impl_trait_ref =
1708
1689
tcx. impl_trait_ref ( impl_const_item. container_id ( tcx) ) . unwrap ( ) . instantiate_identity ( ) ;
1709
-
1710
- debug ! ( "compare_impl_const(impl_trait_ref={:?})" , impl_trait_ref) ;
1690
+ debug ! ( ?impl_trait_ref) ;
1711
1691
1712
1692
compare_number_of_generics ( tcx, impl_const_item, trait_const_item, false ) ?;
1713
1693
compare_generic_param_kinds ( tcx, impl_const_item, trait_const_item, false ) ?;
@@ -1718,6 +1698,7 @@ pub(super) fn compare_impl_const_raw(
1718
1698
/// The equivalent of [compare_method_predicate_entailment], but for associated constants
1719
1699
/// instead of associated functions.
1720
1700
// FIXME(generic_const_items): If possible extract the common parts of `compare_{type,const}_predicate_entailment`.
1701
+ #[ instrument( level = "debug" , skip( tcx) ) ]
1721
1702
fn compare_const_predicate_entailment < ' tcx > (
1722
1703
tcx : TyCtxt < ' tcx > ,
1723
1704
impl_ct : ty:: AssocItem ,
@@ -1732,13 +1713,14 @@ fn compare_const_predicate_entailment<'tcx>(
1732
1713
// because we shouldn't really have to deal with lifetimes or
1733
1714
// predicates. In fact some of this should probably be put into
1734
1715
// 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 ) ;
1716
+ let trait_to_impl_args = GenericArgs :: identity_for_item ( tcx, impl_ct. def_id ) . rebase_onto (
1717
+ tcx,
1718
+ impl_ct. container_id ( tcx) ,
1719
+ impl_trait_ref. args ,
1720
+ ) ;
1738
1721
1739
1722
// Create a parameter environment that represents the implementation's
1740
- // method.
1741
- // Compute placeholder form of impl and trait const tys.
1723
+ // associated const.
1742
1724
let impl_ty = tcx. type_of ( impl_ct_def_id) . instantiate_identity ( ) ;
1743
1725
1744
1726
let trait_ty = tcx. type_of ( trait_ct. def_id ) . instantiate ( tcx, trait_to_impl_args) ;
@@ -1772,7 +1754,7 @@ fn compare_const_predicate_entailment<'tcx>(
1772
1754
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
1773
1755
let ocx = ObligationCtxt :: new_with_diagnostics ( & infcx) ;
1774
1756
1775
- let impl_ct_own_bounds = impl_ct_predicates. instantiate_own ( tcx , impl_args ) ;
1757
+ let impl_ct_own_bounds = impl_ct_predicates. instantiate_own_identity ( ) ;
1776
1758
for ( predicate, span) in impl_ct_own_bounds {
1777
1759
let cause = ObligationCause :: misc ( span, impl_ct_def_id) ;
1778
1760
let predicate = ocx. normalize ( & cause, param_env, predicate) ;
@@ -1783,20 +1765,15 @@ fn compare_const_predicate_entailment<'tcx>(
1783
1765
1784
1766
// There is no "body" here, so just pass dummy id.
1785
1767
let impl_ty = ocx. normalize ( & cause, param_env, impl_ty) ;
1786
-
1787
- debug ! ( "compare_const_impl: impl_ty={:?}" , impl_ty) ;
1768
+ debug ! ( ?impl_ty) ;
1788
1769
1789
1770
let trait_ty = ocx. normalize ( & cause, param_env, trait_ty) ;
1790
-
1791
- debug ! ( "compare_const_impl: trait_ty={:?}" , trait_ty) ;
1771
+ debug ! ( ?trait_ty) ;
1792
1772
1793
1773
let err = ocx. sup ( & cause, param_env, trait_ty, impl_ty) ;
1794
1774
1795
1775
if let Err ( terr) = err {
1796
- debug ! (
1797
- "checking associated const for compatibility: impl ty {:?}, trait ty {:?}" ,
1798
- impl_ty, trait_ty
1799
- ) ;
1776
+ debug ! ( ?impl_ty, ?trait_ty) ;
1800
1777
1801
1778
// Locate the Span containing just the type of the offending impl
1802
1779
let ( ty, _) = tcx. hir ( ) . expect_impl_item ( impl_ct_def_id) . expect_const ( ) ;
@@ -1841,14 +1818,13 @@ fn compare_const_predicate_entailment<'tcx>(
1841
1818
ocx. resolve_regions_and_report_errors ( impl_ct_def_id, & outlives_env)
1842
1819
}
1843
1820
1821
+ #[ instrument( level = "debug" , skip( tcx) ) ]
1844
1822
pub ( super ) fn compare_impl_ty < ' tcx > (
1845
1823
tcx : TyCtxt < ' tcx > ,
1846
1824
impl_ty : ty:: AssocItem ,
1847
1825
trait_ty : ty:: AssocItem ,
1848
1826
impl_trait_ref : ty:: TraitRef < ' tcx > ,
1849
1827
) {
1850
- debug ! ( "compare_impl_type(impl_trait_ref={:?})" , impl_trait_ref) ;
1851
-
1852
1828
let _: Result < ( ) , ErrorGuaranteed > = try {
1853
1829
compare_number_of_generics ( tcx, impl_ty, trait_ty, false ) ?;
1854
1830
compare_generic_param_kinds ( tcx, impl_ty, trait_ty, false ) ?;
@@ -1860,20 +1836,23 @@ pub(super) fn compare_impl_ty<'tcx>(
1860
1836
1861
1837
/// The equivalent of [compare_method_predicate_entailment], but for associated types
1862
1838
/// instead of associated functions.
1839
+ #[ instrument( level = "debug" , skip( tcx) ) ]
1863
1840
fn compare_type_predicate_entailment < ' tcx > (
1864
1841
tcx : TyCtxt < ' tcx > ,
1865
1842
impl_ty : ty:: AssocItem ,
1866
1843
trait_ty : ty:: AssocItem ,
1867
1844
impl_trait_ref : ty:: TraitRef < ' tcx > ,
1868
1845
) -> 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 ) ;
1846
+ let trait_to_impl_args = GenericArgs :: identity_for_item ( tcx, impl_ty. def_id ) . rebase_onto (
1847
+ tcx,
1848
+ impl_ty. container_id ( tcx) ,
1849
+ impl_trait_ref. args ,
1850
+ ) ;
1872
1851
1873
1852
let impl_ty_predicates = tcx. predicates_of ( impl_ty. def_id ) ;
1874
1853
let trait_ty_predicates = tcx. predicates_of ( trait_ty. def_id ) ;
1875
1854
1876
- let impl_ty_own_bounds = impl_ty_predicates. instantiate_own ( tcx , impl_args ) ;
1855
+ let impl_ty_own_bounds = impl_ty_predicates. instantiate_own_identity ( ) ;
1877
1856
if impl_ty_own_bounds. len ( ) == 0 {
1878
1857
// Nothing to check.
1879
1858
return Ok ( ( ) ) ;
@@ -1883,7 +1862,7 @@ fn compare_type_predicate_entailment<'tcx>(
1883
1862
// `ObligationCause` (and the `FnCtxt`). This is what
1884
1863
// `regionck_item` expects.
1885
1864
let impl_ty_def_id = impl_ty. def_id . expect_local ( ) ;
1886
- debug ! ( "compare_type_predicate_entailment: trait_to_impl_args={:?}" , trait_to_impl_args) ;
1865
+ debug ! ( ? trait_to_impl_args) ;
1887
1866
1888
1867
// The predicates declared by the impl definition, the trait and the
1889
1868
// associated type in the trait are assumed.
@@ -1894,18 +1873,18 @@ fn compare_type_predicate_entailment<'tcx>(
1894
1873
. instantiate_own ( tcx, trait_to_impl_args)
1895
1874
. map ( |( predicate, _) | predicate) ,
1896
1875
) ;
1897
-
1898
- debug ! ( "compare_type_predicate_entailment: bounds={:?}" , hybrid_preds) ;
1876
+ debug ! ( ?hybrid_preds) ;
1899
1877
1900
1878
let impl_ty_span = tcx. def_span ( impl_ty_def_id) ;
1901
1879
let normalize_cause = ObligationCause :: misc ( impl_ty_span, impl_ty_def_id) ;
1880
+
1902
1881
let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses ( & hybrid_preds) , Reveal :: UserFacing ) ;
1903
1882
let param_env = traits:: normalize_param_env_or_error ( tcx, param_env, normalize_cause) ;
1883
+ debug ! ( caller_bounds=?param_env. caller_bounds( ) ) ;
1884
+
1904
1885
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
1905
1886
let ocx = ObligationCtxt :: new_with_diagnostics ( & infcx) ;
1906
1887
1907
- debug ! ( "compare_type_predicate_entailment: caller_bounds={:?}" , param_env. caller_bounds( ) ) ;
1908
-
1909
1888
for ( predicate, span) in impl_ty_own_bounds {
1910
1889
let cause = ObligationCause :: misc ( span, impl_ty_def_id) ;
1911
1890
let predicate = ocx. normalize ( & cause, param_env, predicate) ;
@@ -2005,11 +1984,11 @@ pub(super) fn check_type_bounds<'tcx>(
2005
1984
. explicit_item_bounds ( trait_ty. def_id )
2006
1985
. iter_instantiated_copied ( tcx, rebased_args)
2007
1986
. map ( |( concrete_ty_bound, span) | {
2008
- debug ! ( "check_type_bounds: concrete_ty_bound = {:?}" , concrete_ty_bound) ;
1987
+ debug ! ( ? concrete_ty_bound) ;
2009
1988
traits:: Obligation :: new ( tcx, mk_cause ( span) , param_env, concrete_ty_bound)
2010
1989
} )
2011
1990
. collect ( ) ;
2012
- debug ! ( "check_type_bounds: item_bounds={:?}" , obligations) ;
1991
+ debug ! ( item_bounds=? obligations) ;
2013
1992
2014
1993
// Normalize predicates with the assumption that the GAT may always normalize
2015
1994
// to its definition type. This should be the param-env we use to *prove* the
@@ -2028,7 +2007,7 @@ pub(super) fn check_type_bounds<'tcx>(
2028
2007
} else {
2029
2008
ocx. normalize ( & normalize_cause, normalize_param_env, obligation. predicate )
2030
2009
} ;
2031
- debug ! ( "compare_projection_bounds: normalized predicate = {:?}" , normalized_predicate) ;
2010
+ debug ! ( ? normalized_predicate) ;
2032
2011
obligation. predicate = normalized_predicate;
2033
2012
2034
2013
ocx. register_obligation ( obligation) ;
0 commit comments