Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark closures returned via impl-trait as reachable. #43857

Merged
merged 1 commit into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) |
Expand Down
1 change: 1 addition & 0 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
11 changes: 11 additions & 0 deletions src/test/run-pass/impl-trait/auxiliary/xcrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
1 change: 1 addition & 0 deletions src/test/run-pass/impl-trait/xcrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()();
}