diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index ec36fa0fbc1..8ab9686f6f8 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -12,7 +12,7 @@ use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::subst::{Kind, Subst, UnpackedKind}; -use rustc::ty::{self, Ty, TyCtxt}; +use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc::util::nodemap::FxHashMap; use super::explicit::ExplicitPredicatesMap; @@ -208,14 +208,26 @@ fn insert_required_predicates_to_be_wf<'tcx>( debug!("field_ty = {}", &field_ty); debug!("ty in field = {}", &ty); if let Some(ex_trait_ref) = obj.principal() { - check_explicit_predicates( - tcx, - &ex_trait_ref.skip_binder().def_id, - ex_trait_ref.with_self_ty(tcx, ty).skip_binder().substs, - required_predicates, - explicit_map, - true, - ); + // The method `has_escaping_regions` checks if + // there are any late-bound regions, which is + // the lifetime `'r`. It is safe to ignore + // these since `'r` is not in scope for `Foo`. + // + // ``` + // struct Foo { + // bar: for<'r> Fn(usize, &'r FnMut()) + // } + // ``` + if !ty.has_escaping_regions() { + check_explicit_predicates( + tcx, + &ex_trait_ref.skip_binder().def_id, + ex_trait_ref.with_self_ty(tcx, ty).skip_binder().substs, + required_predicates, + explicit_map, + true, + ); + } } } diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index 74ef62e0c63..1b6d51d2b02 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -59,8 +59,7 @@ fn inferred_outlives_of<'a, 'tcx>( ty::Predicate::TypeOutlives(p) => p.to_string(), err => bug!("unexpected predicate {:?}", err), - }) - .collect(); + }).collect(); pred.sort(); let span = tcx.def_span(item_def_id); @@ -117,11 +116,9 @@ fn inferred_outlives_crate<'tcx>( ty::Binder::bind(ty::OutlivesPredicate(region1, region2)), ), }, - ) - .collect(); + ).collect(); (def_id, Lrc::new(vec)) - }) - .collect(); + }).collect(); let empty_predicate = Lrc::new(Vec::new()); diff --git a/src/test/ui/issue-53419.rs b/src/test/ui/issue-53419.rs new file mode 100644 index 00000000000..e4ade1b6323 --- /dev/null +++ b/src/test/ui/issue-53419.rs @@ -0,0 +1,21 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//compile-pass + +#![feature(infer_outlives_requirements)] + +struct Foo { + bar: for<'r> Fn(usize, &'r FnMut()) +} + +fn main() { +} +