diff options
| author | toidiu <apoorv@toidiu.com> | 2018-08-16 20:12:28 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-08-23 14:35:59 -0400 |
| commit | 3860eabbb64d2b53b1a05bd4dba96ac7751441f3 (patch) | |
| tree | 3692c1cfe740a702b294457e2925eb618ba5fe47 | |
| parent | e5284b0b57275cb18618ef1532ee7f07c32a1e18 (diff) | |
| download | rust-3860eabbb64d2b53b1a05bd4dba96ac7751441f3.tar.gz rust-3860eabbb64d2b53b1a05bd4dba96ac7751441f3.zip | |
fix for late-bound regions
| -rw-r--r-- | src/librustc_typeck/outlives/implicit_infer.rs | 30 | ||||
| -rw-r--r-- | src/librustc_typeck/outlives/mod.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/issue-53419.rs | 21 |
3 files changed, 45 insertions, 15 deletions
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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() { +} + |
