Replace exist_ty and ExistTy with opaque_ty and OpaqueTy

This commit is contained in:
varkor 2019-08-02 00:08:05 +01:00
parent 2777386dc2
commit b4fe555796
11 changed files with 79 additions and 79 deletions

View File

@ -505,7 +505,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
visitor.visit_ty(ty);
visitor.visit_generics(generics)
}
ItemKind::OpaqueTy(ExistTy {
ItemKind::OpaqueTy(OpaqueTy {
ref generics,
ref bounds,
..

View File

@ -1721,7 +1721,7 @@ impl<'a> LoweringContext<'a> {
&mut self,
span: Span,
fn_def_id: Option<DefId>,
exist_ty_node_id: NodeId,
opaque_ty_node_id: NodeId,
lower_bounds: impl FnOnce(&mut LoweringContext<'_>) -> hir::GenericBounds,
) -> hir::TyKind {
// Make sure we know that some funky desugaring has been going on here.
@ -1729,30 +1729,30 @@ impl<'a> LoweringContext<'a> {
// desugaring that explicitly states that we don't want to track that.
// Not tracking it makes lints in rustc and clippy very fragile, as
// frequently opened issues show.
let exist_ty_span = self.mark_span_with_reason(
let opaque_ty_span = self.mark_span_with_reason(
DesugaringKind::OpaqueTy,
span,
None,
);
let exist_ty_def_index = self
let opaque_ty_def_index = self
.resolver
.definitions()
.opt_def_index(exist_ty_node_id)
.opt_def_index(opaque_ty_node_id)
.unwrap();
self.allocate_hir_id_counter(exist_ty_node_id);
self.allocate_hir_id_counter(opaque_ty_node_id);
let hir_bounds = self.with_hir_id_owner(exist_ty_node_id, lower_bounds);
let hir_bounds = self.with_hir_id_owner(opaque_ty_node_id, lower_bounds);
let (lifetimes, lifetime_defs) = self.lifetimes_from_impl_trait_bounds(
exist_ty_node_id,
exist_ty_def_index,
opaque_ty_node_id,
opaque_ty_def_index,
&hir_bounds,
);
self.with_hir_id_owner(exist_ty_node_id, |lctx| {
let exist_ty_item = hir::ExistTy {
self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
let opaque_ty_item = hir::OpaqueTy {
generics: hir::Generics {
params: lifetime_defs,
where_clause: hir::WhereClause {
@ -1766,16 +1766,16 @@ impl<'a> LoweringContext<'a> {
origin: hir::OpaqueTyOrigin::ReturnImplTrait,
};
trace!("exist ty from impl trait def-index: {:#?}", exist_ty_def_index);
let exist_ty_id = lctx.generate_opaque_type(
exist_ty_node_id,
exist_ty_item,
trace!("exist ty from impl trait def-index: {:#?}", opaque_ty_def_index);
let opaque_ty_id = lctx.generate_opaque_type(
opaque_ty_node_id,
opaque_ty_item,
span,
exist_ty_span,
opaque_ty_span,
);
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`.
hir::TyKind::Def(hir::ItemId { id: exist_ty_id }, lifetimes)
hir::TyKind::Def(hir::ItemId { id: opaque_ty_id }, lifetimes)
})
}
@ -1783,34 +1783,34 @@ impl<'a> LoweringContext<'a> {
/// returns the lowered node-ID for the opaque type.
fn generate_opaque_type(
&mut self,
exist_ty_node_id: NodeId,
exist_ty_item: hir::ExistTy,
opaque_ty_node_id: NodeId,
opaque_ty_item: hir::OpaqueTy,
span: Span,
exist_ty_span: Span,
opaque_ty_span: Span,
) -> hir::HirId {
let exist_ty_item_kind = hir::ItemKind::OpaqueTy(exist_ty_item);
let exist_ty_id = self.lower_node_id(exist_ty_node_id);
let opaque_ty_item_kind = hir::ItemKind::OpaqueTy(opaque_ty_item);
let opaque_ty_id = self.lower_node_id(opaque_ty_node_id);
// Generate an `type Foo = impl Trait;` declaration.
trace!("registering opaque type with id {:#?}", exist_ty_id);
let exist_ty_item = hir::Item {
hir_id: exist_ty_id,
trace!("registering opaque type with id {:#?}", opaque_ty_id);
let opaque_ty_item = hir::Item {
hir_id: opaque_ty_id,
ident: Ident::invalid(),
attrs: Default::default(),
node: exist_ty_item_kind,
node: opaque_ty_item_kind,
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
span: exist_ty_span,
span: opaque_ty_span,
};
// Insert the item into the global item list. This usually happens
// automatically for all AST items. But this opaque type item
// does not actually exist in the AST.
self.insert_item(exist_ty_item);
exist_ty_id
self.insert_item(opaque_ty_item);
opaque_ty_id
}
fn lifetimes_from_impl_trait_bounds(
&mut self,
exist_ty_id: NodeId,
opaque_ty_id: NodeId,
parent_index: DefIndex,
bounds: &hir::GenericBounds,
) -> (HirVec<hir::GenericArg>, HirVec<hir::GenericParam>) {
@ -1820,7 +1820,7 @@ impl<'a> LoweringContext<'a> {
struct ImplTraitLifetimeCollector<'r, 'a> {
context: &'r mut LoweringContext<'a>,
parent: DefIndex,
exist_ty_id: NodeId,
opaque_ty_id: NodeId,
collect_elided_lifetimes: bool,
currently_bound_lifetimes: Vec<hir::LifetimeName>,
already_defined_lifetimes: FxHashSet<hir::LifetimeName>,
@ -1916,7 +1916,7 @@ impl<'a> LoweringContext<'a> {
let def_node_id = self.context.sess.next_node_id();
let hir_id =
self.context.lower_node_id_with_owner(def_node_id, self.exist_ty_id);
self.context.lower_node_id_with_owner(def_node_id, self.opaque_ty_id);
self.context.resolver.definitions().create_def_with_parent(
self.parent,
def_node_id,
@ -1952,7 +1952,7 @@ impl<'a> LoweringContext<'a> {
let mut lifetime_collector = ImplTraitLifetimeCollector {
context: self,
parent: parent_index,
exist_ty_id,
opaque_ty_id,
collect_elided_lifetimes: true,
currently_bound_lifetimes: Vec::new(),
already_defined_lifetimes: FxHashSet::default(),
@ -2582,40 +2582,40 @@ impl<'a> LoweringContext<'a> {
})
}
// Transforms `-> T` for `async fn` into `-> ExistTy { .. }`
// combined with the following definition of `ExistTy`:
// Transforms `-> T` for `async fn` into `-> OpaqueTy { .. }`
// combined with the following definition of `OpaqueTy`:
//
// type ExistTy<generics_from_parent_fn> = impl Future<Output = T>;
// type OpaqueTy<generics_from_parent_fn> = impl Future<Output = T>;
//
// `inputs`: lowered types of arguments to the function (used to collect lifetimes)
// `output`: unlowered output type (`T` in `-> T`)
// `fn_def_id`: `DefId` of the parent function (used to create child impl trait definition)
// `exist_ty_node_id`: `NodeId` of the opaque `impl Trait` type that should be created
// `opaque_ty_node_id`: `NodeId` of the opaque `impl Trait` type that should be created
// `elided_lt_replacement`: replacement for elided lifetimes in the return type
fn lower_async_fn_ret_ty(
&mut self,
output: &FunctionRetTy,
fn_def_id: DefId,
exist_ty_node_id: NodeId,
opaque_ty_node_id: NodeId,
elided_lt_replacement: LtReplacement,
) -> hir::FunctionRetTy {
let span = output.span();
let exist_ty_span = self.mark_span_with_reason(
let opaque_ty_span = self.mark_span_with_reason(
DesugaringKind::Async,
span,
None,
);
let exist_ty_def_index = self
let opaque_ty_def_index = self
.resolver
.definitions()
.opt_def_index(exist_ty_node_id)
.opt_def_index(opaque_ty_node_id)
.unwrap();
self.allocate_hir_id_counter(exist_ty_node_id);
self.allocate_hir_id_counter(opaque_ty_node_id);
let (exist_ty_id, lifetime_params) = self.with_hir_id_owner(exist_ty_node_id, |this| {
let (opaque_ty_id, lifetime_params) = self.with_hir_id_owner(opaque_ty_node_id, |this| {
let future_bound = this.with_anonymous_lifetime_mode(
AnonymousLifetimeMode::Replace(elided_lt_replacement),
|this| this.lower_async_fn_output_type_to_future_bound(
@ -2642,11 +2642,11 @@ impl<'a> LoweringContext<'a> {
lifetime_params
.iter().cloned()
.map(|(span, hir_name)| {
this.lifetime_to_generic_param(span, hir_name, exist_ty_def_index)
this.lifetime_to_generic_param(span, hir_name, opaque_ty_def_index)
})
.collect();
let exist_ty_item = hir::ExistTy {
let opaque_ty_item = hir::OpaqueTy {
generics: hir::Generics {
params: generic_params,
where_clause: hir::WhereClause {
@ -2660,15 +2660,15 @@ impl<'a> LoweringContext<'a> {
origin: hir::OpaqueTyOrigin::AsyncFn,
};
trace!("exist ty from async fn def index: {:#?}", exist_ty_def_index);
let exist_ty_id = this.generate_opaque_type(
exist_ty_node_id,
exist_ty_item,
trace!("exist ty from async fn def index: {:#?}", opaque_ty_def_index);
let opaque_ty_id = this.generate_opaque_type(
opaque_ty_node_id,
opaque_ty_item,
span,
exist_ty_span,
opaque_ty_span,
);
(exist_ty_id, lifetime_params)
(opaque_ty_id, lifetime_params)
});
let generic_args =
@ -2683,10 +2683,10 @@ impl<'a> LoweringContext<'a> {
})
.collect();
let exist_ty_ref = hir::TyKind::Def(hir::ItemId { id: exist_ty_id }, generic_args);
let opaque_ty_ref = hir::TyKind::Def(hir::ItemId { id: opaque_ty_id }, generic_args);
hir::FunctionRetTy::Return(P(hir::Ty {
node: exist_ty_ref,
node: opaque_ty_ref,
span,
hir_id: self.next_id(),
}))
@ -3445,7 +3445,7 @@ impl<'a> LoweringContext<'a> {
self.lower_generics(generics, ImplTraitContext::disallowed()),
),
ItemKind::OpaqueTy(ref b, ref generics) => hir::ItemKind::OpaqueTy(
hir::ExistTy {
hir::OpaqueTy {
generics: self.lower_generics(generics,
ImplTraitContext::OpaqueTy(None)),
bounds: self.lower_param_bounds(b,

View File

@ -827,7 +827,7 @@ impl<'hir> Map<'hir> {
match self.get(scope) {
Node::Item(i) => {
match i.node {
ItemKind::OpaqueTy(ExistTy { impl_trait_fn: None, .. }) => {}
ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: None, .. }) => {}
_ => break,
}
}

View File

@ -1922,7 +1922,7 @@ pub struct BareFnTy {
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct ExistTy {
pub struct OpaqueTy {
pub generics: Generics,
pub bounds: GenericBounds,
pub impl_trait_fn: Option<DefId>,
@ -2422,7 +2422,7 @@ pub enum ItemKind {
/// A type alias, e.g., `type Foo = Bar<u8>`
Ty(P<Ty>, Generics),
/// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;`
OpaqueTy(ExistTy),
OpaqueTy(OpaqueTy),
/// An enum definition, e.g., `enum Foo<A, B> {C<A>, D<B>}`
Enum(EnumDef, Generics),
/// A struct definition, e.g., `struct Foo<A> {x: A}`
@ -2479,7 +2479,7 @@ impl ItemKind {
Some(match *self {
ItemKind::Fn(_, _, ref generics, _) |
ItemKind::Ty(_, ref generics) |
ItemKind::OpaqueTy(ExistTy { ref generics, impl_trait_fn: None, .. }) |
ItemKind::OpaqueTy(OpaqueTy { ref generics, impl_trait_fn: None, .. }) |
ItemKind::Enum(_, ref generics) |
ItemKind::Struct(_, ref generics) |
ItemKind::Union(_, ref generics) |

View File

@ -1033,13 +1033,13 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
let (in_definition_scope, origin) = match tcx.hir().find(opaque_hir_id) {
Some(Node::Item(item)) => match item.node {
// Anonymous `impl Trait`
hir::ItemKind::OpaqueTy(hir::ExistTy {
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: Some(parent),
origin,
..
}) => (parent == self.parent_def_id, origin),
// Named `type Foo = impl Bar;`
hir::ItemKind::OpaqueTy(hir::ExistTy {
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: None,
origin,
..

View File

@ -480,7 +480,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
};
self.with(scope, |_, this| intravisit::walk_item(this, item));
}
hir::ItemKind::OpaqueTy(hir::ExistTy {
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: Some(_),
..
}) => {
@ -489,7 +489,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
// it.
}
hir::ItemKind::Ty(_, ref generics)
| hir::ItemKind::OpaqueTy(hir::ExistTy {
| hir::ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: None,
ref generics,
..
@ -629,7 +629,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
{
// Named opaque `impl Trait` types are reached via `TyKind::Path`.
// This arm is for `impl Trait` in the types of statics, constants and locals.
hir::ItemKind::OpaqueTy(hir::ExistTy {
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: None,
..
}) => {
@ -637,7 +637,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
return;
}
// RPIT (return position impl trait)
hir::ItemKind::OpaqueTy(hir::ExistTy {
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
ref generics,
ref bounds,
..
@ -1254,7 +1254,7 @@ fn compute_object_lifetime_defaults(tcx: TyCtxt<'_>) -> HirIdMap<Vec<ObjectLifet
hir::ItemKind::Struct(_, ref generics)
| hir::ItemKind::Union(_, ref generics)
| hir::ItemKind::Enum(_, ref generics)
| hir::ItemKind::OpaqueTy(hir::ExistTy {
| hir::ItemKind::OpaqueTy(hir::OpaqueTy {
ref generics,
impl_trait_fn: None,
..

View File

@ -3214,8 +3214,8 @@ fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
pub fn is_impl_trait_defn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
if let Node::Item(item) = tcx.hir().get(hir_id) {
if let hir::ItemKind::OpaqueTy(ref exist_ty) = item.node {
return exist_ty.impl_trait_fn;
if let hir::ItemKind::OpaqueTy(ref opaque_ty) = item.node {
return opaque_ty.impl_trait_fn;
}
}
}

View File

@ -1403,7 +1403,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item) {
hir::ItemKind::Union(..) => {
check_union(tcx, it.hir_id, it.span);
}
hir::ItemKind::OpaqueTy(hir::ExistTy{origin, ..}) => {
hir::ItemKind::OpaqueTy(hir::OpaqueTy{origin, ..}) => {
let def_id = tcx.hir().local_def_id(it.hir_id);
let substs = InternalSubsts::identity_for_item(tcx, def_id);

View File

@ -294,7 +294,7 @@ fn type_param_predicates(
ItemKind::Fn(.., ref generics, _)
| ItemKind::Impl(_, _, _, ref generics, ..)
| ItemKind::Ty(_, ref generics)
| ItemKind::OpaqueTy(ExistTy {
| ItemKind::OpaqueTy(OpaqueTy {
ref generics,
impl_trait_fn: None,
..
@ -456,7 +456,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
}
// Desugared from `impl Trait`, so visited by the function's return type.
hir::ItemKind::OpaqueTy(hir::ExistTy {
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: Some(_),
..
}) => {}
@ -896,7 +896,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
..
}) => Some(tcx.closure_base_def_id(def_id)),
Node::Item(item) => match item.node {
ItemKind::OpaqueTy(hir::ExistTy { impl_trait_fn, .. }) => impl_trait_fn,
ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => impl_trait_fn,
_ => None,
},
_ => None,
@ -920,7 +920,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
ItemKind::Ty(_, ref generics)
| ItemKind::Enum(_, ref generics)
| ItemKind::Struct(_, ref generics)
| ItemKind::OpaqueTy(hir::ExistTy { ref generics, .. })
| ItemKind::OpaqueTy(hir::OpaqueTy { ref generics, .. })
| ItemKind::Union(_, ref generics) => {
allow_defaults = true;
generics
@ -1253,12 +1253,12 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_adt(def, substs)
}
ItemKind::OpaqueTy(hir::ExistTy {
ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: None,
..
}) => find_opaque_ty_constraints(tcx, def_id),
// Opaque types desugared from `impl Trait`.
ItemKind::OpaqueTy(hir::ExistTy {
ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: Some(owner),
..
}) => {
@ -2051,7 +2051,7 @@ fn explicit_predicates_of(
is_trait = Some((ty::TraitRef::identity(tcx, def_id), &empty_trait_items));
generics
}
ItemKind::OpaqueTy(ExistTy {
ItemKind::OpaqueTy(OpaqueTy {
ref bounds,
impl_trait_fn,
ref generics,

View File

@ -3664,8 +3664,8 @@ impl Clean<Item> for doctree::OpaqueTy<'_> {
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: OpaqueTyItem(OpaqueTy {
bounds: self.exist_ty.bounds.clean(cx),
generics: self.exist_ty.generics.clean(cx),
bounds: self.opaque_ty.bounds.clean(cx),
generics: self.opaque_ty.generics.clean(cx),
}, false),
}
}

View File

@ -472,9 +472,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
};
om.typedefs.push(t);
},
hir::ItemKind::OpaqueTy(ref exist_ty) => {
hir::ItemKind::OpaqueTy(ref opaque_ty) => {
let t = OpaqueTy {
exist_ty,
opaque_ty,
name: ident.name,
id: item.hir_id,
attrs: &item.attrs,