@@ -14,6 +14,7 @@ use rustc::hir::def_id::DefId;
1414use rustc:: hir:: itemlikevisit:: ItemLikeVisitor ;
1515use rustc:: ty:: subst:: { Kind , Subst , UnpackedKind } ;
1616use rustc:: ty:: { self , Ty , TyCtxt } ;
17+ use rustc:: ty:: fold:: TypeFoldable ;
1718use rustc:: util:: nodemap:: FxHashMap ;
1819
1920use super :: explicit:: ExplicitPredicatesMap ;
@@ -245,6 +246,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
245246 }
246247}
247248
249+ #[ derive( Debug ) ]
248250pub struct IgnoreSelfTy ( bool ) ;
249251
250252/// We also have to check the explicit predicates
@@ -270,10 +272,18 @@ pub fn check_explicit_predicates<'tcx>(
270272 explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
271273 ignore_self_ty : IgnoreSelfTy ,
272274) {
273- debug ! ( "def_id = {:?}" , & def_id) ;
274- debug ! ( "substs = {:?}" , & substs) ;
275- debug ! ( "explicit_map = {:?}" , explicit_map) ;
276- debug ! ( "required_predicates = {:?}" , required_predicates) ;
275+ debug ! (
276+ "check_explicit_predicates(def_id={:?}, \
277+ substs={:?}, \
278+ explicit_map={:?}, \
279+ required_predicates={:?}, \
280+ ignore_self_ty={:?})",
281+ def_id,
282+ substs,
283+ explicit_map,
284+ required_predicates,
285+ ignore_self_ty,
286+ ) ;
277287 let explicit_predicates = explicit_map. explicit_predicates_of ( tcx, * def_id) ;
278288
279289 for outlives_predicate in explicit_predicates. iter ( ) {
@@ -302,13 +312,23 @@ pub fn check_explicit_predicates<'tcx>(
302312 //
303313 // Note that we do this check for self **before** applying `substs`. In the
304314 // case that `substs` come from a `dyn Trait` type, our caller will have
305- // included `Self = dyn Trait<'x, X> ` as the value for `Self`. If we were
315+ // included `Self = usize ` as the value for `Self`. If we were
306316 // to apply the substs, and not filter this predicate, we might then falsely
307317 // conclude that e.g. `X: 'x` was a reasonable inferred requirement.
308- if let UnpackedKind :: Type ( ty) = outlives_predicate. 0 . unpack ( ) {
309- if ty. is_self ( ) && ignore_self_ty. 0 {
310- debug ! ( "skipping self ty = {:?}" , & ty) ;
311- continue ;
318+ //
319+ // Another similar case is where we have a inferred
320+ // requirement like `<Self as Trait>::Foo: 'b`. We presently
321+ // ignore such requirements as well (cc #54467)-- though
322+ // conceivably it might be better if we could extract the `Foo
323+ // = X` binding from the object type (there must be such a
324+ // binding) and thus infer an outlives requirement that `X:
325+ // 'b`.
326+ if ignore_self_ty. 0 {
327+ if let UnpackedKind :: Type ( ty) = outlives_predicate. 0 . unpack ( ) {
328+ if ty. has_self_ty ( ) {
329+ debug ! ( "skipping self ty = {:?}" , & ty) ;
330+ continue ;
331+ }
312332 }
313333 }
314334
0 commit comments