From 41d3e8318331ce5c947ee8700e2e70dbd12a8125 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 30 Aug 2017 17:32:21 -0700 Subject: [PATCH] rustc: Fix reachability with cross-crate generators Same solution as in f2df1857 Closes #44181 --- src/librustc_privacy/lib.rs | 1 + .../generator/auxiliary/xcrate-reachable.rs | 24 +++++++++++++++++++ .../run-pass/generator/xcrate-reachable.rs | 21 ++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/test/run-pass/generator/auxiliary/xcrate-reachable.rs create mode 100644 src/test/run-pass/generator/xcrate-reachable.rs diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index e34b0927f67..92c4f9ab25f 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -446,6 +446,7 @@ impl<'b, 'a, 'tcx> TypeVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'b ty::TyProjection(ref proj) => Some(proj.item_def_id), ty::TyFnDef(def_id, ..) | ty::TyClosure(def_id, ..) | + ty::TyGenerator(def_id, ..) | ty::TyAnon(def_id, _) => Some(def_id), _ => None }; diff --git a/src/test/run-pass/generator/auxiliary/xcrate-reachable.rs b/src/test/run-pass/generator/auxiliary/xcrate-reachable.rs new file mode 100644 index 00000000000..a6a2a2d081e --- /dev/null +++ b/src/test/run-pass/generator/auxiliary/xcrate-reachable.rs @@ -0,0 +1,24 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(conservative_impl_trait, generators, generator_trait)] + +use std::ops::Generator; + +fn msg() -> u32 { + 0 +} + +pub fn foo() -> impl Generator { + || { + yield; + return msg(); + } +} diff --git a/src/test/run-pass/generator/xcrate-reachable.rs b/src/test/run-pass/generator/xcrate-reachable.rs new file mode 100644 index 00000000000..dff5e08b9c2 --- /dev/null +++ b/src/test/run-pass/generator/xcrate-reachable.rs @@ -0,0 +1,21 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:xcrate-reachable.rs + +#![feature(conservative_impl_trait, generator_trait)] + +extern crate xcrate_reachable as foo; + +use std::ops::Generator; + +fn main() { + foo::foo().resume(); +}