From b4fe5557963b8737d2d40e2517c5a90358691c03 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 2 Aug 2019 00:08:05 +0100 Subject: [PATCH] Replace `exist_ty` and `ExistTy` with `opaque_ty` and `OpaqueTy` --- src/librustc/hir/intravisit.rs | 2 +- src/librustc/hir/lowering.rs | 106 ++++++++++++------------ src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 6 +- src/librustc/infer/opaque_types/mod.rs | 4 +- src/librustc/middle/resolve_lifetime.rs | 10 +-- src/librustc/ty/mod.rs | 4 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/collect.rs | 14 ++-- src/librustdoc/clean/mod.rs | 4 +- src/librustdoc/visit_ast.rs | 4 +- 11 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 397529d4e19..625e746c24f 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -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, .. diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index f2d4ceb1636..f16a637aab3 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1721,7 +1721,7 @@ impl<'a> LoweringContext<'a> { &mut self, span: Span, fn_def_id: Option, - 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, HirVec) { @@ -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, already_defined_lifetimes: FxHashSet, @@ -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 = impl Future; + // type OpaqueTy = impl Future; // // `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, diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 48ff4bb9e42..b93961a1239 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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, } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index f293ddbf467..54392a420a4 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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, @@ -2422,7 +2422,7 @@ pub enum ItemKind { /// A type alias, e.g., `type Foo = Bar` Ty(P, Generics), /// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;` - OpaqueTy(ExistTy), + OpaqueTy(OpaqueTy), /// An enum definition, e.g., `enum Foo {C, D}` Enum(EnumDef, Generics), /// A struct definition, e.g., `struct Foo {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) | diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 7105dd8f745..e797a37fe75 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -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, .. diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 90e449a0c67..80f85bec879 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -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, def_id: DefId) -> Option { pub fn is_impl_trait_defn(tcx: TyCtxt<'_>, def_id: DefId) -> Option { 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; } } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 26d5f462d8d..8d6f9185962 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index abb0bcad0dd..15687eaa943 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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 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, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c82d61632d5..a41b12e29b0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3664,8 +3664,8 @@ impl Clean 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), } } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 3964460633c..098cecef95c 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -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,