work around fallout from these changes in rustc

This commit is contained in:
Niko Matsakis 2018-03-15 16:17:27 -04:00
parent f71de45b23
commit 9d5ec9ef1a
8 changed files with 62 additions and 21 deletions

View File

@ -40,6 +40,7 @@ use traits::{Obligation, ObligationCause, PredicateObligation};
use ty::{self, CanonicalVar, Lift, Region, Slice, Ty, TyCtxt, TypeFlags};
use ty::subst::{Kind, UnpackedKind};
use ty::fold::{TypeFoldable, TypeFolder};
use util::captures::Captures;
use util::common::CellUsizeExt;
use rustc_data_structures::indexed_vec::IndexVec;
@ -382,7 +383,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
unsubstituted_region_constraints: &'a QueryRegionConstraints<'tcx>,
result_subst: &'a CanonicalVarValues<'tcx>,
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a {
) -> impl Iterator<Item = PredicateObligation<'tcx>> + Captures<'gcx> + 'a {
let QueryRegionConstraints {
region_outlives,
ty_outlives,

View File

@ -157,6 +157,7 @@ pub mod traits;
pub mod ty;
pub mod util {
pub mod captures;
pub mod common;
pub mod ppaux;
pub mod nodemap;

View File

@ -19,6 +19,7 @@ use ty::{self, TyCtxt, TypeFoldable};
use ty::fast_reject::{self, SimplifiedType};
use rustc_data_structures::sync::Lrc;
use syntax::ast::Name;
use util::captures::Captures;
use util::nodemap::{DefIdMap, FxHashMap};
/// A per-trait graph of impls in specialization order. At the moment, this
@ -313,9 +314,10 @@ impl<'a, 'gcx, 'tcx> Node {
}
/// Iterate over the items defined directly by the given (impl or trait) node.
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
pub fn items(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>)
-> impl Iterator<Item = ty::AssociatedItem> + 'a {
pub fn items(
&self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
) -> impl Iterator<Item = ty::AssociatedItem> + 'a {
tcx.associated_items(self.def_id())
}
@ -367,9 +369,13 @@ impl<'a, 'gcx, 'tcx> Ancestors {
/// Search the items from the given ancestors, returning each definition
/// with the given name and the given kind.
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
pub fn defs(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, trait_item_name: Name,
trait_item_kind: ty::AssociatedKind, trait_def_id: DefId)
-> impl Iterator<Item = NodeItem<ty::AssociatedItem>> + 'a {
pub fn defs(
self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
trait_item_name: Name,
trait_item_kind: ty::AssociatedKind,
trait_def_id: DefId,
) -> impl Iterator<Item = NodeItem<ty::AssociatedItem>> + Captures<'gcx> + Captures<'tcx> + 'a {
self.flat_map(move |node| {
node.items(tcx).filter(move |impl_item| {
impl_item.kind == trait_item_kind &&

View File

@ -34,6 +34,7 @@ use ty;
use ty::subst::{Subst, Substs};
use ty::util::{IntTypeExt, Discr};
use ty::walk::TypeWalker;
use util::captures::Captures;
use util::nodemap::{NodeSet, DefIdMap, FxHashMap};
use serialize::{self, Encodable, Encoder};
@ -1942,8 +1943,10 @@ impl<'a, 'gcx, 'tcx> AdtDef {
}
#[inline]
pub fn discriminants(&'a self, tcx: TyCtxt<'a, 'gcx, 'tcx>)
-> impl Iterator<Item=Discr<'tcx>> + 'a {
pub fn discriminants(
&'a self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
) -> impl Iterator<Item=Discr<'tcx>> + Captures<'gcx> + 'a {
let repr_type = self.repr.discr_type();
let initial = repr_type.initial_discriminant(tcx.global_tcx());
let mut prev_discr = None::<Discr<'tcx>>;
@ -2290,7 +2293,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
/// Returns an iterator of the def-ids for all body-owners in this
/// crate. If you would prefer to iterate over the bodies
/// themselves, you can do `self.hir.krate().body_ids.iter()`.
pub fn body_owners(self) -> impl Iterator<Item = DefId> + 'a {
pub fn body_owners(
self,
) -> impl Iterator<Item = DefId> + Captures<'tcx> + Captures<'gcx> + 'a {
self.hir.krate()
.body_ids
.iter()
@ -2394,11 +2399,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
}
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
pub fn associated_items(self, def_id: DefId)
-> impl Iterator<Item = ty::AssociatedItem> + 'a {
pub fn associated_items(
self,
def_id: DefId,
) -> impl Iterator<Item = ty::AssociatedItem> + 'a {
let def_ids = self.associated_item_def_ids(def_id);
(0..def_ids.len()).map(move |i| self.associated_item(def_ids[i]))
Box::new((0..def_ids.len()).map(move |i| self.associated_item(def_ids[i])))
as Box<dyn Iterator<Item = ty::AssociatedItem> + 'a>
}
/// Returns true if the impls are the same polarity and are implementing

View File

@ -18,6 +18,7 @@ use rustc_data_structures::indexed_vec::Idx;
use ty::subst::{Substs, Subst, Kind, UnpackedKind};
use ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable};
use ty::{Slice, TyS};
use util::captures::Captures;
use std::iter;
use std::cmp::Ordering;
@ -384,9 +385,11 @@ impl<'a, 'gcx, 'tcx> ClosureSubsts<'tcx> {
/// This returns the types of the MIR locals which had to be stored across suspension points.
/// It is calculated in rustc_mir::transform::generator::StateTransform.
/// All the types here must be in the tuple in GeneratorInterior.
pub fn state_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) ->
impl Iterator<Item=Ty<'tcx>> + 'a
{
pub fn state_tys(
self,
def_id: DefId,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
) -> impl Iterator<Item=Ty<'tcx>> + Captures<'gcx> + 'a {
let state = tcx.generator_layout(def_id).fields.iter();
state.map(move |d| d.ty.subst(tcx, self.substs))
}
@ -403,7 +406,7 @@ impl<'a, 'gcx, 'tcx> ClosureSubsts<'tcx> {
/// This is the types of all the fields stored in a generator.
/// It includes the upvars, state types and the state discriminant which is u32.
pub fn field_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) ->
impl Iterator<Item=Ty<'tcx>> + 'a
impl Iterator<Item=Ty<'tcx>> + Captures<'gcx> + 'a
{
self.pre_transforms_tys(def_id, tcx).chain(self.state_tys(def_id, tcx))
}

View File

@ -0,0 +1,18 @@
// Copyright 2012-2014 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/// "Signaling" trait used in impl trait to tag lifetimes that you may
/// need to capture but don't really need for other reasons.
/// Basically a workaround; see [this comment] for details.
///
/// [this comment]: https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
pub trait Captures<'a> { }
impl<'a, T: ?Sized> Captures<'a> for T { }

View File

@ -29,6 +29,7 @@ use rustc::session::Session;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::codec::TyDecoder;
use rustc::mir::Mir;
use rustc::util::captures::Captures;
use rustc::util::nodemap::FxHashMap;
use std::collections::BTreeMap;
@ -146,7 +147,10 @@ impl<'a, 'tcx: 'a, T: Decodable> Lazy<T> {
}
impl<'a, 'tcx: 'a, T: Decodable> LazySeq<T> {
pub fn decode<M: Metadata<'a, 'tcx>>(self, meta: M) -> impl Iterator<Item = T> + 'a {
pub fn decode<M: Metadata<'a, 'tcx>>(
self,
meta: M,
) -> impl Iterator<Item = T> + Captures<'tcx> + 'a {
let mut dcx = meta.decoder(self.position);
dcx.lazy_state = LazyState::NodeStart(self.position);
(0..self.len).map(move |_| T::decode(&mut dcx).unwrap())

View File

@ -35,8 +35,9 @@ use rustc::ty::{ToPredicate, ReprOptions};
use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
use rustc::ty::maps::Providers;
use rustc::ty::util::IntTypeExt;
use rustc::util::nodemap::{FxHashSet, FxHashMap};
use rustc::ty::util::Discr;
use rustc::util::captures::Captures;
use rustc::util::nodemap::{FxHashSet, FxHashMap};
use syntax::{abi, ast};
use syntax::ast::MetaItemKind;
@ -1281,7 +1282,7 @@ fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
fn early_bound_lifetimes_from_generics<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
ast_generics: &'a hir::Generics)
-> impl Iterator<Item=&'a hir::LifetimeDef>
-> impl Iterator<Item=&'a hir::LifetimeDef> + Captures<'tcx>
{
ast_generics
.lifetimes()