]> git.lizzy.rs Git - rust.git/commitdiff
fix for late-bound regions
authortoidiu <apoorv@toidiu.com>
Fri, 17 Aug 2018 00:12:28 +0000 (20:12 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 23 Aug 2018 18:35:59 +0000 (14:35 -0400)
src/librustc_typeck/outlives/implicit_infer.rs
src/librustc_typeck/outlives/mod.rs
src/test/ui/issue-53419.rs [new file with mode: 0644]

index ec36fa0fbc14531572d1a1b8a5cc1ea3313b8782..8ab9686f6f834b8e7020d1b824e5e456d877f427 100644 (file)
@@ -12,7 +12,7 @@
 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,
+                        );
+                    }
                 }
             }
 
index 74ef62e0c63c6633a8dc542932974b8990b1cf8b..1b6d51d2b02806d74a73e57b6b5cabe2c67b04fa 100644 (file)
@@ -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 (file)
index 0000000..e4ade1b
--- /dev/null
@@ -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() {
+}
+