Skip to content

Commit f2df185

Browse files
Mark closures return via impl-trait as reachable.
1 parent bae4faf commit f2df185

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

src/librustc/middle/reachable.rs

+3
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
296296
hir::ImplItemKind::Type(_) => {}
297297
}
298298
}
299+
hir_map::NodeExpr(&hir::Expr { node: hir::ExprClosure(.., body, _), .. }) => {
300+
self.visit_nested_body(body);
301+
}
299302
// Nothing to recurse on for these
300303
hir_map::NodeForeignItem(_) |
301304
hir_map::NodeVariant(_) |

src/librustc_privacy/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ impl<'b, 'a, 'tcx> TypeVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'b
448448
ty::TyDynamic(ref obj, ..) => obj.principal().map(|p| p.def_id()),
449449
ty::TyProjection(ref proj) => Some(proj.item_def_id),
450450
ty::TyFnDef(def_id, ..) |
451+
ty::TyClosure(def_id, ..) |
451452
ty::TyAnon(def_id, _) => Some(def_id),
452453
_ => None
453454
};

src/test/run-pass/impl-trait/auxiliary/xcrate.rs

+11
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,14 @@
1313
pub fn fourway_add(a: i32) -> impl Fn(i32) -> impl Fn(i32) -> impl Fn(i32) -> i32 {
1414
move |b| move |c| move |d| a + b + c + d
1515
}
16+
17+
fn some_internal_fn() -> u32 {
18+
1
19+
}
20+
21+
// See #40839
22+
pub fn return_closure_accessing_internal_fn() -> impl Fn() -> u32 {
23+
|| {
24+
some_internal_fn() + 1
25+
}
26+
}

src/test/run-pass/impl-trait/xcrate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ extern crate xcrate;
1414

1515
fn main() {
1616
assert_eq!(xcrate::fourway_add(1)(2)(3)(4), 10);
17+
xcrate::return_closure_accessing_internal_fn()();
1718
}

0 commit comments

Comments
 (0)