@@ -194,24 +194,16 @@ fn compare_method_predicate_entailment<'tcx>(
194194 let impl_m_predicates = tcx. predicates_of ( impl_m. def_id ) ;
195195 let trait_m_predicates = tcx. predicates_of ( trait_m. def_id ) ;
196196
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-
207197 // This is the only tricky bit of the new way we check implementation methods
208198 // We need to build a set of predicates where only the method-level bounds
209199 // are from the trait and we assume all other bounds from the implementation
210200 // to be previously satisfied.
211201 //
212202 // We then register the obligations from the impl_m and check to see
213203 // 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 (
215207 trait_m_predicates
216208 . instantiate_own ( tcx, trait_to_placeholder_args)
217209 . map ( |( predicate, _) | predicate) ,
@@ -221,14 +213,18 @@ fn compare_method_predicate_entailment<'tcx>(
221213 // The key step here is to update the caller_bounds's predicates to be
222214 // the new hybrid bounds we computed.
223215 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 ) ;
225217 let param_env = traits:: normalize_param_env_or_error ( tcx, param_env, normalize_cause) ;
226218
227219 let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
228220 let ocx = ObligationCtxt :: new_with_diagnostics ( infcx) ;
229221
230222 debug ! ( "compare_impl_method: caller_bounds={:?}" , param_env. caller_bounds( ) ) ;
231223
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).
232228 let impl_m_own_bounds = impl_m_predicates. instantiate_own ( tcx, impl_to_placeholder_args) ;
233229 for ( predicate, span) in impl_m_own_bounds {
234230 let normalize_cause = traits:: ObligationCause :: misc ( span, impl_m_def_id) ;
@@ -1759,14 +1755,14 @@ fn compare_const_predicate_entailment<'tcx>(
17591755 // The predicates declared by the impl definition, the trait and the
17601756 // associated const in the trait are assumed.
17611757 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 (
17641760 trait_ct_predicates
17651761 . instantiate_own ( tcx, trait_to_impl_args)
17661762 . map ( |( predicate, _) | predicate) ,
17671763 ) ;
17681764
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 ) ;
17701766 let param_env = traits:: normalize_param_env_or_error (
17711767 tcx,
17721768 param_env,
@@ -1892,8 +1888,8 @@ fn compare_type_predicate_entailment<'tcx>(
18921888 // The predicates declared by the impl definition, the trait and the
18931889 // associated type in the trait are assumed.
18941890 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 (
18971893 trait_ty_predicates
18981894 . instantiate_own ( tcx, trait_to_impl_args)
18991895 . map ( |( predicate, _) | predicate) ,
@@ -1903,7 +1899,7 @@ fn compare_type_predicate_entailment<'tcx>(
19031899
19041900 let impl_ty_span = tcx. def_span ( impl_ty_def_id) ;
19051901 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 ) ;
19071903 let param_env = traits:: normalize_param_env_or_error ( tcx, param_env, normalize_cause) ;
19081904 let infcx = tcx. infer_ctxt ( ) . build ( ) ;
19091905 let ocx = ObligationCtxt :: new_with_diagnostics ( & infcx) ;
0 commit comments