Skip to content

Commit 9d5ec9e

Browse files
committed
work around fallout from these changes in rustc
1 parent f71de45 commit 9d5ec9e

File tree

8 files changed

+62
-21
lines changed

8 files changed

+62
-21
lines changed

src/librustc/infer/canonical.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use traits::{Obligation, ObligationCause, PredicateObligation};
4040
use ty::{self, CanonicalVar, Lift, Region, Slice, Ty, TyCtxt, TypeFlags};
4141
use ty::subst::{Kind, UnpackedKind};
4242
use ty::fold::{TypeFoldable, TypeFolder};
43+
use util::captures::Captures;
4344
use util::common::CellUsizeExt;
4445

4546
use rustc_data_structures::indexed_vec::IndexVec;
@@ -382,7 +383,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
382383
param_env: ty::ParamEnv<'tcx>,
383384
unsubstituted_region_constraints: &'a QueryRegionConstraints<'tcx>,
384385
result_subst: &'a CanonicalVarValues<'tcx>,
385-
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a {
386+
) -> impl Iterator<Item = PredicateObligation<'tcx>> + Captures<'gcx> + 'a {
386387
let QueryRegionConstraints {
387388
region_outlives,
388389
ty_outlives,

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub mod traits;
157157
pub mod ty;
158158

159159
pub mod util {
160+
pub mod captures;
160161
pub mod common;
161162
pub mod ppaux;
162163
pub mod nodemap;

src/librustc/traits/specialize/specialization_graph.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use ty::{self, TyCtxt, TypeFoldable};
1919
use ty::fast_reject::{self, SimplifiedType};
2020
use rustc_data_structures::sync::Lrc;
2121
use syntax::ast::Name;
22+
use util::captures::Captures;
2223
use util::nodemap::{DefIdMap, FxHashMap};
2324

2425
/// A per-trait graph of impls in specialization order. At the moment, this
@@ -313,9 +314,10 @@ impl<'a, 'gcx, 'tcx> Node {
313314
}
314315

315316
/// Iterate over the items defined directly by the given (impl or trait) node.
316-
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
317-
pub fn items(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>)
318-
-> impl Iterator<Item = ty::AssociatedItem> + 'a {
317+
pub fn items(
318+
&self,
319+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
320+
) -> impl Iterator<Item = ty::AssociatedItem> + 'a {
319321
tcx.associated_items(self.def_id())
320322
}
321323

@@ -367,9 +369,13 @@ impl<'a, 'gcx, 'tcx> Ancestors {
367369
/// Search the items from the given ancestors, returning each definition
368370
/// with the given name and the given kind.
369371
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
370-
pub fn defs(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, trait_item_name: Name,
371-
trait_item_kind: ty::AssociatedKind, trait_def_id: DefId)
372-
-> impl Iterator<Item = NodeItem<ty::AssociatedItem>> + 'a {
372+
pub fn defs(
373+
self,
374+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
375+
trait_item_name: Name,
376+
trait_item_kind: ty::AssociatedKind,
377+
trait_def_id: DefId,
378+
) -> impl Iterator<Item = NodeItem<ty::AssociatedItem>> + Captures<'gcx> + Captures<'tcx> + 'a {
373379
self.flat_map(move |node| {
374380
node.items(tcx).filter(move |impl_item| {
375381
impl_item.kind == trait_item_kind &&

src/librustc/ty/mod.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use ty;
3434
use ty::subst::{Subst, Substs};
3535
use ty::util::{IntTypeExt, Discr};
3636
use ty::walk::TypeWalker;
37+
use util::captures::Captures;
3738
use util::nodemap::{NodeSet, DefIdMap, FxHashMap};
3839

3940
use serialize::{self, Encodable, Encoder};
@@ -1942,8 +1943,10 @@ impl<'a, 'gcx, 'tcx> AdtDef {
19421943
}
19431944

19441945
#[inline]
1945-
pub fn discriminants(&'a self, tcx: TyCtxt<'a, 'gcx, 'tcx>)
1946-
-> impl Iterator<Item=Discr<'tcx>> + 'a {
1946+
pub fn discriminants(
1947+
&'a self,
1948+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
1949+
) -> impl Iterator<Item=Discr<'tcx>> + Captures<'gcx> + 'a {
19471950
let repr_type = self.repr.discr_type();
19481951
let initial = repr_type.initial_discriminant(tcx.global_tcx());
19491952
let mut prev_discr = None::<Discr<'tcx>>;
@@ -2290,7 +2293,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22902293
/// Returns an iterator of the def-ids for all body-owners in this
22912294
/// crate. If you would prefer to iterate over the bodies
22922295
/// themselves, you can do `self.hir.krate().body_ids.iter()`.
2293-
pub fn body_owners(self) -> impl Iterator<Item = DefId> + 'a {
2296+
pub fn body_owners(
2297+
self,
2298+
) -> impl Iterator<Item = DefId> + Captures<'tcx> + Captures<'gcx> + 'a {
22942299
self.hir.krate()
22952300
.body_ids
22962301
.iter()
@@ -2394,11 +2399,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23942399
}
23952400
}
23962401

2397-
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
2398-
pub fn associated_items(self, def_id: DefId)
2399-
-> impl Iterator<Item = ty::AssociatedItem> + 'a {
2402+
pub fn associated_items(
2403+
self,
2404+
def_id: DefId,
2405+
) -> impl Iterator<Item = ty::AssociatedItem> + 'a {
24002406
let def_ids = self.associated_item_def_ids(def_id);
2401-
(0..def_ids.len()).map(move |i| self.associated_item(def_ids[i]))
2407+
Box::new((0..def_ids.len()).map(move |i| self.associated_item(def_ids[i])))
2408+
as Box<dyn Iterator<Item = ty::AssociatedItem> + 'a>
24022409
}
24032410

24042411
/// Returns true if the impls are the same polarity and are implementing

src/librustc/ty/sty.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_data_structures::indexed_vec::Idx;
1818
use ty::subst::{Substs, Subst, Kind, UnpackedKind};
1919
use ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable};
2020
use ty::{Slice, TyS};
21+
use util::captures::Captures;
2122

2223
use std::iter;
2324
use std::cmp::Ordering;
@@ -384,9 +385,11 @@ impl<'a, 'gcx, 'tcx> ClosureSubsts<'tcx> {
384385
/// This returns the types of the MIR locals which had to be stored across suspension points.
385386
/// It is calculated in rustc_mir::transform::generator::StateTransform.
386387
/// All the types here must be in the tuple in GeneratorInterior.
387-
pub fn state_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) ->
388-
impl Iterator<Item=Ty<'tcx>> + 'a
389-
{
388+
pub fn state_tys(
389+
self,
390+
def_id: DefId,
391+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
392+
) -> impl Iterator<Item=Ty<'tcx>> + Captures<'gcx> + 'a {
390393
let state = tcx.generator_layout(def_id).fields.iter();
391394
state.map(move |d| d.ty.subst(tcx, self.substs))
392395
}
@@ -403,7 +406,7 @@ impl<'a, 'gcx, 'tcx> ClosureSubsts<'tcx> {
403406
/// This is the types of all the fields stored in a generator.
404407
/// It includes the upvars, state types and the state discriminant which is u32.
405408
pub fn field_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) ->
406-
impl Iterator<Item=Ty<'tcx>> + 'a
409+
impl Iterator<Item=Ty<'tcx>> + Captures<'gcx> + 'a
407410
{
408411
self.pre_transforms_tys(def_id, tcx).chain(self.state_tys(def_id, tcx))
409412
}

src/librustc/util/captures.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
/// "Signaling" trait used in impl trait to tag lifetimes that you may
12+
/// need to capture but don't really need for other reasons.
13+
/// Basically a workaround; see [this comment] for details.
14+
///
15+
/// [this comment]: https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
16+
pub trait Captures<'a> { }
17+
18+
impl<'a, T: ?Sized> Captures<'a> for T { }

src/librustc_metadata/decoder.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc::session::Session;
2929
use rustc::ty::{self, Ty, TyCtxt};
3030
use rustc::ty::codec::TyDecoder;
3131
use rustc::mir::Mir;
32+
use rustc::util::captures::Captures;
3233
use rustc::util::nodemap::FxHashMap;
3334

3435
use std::collections::BTreeMap;
@@ -146,7 +147,10 @@ impl<'a, 'tcx: 'a, T: Decodable> Lazy<T> {
146147
}
147148

148149
impl<'a, 'tcx: 'a, T: Decodable> LazySeq<T> {
149-
pub fn decode<M: Metadata<'a, 'tcx>>(self, meta: M) -> impl Iterator<Item = T> + 'a {
150+
pub fn decode<M: Metadata<'a, 'tcx>>(
151+
self,
152+
meta: M,
153+
) -> impl Iterator<Item = T> + Captures<'tcx> + 'a {
150154
let mut dcx = meta.decoder(self.position);
151155
dcx.lazy_state = LazyState::NodeStart(self.position);
152156
(0..self.len).map(move |_| T::decode(&mut dcx).unwrap())

src/librustc_typeck/collect.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ use rustc::ty::{ToPredicate, ReprOptions};
3535
use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
3636
use rustc::ty::maps::Providers;
3737
use rustc::ty::util::IntTypeExt;
38-
use rustc::util::nodemap::{FxHashSet, FxHashMap};
3938
use rustc::ty::util::Discr;
39+
use rustc::util::captures::Captures;
40+
use rustc::util::nodemap::{FxHashSet, FxHashMap};
4041

4142
use syntax::{abi, ast};
4243
use syntax::ast::MetaItemKind;
@@ -1281,7 +1282,7 @@ fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
12811282
fn early_bound_lifetimes_from_generics<'a, 'tcx>(
12821283
tcx: TyCtxt<'a, 'tcx, 'tcx>,
12831284
ast_generics: &'a hir::Generics)
1284-
-> impl Iterator<Item=&'a hir::LifetimeDef>
1285+
-> impl Iterator<Item=&'a hir::LifetimeDef> + Captures<'tcx>
12851286
{
12861287
ast_generics
12871288
.lifetimes()

0 commit comments

Comments
 (0)