@@ -194,24 +194,16 @@ fn compare_method_predicate_entailment<'tcx>(
194
194
let impl_m_predicates = tcx. predicates_of ( impl_m. def_id ) ;
195
195
let trait_m_predicates = tcx. predicates_of ( trait_m. def_id ) ;
196
196
197
- // Create obligations for each predicate declared by the impl
198
- // definition in the context of the trait's parameter
199
- // environment. We can't just use `impl_env.caller_bounds`,
200
- // however, because we want to replace all late-bound regions with
201
- // region variables.
202
- let impl_predicates = tcx. predicates_of ( impl_m_predicates. parent . unwrap ( ) ) ;
203
- let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) ;
204
-
205
- debug ! ( "compare_impl_method: impl_bounds={:?}" , hybrid_preds) ;
206
-
207
197
// This is the only tricky bit of the new way we check implementation methods
208
198
// We need to build a set of predicates where only the method-level bounds
209
199
// are from the trait and we assume all other bounds from the implementation
210
200
// to be previously satisfied.
211
201
//
212
202
// We then register the obligations from the impl_m and check to see
213
203
// if all constraints hold.
214
- hybrid_preds. predicates . extend (
204
+ let impl_predicates = tcx. predicates_of ( impl_m_predicates. parent . unwrap ( ) ) ;
205
+ let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) . predicates ;
206
+ hybrid_preds. extend (
215
207
trait_m_predicates
216
208
. instantiate_own ( tcx, trait_to_placeholder_args)
217
209
. map ( |( predicate, _) | predicate) ,
@@ -221,14 +213,18 @@ fn compare_method_predicate_entailment<'tcx>(
221
213
// The key step here is to update the caller_bounds's predicates to be
222
214
// the new hybrid bounds we computed.
223
215
let normalize_cause = traits:: ObligationCause :: misc ( impl_m_span, impl_m_def_id) ;
224
- let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses ( & hybrid_preds. predicates ) , Reveal :: UserFacing ) ;
216
+ let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses ( & hybrid_preds) , Reveal :: UserFacing ) ;
225
217
let param_env = traits:: normalize_param_env_or_error ( tcx, param_env, normalize_cause) ;
226
218
227
219
let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
228
220
let ocx = ObligationCtxt :: new_with_diagnostics ( infcx) ;
229
221
230
222
debug ! ( "compare_impl_method: caller_bounds={:?}" , param_env. caller_bounds( ) ) ;
231
223
224
+ // Create obligations for each predicate declared by the impl
225
+ // definition in the context of the hybrid param-env. This makes
226
+ // sure that the impl's method's where clauses are not more
227
+ // restrictive than the trait's method (and the impl itself).
232
228
let impl_m_own_bounds = impl_m_predicates. instantiate_own ( tcx, impl_to_placeholder_args) ;
233
229
for ( predicate, span) in impl_m_own_bounds {
234
230
let normalize_cause = traits:: ObligationCause :: misc ( span, impl_m_def_id) ;
@@ -1759,14 +1755,14 @@ fn compare_const_predicate_entailment<'tcx>(
1759
1755
// The predicates declared by the impl definition, the trait and the
1760
1756
// associated const in the trait are assumed.
1761
1757
let impl_predicates = tcx. predicates_of ( impl_ct_predicates. parent . unwrap ( ) ) ;
1762
- let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) ;
1763
- hybrid_preds. predicates . extend (
1758
+ let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) . predicates ;
1759
+ hybrid_preds. extend (
1764
1760
trait_ct_predicates
1765
1761
. instantiate_own ( tcx, trait_to_impl_args)
1766
1762
. map ( |( predicate, _) | predicate) ,
1767
1763
) ;
1768
1764
1769
- let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses ( & hybrid_preds. predicates ) , Reveal :: UserFacing ) ;
1765
+ let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses ( & hybrid_preds) , Reveal :: UserFacing ) ;
1770
1766
let param_env = traits:: normalize_param_env_or_error (
1771
1767
tcx,
1772
1768
param_env,
@@ -1892,8 +1888,8 @@ fn compare_type_predicate_entailment<'tcx>(
1892
1888
// The predicates declared by the impl definition, the trait and the
1893
1889
// associated type in the trait are assumed.
1894
1890
let impl_predicates = tcx. predicates_of ( impl_ty_predicates. parent . unwrap ( ) ) ;
1895
- let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) ;
1896
- hybrid_preds. predicates . extend (
1891
+ let mut hybrid_preds = impl_predicates. instantiate_identity ( tcx) . predicates ;
1892
+ hybrid_preds. extend (
1897
1893
trait_ty_predicates
1898
1894
. instantiate_own ( tcx, trait_to_impl_args)
1899
1895
. map ( |( predicate, _) | predicate) ,
@@ -1903,7 +1899,7 @@ fn compare_type_predicate_entailment<'tcx>(
1903
1899
1904
1900
let impl_ty_span = tcx. def_span ( impl_ty_def_id) ;
1905
1901
let normalize_cause = ObligationCause :: misc ( impl_ty_span, impl_ty_def_id) ;
1906
- let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses ( & hybrid_preds. predicates ) , Reveal :: UserFacing ) ;
1902
+ let param_env = ty:: ParamEnv :: new ( tcx. mk_clauses ( & hybrid_preds) , Reveal :: UserFacing ) ;
1907
1903
let param_env = traits:: normalize_param_env_or_error ( tcx, param_env, normalize_cause) ;
1908
1904
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
1909
1905
let ocx = ObligationCtxt :: new_with_diagnostics ( & infcx) ;
0 commit comments