Mark closures return via impl-trait as reachable.

This commit is contained in:
Michael Woerister 2017-08-14 12:04:52 +02:00
parent bae4fafdfb
commit f2df18579b
4 changed files with 16 additions and 0 deletions

View File

@ -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(_) |

View File

@ -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
};

View File

@ -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
}
}

View File

@ -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()();
}