diff options
| author | bors <bors@rust-lang.org> | 2017-08-14 11:28:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-08-14 11:28:12 +0000 |
| commit | d49b730157c83ac3b1502a0127f199607b06a174 (patch) | |
| tree | e5a72eb86963a2407b730e333c4f98ea87539b53 /src | |
| parent | b1ff235490917e7cd351398d72557b3205474135 (diff) | |
| parent | f2df18579b139216f15a2ea17e27bb980f02a0ab (diff) | |
Auto merge of #43857 - michaelwoerister:fix-impl-trait-closure-vis, r=eddyb
Mark closures return via impl-trait as reachable. This should fix some of the open `impl trait` issues, like #40839, #43135, and #35870. r? @eddyb
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/reachable.rs | 3 | ||||
| -rw-r--r-- | src/librustc_privacy/lib.rs | 1 | ||||
| -rw-r--r-- | src/test/run-pass/impl-trait/auxiliary/xcrate.rs | 11 | ||||
| -rw-r--r-- | src/test/run-pass/impl-trait/xcrate.rs | 1 |
4 files changed, 16 insertions, 0 deletions
diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index df828c8d8e7..4a608c69d14 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -296,6 +296,9 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { hir::ImplItemKind::Type(_) => {} } } + hir_map::NodeExpr(&hir::Expr { node: hir::ExprClosure(.., body, _), .. }) => { + self.visit_nested_body(body); + } // Nothing to recurse on for these hir_map::NodeForeignItem(_) | hir_map::NodeVariant(_) | diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 9fa5fea20d9..81cf22e3b37 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -448,6 +448,7 @@ impl<'b, 'a, 'tcx> TypeVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'b ty::TyDynamic(ref obj, ..) => obj.principal().map(|p| p.def_id()), ty::TyProjection(ref proj) => Some(proj.item_def_id), ty::TyFnDef(def_id, ..) | + ty::TyClosure(def_id, ..) | ty::TyAnon(def_id, _) => Some(def_id), _ => None }; diff --git a/src/test/run-pass/impl-trait/auxiliary/xcrate.rs b/src/test/run-pass/impl-trait/auxiliary/xcrate.rs index be353f6d563..e9074f8c230 100644 --- a/src/test/run-pass/impl-trait/auxiliary/xcrate.rs +++ b/src/test/run-pass/impl-trait/auxiliary/xcrate.rs @@ -13,3 +13,14 @@ pub fn fourway_add(a: i32) -> impl Fn(i32) -> impl Fn(i32) -> impl Fn(i32) -> i32 { move |b| move |c| move |d| a + b + c + d } + +fn some_internal_fn() -> u32 { + 1 +} + +// See #40839 +pub fn return_closure_accessing_internal_fn() -> impl Fn() -> u32 { + || { + some_internal_fn() + 1 + } +} diff --git a/src/test/run-pass/impl-trait/xcrate.rs b/src/test/run-pass/impl-trait/xcrate.rs index fe3ed7b3465..6d00c46fa35 100644 --- a/src/test/run-pass/impl-trait/xcrate.rs +++ b/src/test/run-pass/impl-trait/xcrate.rs @@ -14,4 +14,5 @@ extern crate xcrate; fn main() { assert_eq!(xcrate::fourway_add(1)(2)(3)(4), 10); + xcrate::return_closure_accessing_internal_fn()(); } |
